I have 5 combo boxes, used to filter a listbox. I want to make it so not all 5 have to be selected in order for the filter to work. Each combobox starts blank ( "" ), and I want to be able to skip 1 or several and filter with the ones I select. Here is the AfterUpdate code for one of the comboboxes:
On Error Resume Next
'These are the comboboxes
Me.BilletMaterial.RowSource = [MechanicalData.Billet Material]
Me.BilletNumber.RowSource = [MechanicalData.Billet Number]
Me.TestType.RowSource = [MechanicalData.Test Type]
Me.Axis.RowSource = [MechanicalData.Axis]
Me.Temperature.RowSource = [MechanicalData.Temperature]
Me.BilletMaterial.Requery
Me.BilletNumber.Requery
Me.TestType.Requery
Me.Axis.Requery
Me.Temperature.Requery
'Listbox
Me.DataView.RowSource = "SELECT [Billet Material],[Billet Number], " & _
"[Specimen],[Temperature],[Modulus],[Ultimate Tensile Strength],[Strain] " & _
"FROM MechanicalData " & _
"WHERE 1=1 " & _
"AND [MechanicalData.Axis] = '" & Me.Axis.Value & "' " & _
"AND [MechanicalData.Test Type] = '" & TestType.Value & "' " & _
"AND [MechanicalData.Temperature] = " & Temperature.Value & " " & _
"AND If (Not IsNull(BilletNumber.Value)) Then [MechanicalData.Billet Number] = " & BilletNumber.Value & " End if " & _
"AND [MechanicalData.Billet Material] = '" & BilletMaterial.Value & "' "
My first thought would be to implement multiple "if is not empty..." statements in the WHERE portion of the SELECT statement, but I'm not sure how to do that or even if it's possible.
I know the syntax of this line is wrong.
"AND If (Not IsNull(BilletNumber.Value)) Then [MechanicalData.Billet Number] = " & BilletNumber.Value & " End if " & _
If (Not IsNull(Combo)) Then strWhere = strWhere &
– FionnualaWHERE 1=1
so everything else can beAND this=that
– FionnualaAND [MechanicalData.Axis] = " & Me.Axis.Value & "
.. Single quotes are not needed. Has this actually worked before? Also, when I check for Null values in comboboxes, I used the method Remou described (except I useIf IsNull (Object.Value) = False Then
) – Mark C.