listbox and qdf

V

Van Eenoo Stefaan

Hey, how can i modify the following code for multiple listbox's ?
(on my form I have multiple listbox, and according to the choices the users
make, the querie, and thus the result is poulated)
I hop this makes sens.
Thanx in advance for the time and effort.
Stefaan

Public Function lijstbox()


' Declare variables
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String
' Get the database and stored query
Set db = CurrentDb()
Set qdf = db.QueryDefs("mail")
' Loop through the selected items in the list box and build a text string
For Each varItem In Me!listcat.ItemsSelected
strCriteria = strCriteria & ",'" & Me!listcat.ItemData(varItem) &
"'"
Next varItem
' Check that user selected something
If Len(strCriteria) = 0 Then
MsgBox "You did not select anything from the list" _
, vbExclamation, "Nothing to find!"
Exit Function
End If
' Remove the leading comma from the string
strCriteria = Right(strCriteria, Len(strCriteria) - 1)
' Build the new SQL statement incorporating the string
strSQL = "SELECT * FROM tblData " & _
"WHERE tblData.Region IN(" & strCriteria & ");"
' Apply the new SQL statement to the query
qdf.SQL = strSQL

End Function
 
S

SA

Stefaan:

Why not just add a parameter to the function call as in:

Public Function LijstBox(ListBoxID as Byte)

And then use a Select Case statement to determine what the SQL and/or target
control should be.

Alternately you could simply pass the list box obj as in:

Public Function LijstBox (objListBox as Control)

And then use the objListBox.Name to select the SQL to use for that List box.
 

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