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.Item sSelected
strPark = strPark & ",'" & Me.mslPark.Item Data(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.I temsSelected
strSpecies = strSpecies & ",'" & Me.mslSpecies.I temData(varItem ) _
& "'"
Next varItem
If Len(strSpecies) = 0 Then
strSpecies = "Like '*'"
Else
strSpecies = Right(strSpecie s, 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("q ryTest")
qdf.SQL = strSQL
Set qdf = Nothing
Set db = Nothing
DoCmd.OpenQuery "qryTest"
DoCmd.Close acForm, Me.Name
End Sub
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.Item sSelected
strPark = strPark & ",'" & Me.mslPark.Item Data(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.I temsSelected
strSpecies = strSpecies & ",'" & Me.mslSpecies.I temData(varItem ) _
& "'"
Next varItem
If Len(strSpecies) = 0 Then
strSpecies = "Like '*'"
Else
strSpecies = Right(strSpecie s, 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("q ryTest")
qdf.SQL = strSQL
Set qdf = Nothing
Set db = Nothing
DoCmd.OpenQuery "qryTest"
DoCmd.Close acForm, Me.Name
End Sub