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

List box Multi select simple use in query

Status
Not open for further replies.

kayek

Programmer
Jun 19, 2003
95
0
0
US
I have a Form with a list box set to mulit Select Simple. I want to use that list box in a query.

The Form Name is frmAccount. The List box name is AcctType_ListBox. I am using a textbox named AcctType to store the listbox selection values separated by commas.

The code and query is below. The in statement in the query does not work. Help!

Private Sub AccountType_ListBox_AfterUpdate()
Call ListSelectedItems
End Sub

Private Sub ListSelectedItems()
Dim v As Variant
Dim s As String
For Each v In Me.AcctType_ListBox.ItemsSelected
If s <> "" Then
s = s & ", "
End If
s = s & "'" & Me.AcctType_ListBox.ItemData(CLng(v)) & "'"
Next v
Me.AccountType.Value = s
End Sub

The Query is:
Select tblmain1.*
FROM tblmain1
WHERE name In ([Forms]![frmAccount]![AcctType])
 
You may try this:
WHERE InStr([Forms]![frmAccount]![AcctType], "'" & name & "'")>0

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top