In addition to Ajax's comments, I would write the code more like Allen Browne's example. (http://allenbrowne.com/ser-62code.html)
This is what I came up with
Code:
Private Sub YourButton_Click()
Dim Locn As String
Dim Disp As String
Dim fltLocn As String
Dim fltDisp As String
Dim strWhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria string to append to.
Me.Filter = ""
Me.FilterOn = False
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If IsNull(Me.txtSLocn) = False And Me.txtSLocn <> "" Then
Locn = Me.txtSLocn
strWhere = "Locn like '" & Locn & "*' AND "
End If
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'start date
If Not IsNull(Me.txtSDispStart) Then
strWhere = strWhere & "[Disp] >= #" & Me.txtSDispStart & "# AND "
End If
'end date
If Not IsNull(Me.txtSDispEnd) Then
strWhere = strWhere & "[Disp] <= #" & Me.txtSDispEnd & "# AND "
End If
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'See if the string has more than 5 characters (a trailng " AND ") to remove.
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
ClearFilter
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the " AND " at the end.
strWhere = Left(strWhere, lngLen)
'For debugging, remove the leading quote on the next line. Prints to Immediate Window (Ctrl+G).
' Debug.Print strWhere
'Finally, apply the string as the form's Filter.
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub