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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble adding 'And' to Sql String from ListBox Selection 1

Status
Not open for further replies.

pdldavis

Technical User
Oct 29, 2001
522
US
Hello, I am building the 'Where' part of a string from a list box selection and am having some trouble with the AND portion where I want two use two criteria. The Column numbers are correct. It seems to be picking up column 0 once and column 2 twice so I think I have an error in the and / or syntax.


For Each varItem In lstPsn.ItemsSelected

This works:

StrsqlWhere = StrsqlWhere & "[tblDiscipline].[discid] = " & lstPsn.Column(0, varItem) & " OR "

This Doesnt:

I would like to add an 'And' to this:

StrsqlWhere = StrsqlWhere & " [tblDiscipline].[discid] = " & lstPsn.Column(0, varItem) & " AND " & _
"tblReview.EvalID = " & lstPsn.Column(2, varItem) & " OR "

Next varItem

msgbox StrSql

Help would be very much appreciated.

Thanks, Dan

 
And this ?
StrsqlWhere = StrsqlWhere & " (tblDiscipline.discid=" & lstPsn.Column(0, varItem) & " AND " & _
"tblReview.EvalID=" & lstPsn.Column(2, varItem) & ") OR "

Mixing AND & OR operators forces the use of proper parentheses...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks for the help, PHV. Anyone aware of a cheat sheet or similar that would help with manually constructing these strings?
 
I understand this FAQ181-5497 has a function that creates a where clause from different controls on a form.

Leslie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top