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!

query to handle a multiple selection in a list box

Status
Not open for further replies.

ierax

Technical User
May 13, 2001
4
GR
hi,
i store the user selection from a list box, in a variable
and pass that variable as a parameter in my query.
i.e when the user chooses "Rblt1" from the list box the variable "varRblt" gets the value "Rblt1" and the query

sqltext="SELECT * FROM DBname WHERE RBLT='"& varRblt&"';" works fine.

When the user makes multiple selections (i.e Rblt1 and Rblt2)from the list box,the variable varRblt gets the value
"Rblt1,Rblt2" and the query does NOT work.
How should i write sqltext in order to work with single and multiple selections?

Waiting for help,

Thanks in advance
ierax
 
...Using Access 97, do this...

Private Sub Command0_Click()
Dim Criteria As String
Dim strSQL as string
Dim i As integer

strSQL = "SELECT * FROM [tablename]"
Criteria = ""

For Each i In Me![List0].ItemsSelected '[red] get each selected item in list.[/red]
If Criteria <> &quot;&quot; Then
Criteria = Criteria & &quot; AND [txtField1]=' &quot;& Me![List0].ItemData(i) & &quot;' &quot;
Else
Criteria = &quot; WHERE [txtField1]=' &quot;& Me![List0].ItemData(i) & &quot;' &quot;
End If

Next i

' for debugging purposes you may want to set a break prior
' to executing the query to make sure it looks like you
' want it to. :cool:. Perhaps not.

' execute the query. Done.

End Sub

Have fun. Amiel
amielzz@netscape.net

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top