Multi Select from Combo Boxes

AndyShuter

Registered User.
Local time
Today, 09:10
Joined
Mar 3, 2003
Messages
151
I have found some very interesting & useful code (thanx to DAVE UK) that allows me to muli select from a listbox and form a new query on its results!

Here it is

Dim MyDB As DAO.Database
Dim qdf As DAO.QueryDef
Dim i As Integer, strSQL As String
Dim strWhere As String, strWhere1 As String, strIN1 As String, strIN As String
Dim flgAll As Boolean
Set MyDB = CurrentDb()
strSQL = "SELECT *FROM qryLog"
'create the IN string by looping thru the listbox
For i = 0 To Me.List139.ListCount - 1
If Me.List139.Selected(i) Then
If Me.List139.Column(0, i) = "All" Then
flgAll = True
End If
strIN = strIN & "'" & Me.List139.Column(0, i) & "',"
End If
Next i
'create the WHERE string, stripping off the last comma of the IN string
strWhere = " WHERE [CurrentStatus] in (" & Left(strIN, Len(strIN) - 1) & ")"

'if "All" was selected, don't add the WHERE condition
If Not flgAll Then
strSQL = strSQL & strWhere
End If
MyDB.QueryDefs.Delete "qryLog1"
Set qdf = MyDB.CreateQueryDef("qryLog1", strSQL)

However 2 problems from this code arise

1. How do I add further search criteria from another listbox and place it in the next column of the query???

2. When you select ALL from one of the listboxes, it removed the "where" statement all together, whereas I may wish to see all of Colunm1, some of column 2 etc etc

Any help would be much apprerciated!!!

Thanks

Andy
 

Users who are viewing this thread

Back
Top Bottom