Hello everyone, I am trying to create a database email filter based on selected checkboxes. I am using a table subform in the form in order to display filtered out content. However, I am having trouble with content display when more than one checkbox is selected. Here is the code I am using. If it is not too much trouble please help out. Thanks a lot...
-----------------------------------------------
Option Compare Database
Option Explicit
'--> Set default record source of form
Const strInfo = "SELECT strFaction,strLastName,strFirstName,strEmailAddress,strFaxNumber,strState FROM tblContacts subform"
------------------------------------------------
Private Sub cmdFilt_Click()
Dim strFilterSQL As String
If chk1.Value = True Then
strFilterSQL = strInfo & " Where [strFaction] = 'Architecture';"
ElseIf chk2.Value = True Then
strFilterSQL = strInfo & " Where [strFaction] = 'Government';"
ElseIf chk3.Value = True Then
strFilterSQL = strInfo & " Where [strFaction] = 'Planning';"
ElseIf chk4.Value = True Then
strFilterSQL = strInfo & " Where [strFaction] = 'AEP';"
ElseIf chk5.Value = True Then
strFilterSQL = strInfo & " Where [strFaction] = 'Client';"
ElseIf chk6.Value = True Then
strFilterSQL = strInfo & " Where [strFaction] = 'Government';"
ElseIf chk7.Value = True Then
strFilterSQL = strInfo & " Where [strFaction] = 'Organization';"
ElseIf chk8.Value = True Then
strFilterSQL = strInfo & " Where [strState] = 'New York';"
ElseIf chk9.Value = True Then
strFilterSQL = strInfo & " Where [strState] = 'New Jersey';"
ElseIf chk10.Value = True Then
strFilterSQL = strInfo & " Where [strState] = 'Connecticut';"
End If
Me.RecordSource = strFilterSQL
Me.Requery
End Sub
--------------------------------------------------
-----------------------------------------------
Option Compare Database
Option Explicit
'--> Set default record source of form
Const strInfo = "SELECT strFaction,strLastName,strFirstName,strEmailAddress,strFaxNumber,strState FROM tblContacts subform"
------------------------------------------------
Private Sub cmdFilt_Click()
Dim strFilterSQL As String
If chk1.Value = True Then
strFilterSQL = strInfo & " Where [strFaction] = 'Architecture';"
ElseIf chk2.Value = True Then
strFilterSQL = strInfo & " Where [strFaction] = 'Government';"
ElseIf chk3.Value = True Then
strFilterSQL = strInfo & " Where [strFaction] = 'Planning';"
ElseIf chk4.Value = True Then
strFilterSQL = strInfo & " Where [strFaction] = 'AEP';"
ElseIf chk5.Value = True Then
strFilterSQL = strInfo & " Where [strFaction] = 'Client';"
ElseIf chk6.Value = True Then
strFilterSQL = strInfo & " Where [strFaction] = 'Government';"
ElseIf chk7.Value = True Then
strFilterSQL = strInfo & " Where [strFaction] = 'Organization';"
ElseIf chk8.Value = True Then
strFilterSQL = strInfo & " Where [strState] = 'New York';"
ElseIf chk9.Value = True Then
strFilterSQL = strInfo & " Where [strState] = 'New Jersey';"
ElseIf chk10.Value = True Then
strFilterSQL = strInfo & " Where [strState] = 'Connecticut';"
End If
Me.RecordSource = strFilterSQL
Me.Requery
End Sub
--------------------------------------------------