Query data based on List Box multiple selection

T

titlepusher

I need to query data based upon the multiple criteria selected in a list box.
Can't seem to make it happen. I'm not a coder... please dumb it down.
Thanks
 
R

Roger Carlson

O

Ofer

Try this to get all the item that were selected in the list box

Dim VarItm, OutputString As String, i As Integer
i = 1
For Each VarItm In prm_MyCtl.ItemsSelected
If i = 1 Then
'------------------------------create output string
If prm_DataType = 1 Then '--Integer data
OutputString = prm_MyCtl.ItemData(VarItm)
Else '--String data
OutputString = "'" & prm_MyCtl.ItemData(VarItm) & "'"
End If
Else
If prm_DataType = 1 Then
OutputString = OutputString & "," & prm_MyCtl.ItemData(VarItm)
Else
OutputString = OutputString & ",'" & prm_MyCtl.ItemData(VarItm)
& "'"
End If
End If
i = i + 1
Next VarItm

You can use the OutputString as a filter for the query
 
R

Robbie Doo

Where do you put this code?

Ofer said:
Try this to get all the item that were selected in the list box

Dim VarItm, OutputString As String, i As Integer
i = 1
For Each VarItm In prm_MyCtl.ItemsSelected
If i = 1 Then
'------------------------------create output string
If prm_DataType = 1 Then '--Integer data
OutputString = prm_MyCtl.ItemData(VarItm)
Else '--String data
OutputString = "'" & prm_MyCtl.ItemData(VarItm) & "'"
End If
Else
If prm_DataType = 1 Then
OutputString = OutputString & "," & prm_MyCtl.ItemData(VarItm)
Else
OutputString = OutputString & ",'" & prm_MyCtl.ItemData(VarItm)
& "'"
End If
End If
i = i + 1
Next VarItm

You can use the OutputString as a filter for the query
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top