I am working on an advanced search form where users can filter product types by the various categories selected in the checkboxes provided. Right now I am working off of the design of a previous search form built which works fine. Here is the code I have running in the background:
Code:
Private Sub btnSearchAdvCrit_Click()
Me.subAdvProductSrch.Form.RecordSource = "SELECT * FROM qryAdvProductSrch " & BuildFilter
End Sub
Private Function BuildFilter() As Variant
Dim varWhere As Variant
varWhere = Null
If Me.Category <> "" Then
varWhere = varWhere & "[Category] LIKE """ & Me.Category & "*"" AND "
End If
If Me.TypeOfTool <> "" Then
varWhere = varWhere & "[TypeOfTool] = """ & Me.TypeOfTool & """ AND "
End If
If Me.ProductType <> "" Then
varWhere = varWhere & "[ProductType] = """ & Me.ProductType & """ AND "
End If
If Me.Audience <> "" Then
varWhere = varWhere & "[Audience] = """ & Me.Audience & """ AND "
End If
If Me.Status <> "" Then
varWhere = varWhere & "[Status] = """ & Me.Status & """ AND "
End If
If Me.Language <> "" Then
varWhere = varWhere & "[Language] = """ & Me.Language & """ AND "
End If
If Me.Format <> "" Then
varWhere = varWhere & "[Format] = """ & Me.Format & """ AND "
End If
'Here is my attempt at adding checkbox criterea...
If Me.Earthquake = -1 Then
varWhere = varWhere & "[Earthquake] = """ & Me.Earthquaket & """ AND "
End If
If IsNull(varWhere) Then
varWhere = ""
Else
varWhere = "WHERE " & varWhere
If Right(varWhere, 5) = " AND " Then
varWhere = Left(varWhere, Len(varWhere) - 5)
End If
End If
BuildFilter = varWhere
End Function