Multi Select List box to filter data on Continues form

A

Anne

Is it possbile to use a List box to select several item to display in the
form.
I am trying to select greenhouses benches, but I would like to be able to
select several benches at a time. I have some double or split benches.

I have created the unbound list box and after selecting the benches I would
like the form to only display the items selected in the list box.

I created a command button:
Private Sub Command62_Click()
Dim varSelected As Variant
'Dim strWhere As String
Dim strSQL As String
For Each varSelected In Me!lstSelect.ItemsSelected
strSQL = strSQL & Me!lstSelect.ItemData(varSelected) & ","
Next varSelected
If strSQL <> "" Then
strSQL = "[GHBenchID] IN (" & Left(strSQL, Len(strSQL) - 1) & ")"
End If
End Sub



This code is actually part of a multi select list box I have been using to
open a report.

As far as the form goes, it does nothing, and I can see where some code is
missing, which whould actually restrict the data on my form.

Anne
 
A

Arvin Meyer [MVP]

I use something like this to fill a textbox which is then used in the sql
statement:

Dim varItem As Variant
Dim strList As String
Dim strSQL As String

With Me.lstSelect
If .MultiSelect = 0 Then
Me.txtSelected = .Value
Else
For Each varItem In .ItemsSelected
strList = strList & .Column(0, varItem) & ","
Next varItem
If strList <> "" Then
strList = Left$(strList, Len(strList) - 1)
End If
Me.txtSelected = strList
End If

End With

strSQL = "SELECT * FROM tblItem "
strSQL= strSQL & "WHERE ItemID In (" & Me.txtSelected & ") Order By ItemID;"
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 

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