I cant seem to figure out how to reference a combo box value on a form in another textboxs sum iif function. The sample of what I am trying to do is below, with the reference to "TestCombo" the value I want to change based on who is selected. I tried using CHR(34) quotes, and I cant seem to figure it out.
SUM(iif([SaleStatus]= 'Pending' And [SalesAdvisor] = [TestCombo],1,0))
This same function works if I do the following
SUM(iif[SaleStatus]= 'Pending' And [SalesAdvisor] = 'TestAdvisor',1,0))
That led me to believe I needed quotes, which I expected, but that doesn't work either, such as the example below.
SUM(iif"[SalesStauts]= 'Pending' And [SalesAdvisor] = " & chr(39) & [TestCombo] & chr(39) & "",1,0))
Can somebody help me use the combo box as a dynamic reference to the sum iif?
Are you sure that your combo is equal to 'TestAdvisor'? It is quite common to have a numeric bound column and a text display. If you have more than one column in the combo, you will need to refer to the column property to get the text column. If you include the RecordSource for the combo in your question, it will be easy to see.
Related
Wonder if any of y'all can help me. I keep getting errors on this. Here's my table:
- tblCutting
- PartNumber (Primary Key Text Field)
- CuttingStep1 (Number)
- CuttingStep2 (Number)
- CuttingStep3 (Number)
I'm trying to use a combo box (cmbPartNumber1) to pick from PartNumber and then a text box fills in with the corresponding CuttingStep1. Here's are the various formulas I've tried underneath the textbox:
=DLookUp("CuttingStep1","tblCutting","cmbPartNumber1=" & [tblCutting]![PartNumber])
=DLookUp("CuttingStep1","tblCutting","[cmbPartNumber1]=" & [tblCutting]![PartNumber])
=DLookUp("CuttingStep1","tblCutting","cmbPartNumber1=" & [PartNumber])
=DLookUp("CuttingStep1","tblCutting","[tblCutting]![PartNumber]=" & [cmbPartNumber1])
=DLookUp("CuttingStep1","tblCutting","[PartNumber]=" & [cmbPartNumber1])
None of these have worked and I have no idea why. Any suggestions?
Or am I way off on how this is supposed to work?
Edit: added field types above.
Text values need to be delimited:
=DLookUp("CuttingStep1","tblCutting","PartNumber='" & [cmbPartNumber1] & "'")
Also, since your textboxes are using a calculated formula, they are "Unbound", therefore you need to update their contents yourself.
To handle this you'll need an event sub for the "Change" event of your ComboBox. Add the following code or similar, since I do not know the names of your Textboxes. Add to your Form Module:
Private Sub cmbPartNumber1_Change()
' Refresh (recalculate) values. textBox1,2,3 are names of your Textboxes that contain calculated values based on value of cmbPartNumber1.
textBox1.Refresh
textBox2.Refresh
TextBox3.Refresh
End Sub
I am trying to populate a text box by looking up a value after a combo box is updated. Right now in the combo box "after update" event I have:
Me.Text42 = DLookUp("field","query","Baseline=" & [Combo26])
But that is not working. What am I doing wrong?
If the Baseline column in query is defined as text data rather than numeric, then you need
Me.Text42 = DLookUp("field","query","Baseline='" & [Combo26] & "'")
If this is not the problem, can you post more details. What appears in Text42? Nothing or #Error? Have you tried putting a break point in the code and testing the value of your DLookup function in the immediate pane?
I have a form called DisplayForm. In that form is a combo box drop down that is at the top of column on the form where a label would usually go. I want to select an item from that drop down menu and use that bit of data to open another form. I have copied an example from the web, changed the names and can't get it to work. Here is the code;
If Not Me.NewRecord Then
DoCmd.OpenForm "AreaForm", _
WhereCondition:="LArea=" & Me.AreaCBDrop
End If
Area is the name of the field in the query that is the recordsource for the form, but when I run it, it opens a msgbox that wants me to enter a peramater value. I also don't understand what the IF is about. I have tried this with and without the if but get the same result. Me.AreaCBDrop has the correct value in it, but the where does not work.
Thanks
Thanks
Your WHERE condition is expecting a text parameter, but you are not supplying the expected format, so it is asking for one.
Surround your Me.AreaCBDrop with single quotes, like this:
If Not Me.NewRecord Then
DoCmd.OpenForm "AreaForm", _
WhereCondition:="LArea='" & Me.AreaCBDrop & "'"
End If
I would like to hide empty fields, not show a blank line. How can i do this?
Add a row to your details group to hold the potential list of values. Drop a single textbox field that displays a calculated field. The calculated field should be an expression similar to the below to display up to 4 sequential fields.
=Fields!ExampleField1.Value & IIF(Fields!ExampleField1.Value.ToString().Length >0,vbCrLf,"") &
Fields!ExampleField2.Value & IIF(Fields!ExampleField2.Value.ToString().Length >0,vbCrLf,"") &
Fields!ExampleField3.Value & IIF(Fields!ExampleField3.Value.ToString().Length >0,vbCrLf,"") &
Fields!ExampleField4.Value
Select the TableRow (not the individual cells) you want to make conditionally suppressed, then enter the conditional suppression formula into the Visibility - Hidden property expression on the Properties tab.
I'm having problems with a cascading combo box. Everything works fine with the combo boxes and the values get populated correctly.
Private Sub cmbAdjComp_AfterUpdate()
Me.cboAdjOff.RowSource = "SELECT AdjusterCompanyOffice.ID,
AdjusterCompanyOffice.Address1,
AdjusterCompanyOffice.Address2,
AdjusterCompanyOffice.Address3,
AdjusterCompanyOffice.Address4,
AdjusterCompanyOffice.Address5 FROM" & _
" AdjusterCompanyOffice WHERE
AdjusterCompanyOffice.AdjCompID = " & Me.cmbAdjComp.Column(1) & _
" ORDER BY AdjusterCompanyOffice.Address1"
Me.cboAdjOff = Me.cboAdjOff.ItemData(0)
End Sub
The secondary combo box has a row source query:
SELECT AdjusterCompanyOffice.ID, AdjusterCompanyOffice.Address1,
AdjusterCompanyOffice.Address2, AdjusterCompanyOffice.Address3,
AdjusterCompanyOffice.Address4, AdjusterCompanyOffice.Address5 FROM
AdjusterCompanyOffice ORDER BY AdjusterCompanyOffice.Address1;
Both comboboxes have the same controlsource.
Everything works fine and dandy moving between records and the boxes show the correct fields for each record.
When i use the first combo box, and then select the appropriate option in the second combo box, everything works great on the specific record.
However when I move to the next record, the values in the second combo box are all empty. If i close the form and reopen it, and avoid using the cascading combo boxes all the values are all correct when i move between records.
Somehow using the cascading combo boxes creates a conflict with the row source of the secondary combo box.
Hope that is clear! Have been rummaging around for an answer but cant find anything.
any help would be greatly appreciated.
Thanks
Noel
The reason why the combo box is blank when you navigate to the next record is because you have NotInList set to TRUE (which is what you want), but when you arrive on the record, the rowsource has been filtered to not include the value stored in the field the combo box is bound to. Thus, it's blank -- the value is there, but it can't be displayed, since it's not in the list.
To fix this, you need to clear the filter on the second combo box. To do that, in the OnCurrent event of your form, set the rowsource of the filtered combo box to be unfiltered:
Me!cboAdjOff.RowSource = "SELECT AdjusterCompanyOffice.ID, AdjusterCompanyOffice.Address1, AdjusterCompanyOffice.Address2, AdjusterCompanyOffice.Address3, AdjusterCompanyOffice.Address4, AdjusterCompanyOffice.Address5 FROM AdjusterCompanyOffice ORDER BY AdjusterCompanyOffice.Address1"
I usually handle this by creating two constants at the top of the form's module, one for the SELECT statement and one for the ORDER BY:
cstrRecordsourceSelect = "SELECT AdjusterCompanyOffice.ID, AdjusterCompanyOffice.Address1, AdjusterCompanyOffice.Address2, AdjusterCompanyOffice.Address3, AdjusterCompanyOffice.Address4, AdjusterCompanyOffice.Address5 FROM AdjusterCompanyOffice"
cstrRecordsourceOrderBy = "ORDER BY AdjusterCompanyOffice.Address1"
Then it's much easier to handle. In the OnCurrent it looks like this:
Me!cboAdjOff.RowSource = cstrRecordsourceSelect & " " & cstrRecordsourceSelect
...and in the AfterUpdate of your first combo box:
Me!cboAdjOff.RowSource = cstrRecordsourceSelect & _
"WHERE AdjusterCompanyOffice.AdjCompID = " & Me!cmbAdjComp.Column(1) & _
" " & cstrRecordsourceSelect
This makes the code easier to read, and it also makes it easier to alter the rowsource if you need to, since you have to edit only the constant.