I have a form with 3 combo boxes that I would like to uses to filter records in query. I used the If..Then statement
I have written the code to run a query if one of the 3 boxes has value in it and it works.
If Not IsNull(Me.[Combo1]) And IsNull(Me.[Combo2]) And IsNull(Me.[Combo3]) Then
strMySQL = "Select * from myQuery Where MyQuery.[Value1]= '" & Me.[Combo1] & "'".
End IF
Set strSQL = CurrentDb.CreateQueryDef("MyQuery", strMySQL)
DoCmd.OpenQuery "MyQuery"
However, if there are two boxes with values in them, the code I have below to assign the values does not work. I think it has something to do with how I am placing all the "" for the second parameter.
strMySQL = "Select * from myQuery Where myQuery.[Value1]= '" & Me.[Combo1] & "'" And "myQuery.[Value2] = '" & Me.[Combo2] & "'"
I also need to have the code run if all the 3 boxes have values in them.
Then I would like to include an Order By clause
Please help.
I have written the code to run a query if one of the 3 boxes has value in it and it works.
If Not IsNull(Me.[Combo1]) And IsNull(Me.[Combo2]) And IsNull(Me.[Combo3]) Then
strMySQL = "Select * from myQuery Where MyQuery.[Value1]= '" & Me.[Combo1] & "'".
End IF
Set strSQL = CurrentDb.CreateQueryDef("MyQuery", strMySQL)
DoCmd.OpenQuery "MyQuery"
However, if there are two boxes with values in them, the code I have below to assign the values does not work. I think it has something to do with how I am placing all the "" for the second parameter.
strMySQL = "Select * from myQuery Where myQuery.[Value1]= '" & Me.[Combo1] & "'" And "myQuery.[Value2] = '" & Me.[Combo2] & "'"
I also need to have the code run if all the 3 boxes have values in them.
Then I would like to include an Order By clause
Please help.