Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combo box problems with or statements 2

Status
Not open for further replies.

LATECHmatt05

Technical User
Jun 23, 2004
11
US
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

 
Sorry, I don't understand what you're asking. Btw - is thread702-866649 brought to closure? Welcome to Tek-Tips btw, here's a faq on how to get the most out of the membership faq181-2886.

You could try to play with the QBE first, and find out what you need there, before writing code. Just wondering, is it something like this you're after? (there where some additional spaces, a missing =, not sure I've got it all)

[tt]"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 & "');"[/tt]

Roy-Vidar
 
How are ya LATECHmatt05 . . . . . .

All ya need to do is get it working like ya want in [blue]Query Design View[/blue] and just copy the SQL in [blue]SQL View[/blue].

I don't write SQL anymore. I do it this way. saves alot of time.

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top