LATECHmatt05
Technical User
I am having trouble with three combo boxes I want them to be or statements in SQL but within the vba i am writing for the clicking of a button on a form. I am really lost my syntax has to be wrong also how hard would it be to put and or boxes between the three boxes so that they can be (AND / OR ) conditional statements rather than just ors. below is my sample code. any help is greatly appreciated.
Private Sub cmdOK_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Set db = CurrentDb
Set qdf = db.QueryDefs("masterq")
strSQL = "SELECT Begin.* " & _
"FROM Begin " & _
"WHERE Begin.date BETWEEN #" & DateA & " # AND # " & DateB & " # " & _
"AND Begin.UnitName'" & Me.UnitA.Value & "'" & _
" OR Begin.UnitName='" & Me.UnitB.Value & " ' " & _
" OR Begin.UnitName='" & Me.UnitC.Value & "';"
qdf.sql = strSQL
DoCmd.OpenQuery "masterq"
DoCmd.Close acForm, Me.Name
Set qdf = Nothing
Set db = Nothing
End Sub
Private Sub cmdOK_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Set db = CurrentDb
Set qdf = db.QueryDefs("masterq")
strSQL = "SELECT Begin.* " & _
"FROM Begin " & _
"WHERE Begin.date BETWEEN #" & DateA & " # AND # " & DateB & " # " & _
"AND Begin.UnitName'" & Me.UnitA.Value & "'" & _
" OR Begin.UnitName='" & Me.UnitB.Value & " ' " & _
" OR Begin.UnitName='" & Me.UnitC.Value & "';"
qdf.sql = strSQL
DoCmd.OpenQuery "masterq"
DoCmd.Close acForm, Me.Name
Set qdf = Nothing
Set db = Nothing
End Sub