I have two list boxes, one entitled source(lstsource) and one called position(lstposition). I have populated them with information from a table, and i want to be able to choose specific items from the list and run a report based on teh filtered selections. I successfully configured the first list so it runs a report based on my selections, but the second lsit box runs all of the items in the list rather than the ones i choose. here is my query
Private Sub cmdresumefilter_Click()
Dim strFilterString As String
Dim varSelectedItem As Variant
Dim intCurrentCount As Integer
Dim stDocName As String
intCurrentCount = 1
For Each varSelectedItem In Me.lstsource.ItemsSelected
strFilterString = strFilterString & "(Source = '" & Me.lstsource.ItemData(varSelectedItem) & "')AND( Position = '" & Me.lstposition.ItemData(varSelectedItem) & "')"
If Not (intCurrentCount = Me.lstsource.ItemsSelected.Count) And (intCurrentCount = Me.lstposition.ItemsSelected.Count) Then
strFilterString = strFilterString & " Or "
End If
intCurrentCount = intCurrentCount + 1
Next varSelectedItem
For Each varSelectedItem In Me.lstposition.ItemsSelected
strFilterString = strFilterString & "(Source = '" & Me.lstsource.ItemData(varSelectedItem) & "')AND( Position = '" & Me.lstposition.ItemData(varSelectedItem) & "')"
Next varSelectedItem
stDocName = "New Resume Query1"
DoCmd.OpenReport stDocName, acViewPreview, , strFilterString
End Sub
Private Sub cmdresumefilter_Click()
Dim strFilterString As String
Dim varSelectedItem As Variant
Dim intCurrentCount As Integer
Dim stDocName As String
intCurrentCount = 1
For Each varSelectedItem In Me.lstsource.ItemsSelected
strFilterString = strFilterString & "(Source = '" & Me.lstsource.ItemData(varSelectedItem) & "')AND( Position = '" & Me.lstposition.ItemData(varSelectedItem) & "')"
If Not (intCurrentCount = Me.lstsource.ItemsSelected.Count) And (intCurrentCount = Me.lstposition.ItemsSelected.Count) Then
strFilterString = strFilterString & " Or "
End If
intCurrentCount = intCurrentCount + 1
Next varSelectedItem
For Each varSelectedItem In Me.lstposition.ItemsSelected
strFilterString = strFilterString & "(Source = '" & Me.lstsource.ItemData(varSelectedItem) & "')AND( Position = '" & Me.lstposition.ItemData(varSelectedItem) & "')"
Next varSelectedItem
stDocName = "New Resume Query1"
DoCmd.OpenReport stDocName, acViewPreview, , strFilterString
End Sub