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

Query based on multi-select list box

Status
Not open for further replies.

edluke

MIS
Jul 5, 2001
26
0
0
US
Is it possible to have a query based on the selected values of a multi-select list box.
I have a list box which will contain office #'s. I want to be able to create a select query that will give a list of employees from the office #'s selected in the list box.

thanx in advance
 
You'll need to use the ItemsSelected collection of the listbox and create a string "WHERE tbl.field IN (item1,item2, item3, etc.)"

If this is a text value you'll need to wrap each item in double or single quotes. You'll need to parse the superfluous comma at the end of your string.

Use the Object Browser and view help files for ListBox.ItemsSelected property. Here's an example they give for getting the items (*you'll need to be sure that the bound column of the listbox is what you want to use for the parameter):

[tt]Sub BoundData()
Dim frm As Form, ctl As Control
Dim varItm As Variant

Set frm = Forms!Contacts
Set ctl = frm!Names
For Each varItm In ctl.ItemsSelected
Debug.Print ctl.ItemData(varItm)
Next varItm
End Sub
[/tt] Jeff Roberts
Analysis, Design, & Implementation
RenaissanceData.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top