Using Multi select list boxes in WHERE statements

S

Sidney

Hi

I have a table where users can populate a text field with 1 or more choices
from a list box. If the person selects more than 1 choice, then teh choices
are separated by a semi-colon. Thus, the records could look like this.

Record 1: Topic A
Record 2: Topic B
Record 3: Topic A; B

This works great but I am having some trouble with a query built into an
unbound search form. The user uses the same list box to search for the
records. The problem I am having is if the user wants to search for Topic A,
then the user only gets Record 1. If the user selects both Topic A and B
from the list box, then the user gets Record 1 and Record 2. I cannot find
any way to return Record 3 in the search.

I would like the query to return all records where the topic is found. For
example, if the user selects Topic A, then I would like the query to return
Records 1 and 3. Here is the code I am using:

strSQL = "SELECT tblIssues.*, tblIssueType.* " & _
"FROM tblIssues LEFT JOIN tblIssueType ON tblIssues.IssueID
= tblIssueType.IssueID "

strFilter = "WHERE IssueType IN( "

For i = 0 To lstIssueType.ListCount - 1
If lstIssueType.Selected(i) Then
strFilter = strFilter & "'" & Me.lstIssueType.Column(0,
i) & "', "
End If
Next i

strFilter = Left(strFilter, Len(strFilter) - 2) & ");"

strSQL = strSQL & strFilter

Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Set db = CurrentDb
db.QueryDefs.Delete "qryIssueType"
Set qdf = db.CreateQueryDef("qryIssueType", strSQL)

DoCmd.OpenForm "frmIssueRead", acNormal, "qryIssueType", , ,
acWindowNormal

I am using Access 03 and the list box is set as Extended.

Thank you
Sidney
 

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