Private Sub cmdRunReports_Click()
Dim filterContract As String
Dim filterCounty As String
Dim filterPriority As String
Dim strFilter As String
Dim strSql As String
Dim i As Integer
Dim idx As Variant
Dim lst As Access.ListBox
Dim AndOr As String
'You can put code here to make it an AND or OR
AndOr = " AND "
'------------ Do contract
Set lst = Me.lstContractType
For Each idx In lst.ItemsSelected
If filterContract = "" Then
filterContract = "'" & lst.ItemData(idx) & "'"
'Debug.Print filterContract
Else
filterContract = filterContract & ", '" & lst.ItemData(idx) & "'"
End If
Next idx
If filterContract <> "" Then
filterContract = "ContractType IN (" & filterContract & ")" & AndOr
End If
'Debug.Print filterContract
'----------------Do Counties
Set lst = Me.lstCounties
For Each idx In lst.ItemsSelected
If filterCounty = "" Then
filterCounty = "'" & lst.ItemData(idx) & "'"
Else
filterCounty = filterCounty & ", '" & lst.ItemData(idx) & "'"
End If
Next idx
If filterCounty <> "" Then
filterCounty = "County.value IN (" & filterCounty & ")" & AndOr
End If
' Debug.Print filterCounty
'-------------- Do Priority
Set lst = Me.lstPriorityCategory
For Each idx In lst.ItemsSelected
If filterPriority = "" Then
filterPriority = "'" & lst.ItemData(idx) & "'"
'Debug.Print filterPriority
Else
filterPriority = filterPriority & ", '" & lst.ItemData(idx) & "'"
End If
Next idx
If filterPriority <> "" Then
Debug.Print filterPriority
filterPriority = "PriorityCategory.value IN (" & filterPriority & ")" & AndOr
End If
' Debug.Print filterPriority
'------------------- need to add more code to check for which strings have a value
strSql = "Select * from tblMain "
strFilter = filterContract & filterCounty & filterPriority
If strFilter <> "" Then
strFilter = " WHERE " & strFilter
strFilter = Left(strFilter, Len(strFilter) - Len(AndOr))
strSql = strSql & strFilter
End If
Debug.Print strSql
End Sub