I've produced the following code:
For some perculiar reason, the filter on DOB works fine when the surfacs ID (an alphnumeric string) is not set in the table, but returns no results when it is.
This is either going to be really simple, or fiendishly subtle. Any suggestions?
Stuart
Code:
Function FilterServiceUser()
Dim SUFilter As String
Dim varFilter_Surfacs As String
Dim varFilter_Surname As String
Dim varFilter_FirstName As String
Dim varFilter_DOB As String
'Set values, making sure to set them empty strings if the filed id empty (by adding a "" at the end)
varFilter_Surfacs = Forms!frmListServiceUsers!Filter_Surfacs & ""
varFilter_Surname = Forms!frmListServiceUsers!Filter_Surname & ""
varFilter_FirstName = Forms!frmListServiceUsers!Filter_FirstName & ""
varFilter_DOB = Forms!frmListServiceUsers!Filter_DOB & ""
'Set filter for Surfacs ONLY if Filter_Surfacs is set
If varFilter_Surfacs = "" Then
SUFilter = ""
Else
SUFilter = "Surfacs Like '*" & varFilter_Surfacs & "*' AND "
End If
'Append filter for surname and first name whether set or not
SUFilter = SUFilter & "Surname Like '*" & varFilter_Surname & "*' AND "
SUFilter = SUFilter & "FirstName Like '*" & varFilter_FirstName & "*'"
'Append filter for DOB ONLY if Filter DOB is set
If Forms!frmListServiceUsers!Filter_DOB <> "" Then
SUFilter = SUFilter & " AND DOB = #" & (varFilter_DOB) & "#"
End If
'For some reason, does not find DOB when the surfacs value is set (the actual
'value, not the filter). For the time being, DOB search is broken.
MsgBox (SUFilter)
'Apply filter
Forms!frmListServiceUsers!frmListServiceUsers_Sub.Form.Filter = SUFilter
Forms!frmListServiceUsers!frmListServiceUsers_Sub.Form.FilterOn = True
End Function
For some perculiar reason, the filter on DOB works fine when the surfacs ID (an alphnumeric string) is not set in the table, but returns no results when it is.
This is either going to be really simple, or fiendishly subtle. Any suggestions?
Stuart