Hi
I have a form with a subform which searches the database using multiple criteria using Text Boxes and a search button. One of which is a date range(The code for which was kindly provided by another member) which is entered into 2 text boxes(SDTxt and EDTxt). At first glance the code works. If I enter 03/05/2015 in SDText and say 24/05/2015 in EDTxt and hit the search button(SearchBtn) the correct records are shown in the subform(OfficeSubform). But if I enter 05/06/2015 in SDTxt and 13/06/2015 into EDTxt not only does it show the records between the 2 dates but also all records from May. I cant understand why this would be. So any help would be greatly appreciated.
I have put on a cut down version of the code which just shows the date range search.
I have a form with a subform which searches the database using multiple criteria using Text Boxes and a search button. One of which is a date range(The code for which was kindly provided by another member) which is entered into 2 text boxes(SDTxt and EDTxt). At first glance the code works. If I enter 03/05/2015 in SDText and say 24/05/2015 in EDTxt and hit the search button(SearchBtn) the correct records are shown in the subform(OfficeSubform). But if I enter 05/06/2015 in SDTxt and 13/06/2015 into EDTxt not only does it show the records between the 2 dates but also all records from May. I cant understand why this would be. So any help would be greatly appreciated.
I have put on a cut down version of the code which just shows the date range search.
Code:
Private Sub SearchBtn_Click()
Dim strWhere As String
If IsDate(.SDTxt.Value) And IsDate(.EDTxt.Value) Then
strWhere = strWhere & _
"DateBookedIn BETWEEN #" & .SDTxt.Value & "# AND #" & .EDTxt.Value & "#" & AND_STR
End If
' Clean up and apply/remove filter
With .OfficeSubform.Form
If Len(strWhere) <> 0 Then
strWhere = Left(strWhere, Len(strWhere) - Len(AND_STR))
.Filter = strWhere
.FilterOn = True
Else
.Filter = vbNullString
.FilterOn = False
End If
End With
End With
End Sub