By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,294 Members | 2,484 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,294 IT Pros & Developers. It's quick & easy.

Cascading listboxes

P: 3
Can someone tell me how to modify this code to have the second listbox be dependent on the first? I can't seem to get the rowsource in the second listbox to point to strPark. My two listboxes are mslPark and mslSpecies. Thanks!!

Kara

Private Sub cmdOK_Click()
Dim varItem As Variant
Dim strPark As String
Dim strSpecies As String
Dim strSQL As String
For Each varItem In Me.mslPark.ItemsSelected
strPark = strPark & ",'" & Me.mslPark.ItemData(varItem) _
& "'"
Next varItem
If Len(strPark) = 0 Then
strPark = "Like '*'"
Else
strPark = Right(strPark, Len(strPark) - 1)
strPark = "IN(" & strPark & ")"
End If
For Each varItem In Me.mslSpecies.ItemsSelected
strSpecies = strSpecies & ",'" & Me.mslSpecies.ItemData(varItem) _
& "'"
Next varItem
If Len(strSpecies) = 0 Then
strSpecies = "Like '*'"
Else
strSpecies = Right(strSpecies, Len(strSpecies) - 1)
strSpecies = "IN(" & strSpecies & ")"
End If
strSQL = "SELECT qryTest.* FROM qryTest " & _
"WHERE qryTest.[ParkName] " & strPark & _
"qryTest.[Species] " & strSpecies & ";"
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Set db = CurrentDb
Set qdf = db.QueryDefs("qryTest")
qdf.SQL = strSQL
Set qdf = Nothing
Set db = Nothing
DoCmd.OpenQuery "qryTest"
DoCmd.Close acForm, Me.Name
End Sub
Jul 10 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.