Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DOB recordset search

Status
Not open for further replies.

eussias

Programmer
Sep 25, 2001
97
AU
The code below is working fine for the majority of the records, but for some reason, every known and then, will not find a specific date that is already in the database. It is used to search for a patient with a specific date of birth. Does anyone know why this may be happening?

Dim rst As Recordset
Dim myBookmark As Date
txtDate.SetFocus
If txtDate.Text = "" Then
MsgBox "You must enter a Date of Birth"
Exit Sub
End If
Set rst = CurrentDb.OpenRecordset("SELECT * FROM ClientInfo WHERE [DOB] = #" & txtDate.Text & "#")
On Error Resume Next
Dim MyValue As Date
MyValue = txtDate
rst.MoveFirst
If rst.Fields(&quot;DOB&quot;) <> MyValue Then
MsgBox &quot;No record for that patient&quot;, vbInformation, &quot;LMTC Database&quot;
txtDate.Text = &quot; &quot;
txtDate.SetFocus
Exit Sub
End If
Me.RecordsetClone.FindFirst &quot;[DOB] = #&quot; & MyValue & &quot;#&quot;
Me.Bookmark = Me.RecordsetClone.Bookmark
 
Perhaps, you are getting a result but your DOB field might have time in it or there's a difference in formats between the textbox and the DOB field. Hence the values are not exact but the messagebox appears. Have you tried using something like:
Code:
Debug.print &quot;DOB Field Value: &quot; & rst.Fields(&quot;DOB&quot;) _
            & vbcrlf & &quot;MyValue&quot;: &quot; & cstr(MyValue)

Hope this helps,
Rewdee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top