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!

Searching recordset for specific date

Status
Not open for further replies.

eussias

Programmer
Sep 25, 2001
97
AU
Can anyone help??!! I've been trying to get this code below to work, and for some reason it's fully working... The user enters a Date into the txtDate text box and when the Command Button is clicked the recordset is serched, looking for a matching DOB. When the record is found it drops out of the loop, but for some reason is not navigating to the record.
Skep has suggested numerous things, and as yet we have had no success. Any help would be greatly appreciated!! :cool:

Dim rst As Recordset
Dim myBookmark As Date
Set rst = CurrentDb.OpenRecordset("ClientInfo", dbOpenDynaset)
On Error Resume Next
rst.MoveFirst
Dim MyValue As Date
MyValue = txtDate
Do While Not rst.EOF
If rst.Fields("DOB") = MyValue Then
myBookmark = rst.Bookmark
Exit Do
End If
rst.MoveNext
Loop
If rst.Fields(&quot;DOB&quot;) <> MyValue Then
MsgBox &quot;No record for that patient&quot;, vbInformation, &quot;LMTC Database&quot;
txtClientSrch.Text = &quot; &quot;
txtClientSrch.SetFocus
Exit Sub
End If
Me.RecordsetClone.FindFirst &quot;[DOB] = &quot; & MyValue
Me.Bookmark = Me.RecordsetClone.Bookmark
 
Why not &quot;SELECT * FROM ClientInfo WHERE DOB = #&quot; & txtDate.Text & &quot;#&quot;.

That will then only create a recordset with matching dates in. Seems a bit odd to build a recordset and then loop to find matching ones.

Craig
 
Craig,

Thanks for that. Got it working perfectly now.... got rid of a lot of redundant code. Thanks again :cool:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top