I
injanib via AccessMonster.com
I have, on my form, a search button and an unbound textbox to input date
values to be searched for.
I want the code on On Click Event property of the button to filter the
database for Dates in the field called [ReceivedOn]. If there is no matching
record it should display a message saying so. I have tried the following code
and I suspect an error in the format of the dates. It will give me the error
message even if a record exists for that date. Please tell me what is wrong
with my code.
Private Sub Search_Click()
Dim strWhere As String
Const conJetDate = "\#mm\/dd\/yyyy\#"
If IsNull(Me.txtSearchDate) Or Me.txtSearchDate = "" Then
MsgBox "Please Enter a Date", vbOKOnly, "Data Needed!"
Me.txtSearchDate.SetFocus
Else
If DCount("*", "Tracking", "[ReceivedOn]=" & Me.txtSearchDate) > 0 Then
strWhere = "([ReceivedOn] = " & Format(Me.txtSearchDate, conJetDate)
& ")"
Me.Filter = strWhere
Me.FilterOn = True
Else
MsgBox "No record found for the date specified. Please try again.",
vbOKOnly, "Not Found!"
Me.txtSearchDate.SetFocus
End If
End If
End Sub
values to be searched for.
I want the code on On Click Event property of the button to filter the
database for Dates in the field called [ReceivedOn]. If there is no matching
record it should display a message saying so. I have tried the following code
and I suspect an error in the format of the dates. It will give me the error
message even if a record exists for that date. Please tell me what is wrong
with my code.
Private Sub Search_Click()
Dim strWhere As String
Const conJetDate = "\#mm\/dd\/yyyy\#"
If IsNull(Me.txtSearchDate) Or Me.txtSearchDate = "" Then
MsgBox "Please Enter a Date", vbOKOnly, "Data Needed!"
Me.txtSearchDate.SetFocus
Else
If DCount("*", "Tracking", "[ReceivedOn]=" & Me.txtSearchDate) > 0 Then
strWhere = "([ReceivedOn] = " & Format(Me.txtSearchDate, conJetDate)
& ")"
Me.Filter = strWhere
Me.FilterOn = True
Else
MsgBox "No record found for the date specified. Please try again.",
vbOKOnly, "Not Found!"
Me.txtSearchDate.SetFocus
End If
End If
End Sub