I've created a form that allows me to select the email addresses that I want from the database based on the dataset that the customers has signed up for.
I now need to put another filter on this so that as well selecting which dataset the customer has signed up, but it also selects the type of customer they are. Eg provider, commissioner, Third Party etc so that the emails are sent to the appropriate customers. For example, the provider email may contain information that isn't relevent to commissioners so there isn't any point in sending to them so I want to filter them out.
I've included the code that allows me to select datasets, sometmes we will want to send the same email to customers of two or more datasets.
I've commented out the category section at the moment as it isn't working and is returning just based on dataset at the moment and ignores the additional filter.
How do I modify the code to include this secondary filter?
Many thanks for reading this and any help provided will be much appreciated.
I now need to put another filter on this so that as well selecting which dataset the customer has signed up, but it also selects the type of customer they are. Eg provider, commissioner, Third Party etc so that the emails are sent to the appropriate customers. For example, the provider email may contain information that isn't relevent to commissioners so there isn't any point in sending to them so I want to filter them out.
I've included the code that allows me to select datasets, sometmes we will want to send the same email to customers of two or more datasets.
I've commented out the category section at the moment as it isn't working and is returning just based on dataset at the moment and ignores the additional filter.
How do I modify the code to include this secondary filter?
Many thanks for reading this and any help provided will be much appreciated.
Code:
Option Compare Database
Option Explicit
Private Sub DistroClear_Click()
Dim intIndex As Integer
' Clear all search items
Me.cmbMHMDS = ""
Me.cmbIAPT = ""
Me.cmbChild = ""
Me.cmbComm = ""
Me.cmbCAMHS = ""
Me.cmbYPEOPLE = ""
Me.cmbKey = ""
' Reset
If BuildFilter = "" Then
Me.frmDistroSub.Form.RecordSource = "SELECT * FROM qryDistro " & BuildFilter
Else
Me.frmDistroSub.Form.RecordSource = "SELECT * FROM qryDistro WHERE " & BuildFilter
End If
End Sub
Private Sub DistroSearch_Click()
' Update the record source
If BuildFilter = "" Then
Me.frmDistroSub.Form.RecordSource = "SELECT * FROM qryDistro " & BuildFilter
Else
Me.frmDistroSub.Form.RecordSource = "SELECT * FROM qryDistro WHERE " & BuildFilter
End If
End Sub
Private Function BuildFilter() As Variant
Dim varWhere As Variant
Dim varItem As Variant
Dim intIndex As Integer
varWhere = Null ' Main filter
' Check for MHMDS
If Me.cmbMHMDS = -1 Then
varWhere = varWhere & "([DS_MHMDS] = True) OR "
ElseIf Me.cmbMHMDS = 0 Then
varWhere = varWhere & "([DS_MHMDS] = False) OR "
End If
' Check for IAPT
If Me.cmbIAPT = -1 Then
varWhere = varWhere & "([DS_IAPT] = True) OR "
ElseIf Me.cmbIAPT = 0 Then
varWhere = varWhere & "([DS_IAPT] = False) OR "
End If
' Check for Children
If Me.cmbChild = -1 Then
varWhere = varWhere & "([DS_CHILDREN] = True) OR "
ElseIf Me.cmbChild = 0 Then
varWhere = varWhere & "([DS_CHILDREN] = False) OR "
End If
' Check for Community
If Me.cmbComm = -1 Then
varWhere = varWhere & "([DS_COMMUNITY] = True) OR "
ElseIf Me.cmbComm = 0 Then
varWhere = varWhere & "([DS_COMMUNITY] = False) OR "
End If
' Check for CAMHS
If Me.cmbCAMHS = -1 Then
varWhere = varWhere & "([DS_CAMHS] = True) OR "
ElseIf Me.cmbCAMHS = 0 Then
varWhere = varWhere & "([DS_CAMHS] = False) OR "
End If
' Check for Young People
If Me.cmbYPEOPLE = -1 Then
varWhere = varWhere & "([DS_YPEOPLE] = True) OR "
ElseIf Me.cmbYPEOPLE = 0 Then
varWhere = varWhere & "([DS_YPEOPLE] = False) OR "
End If
' ' Check for Category
' If Not IsNull(Me.cmbCategory) Then
' varWhere = varWhere & "([Category] = """ & Me.cmbCategory & """) AND "
' End If
'
' Check if there is a filter to return...
If IsNull(varWhere) Then
varWhere = ""
Else
' strip off last "OR" in the filter
If Right(varWhere, 4) = " OR " Then
varWhere = Left(varWhere, Len(varWhere) - 4)
End If
End If
BuildFilter = varWhere
End Function
Private Sub ExitDistro_Click()
On Error GoTo Err_Exitsearch_Click
DoCmd.Close
Exit_Exitsearch_Click:
Exit Sub
Err_Exitsearch_Click:
MsgBox Err.Description
Resume Exit_Exitsearch_Click
End Sub