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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you move to a specific record?

Status
Not open for further replies.

MrMajik

IS-IT--Management
Apr 2, 2002
267
Opening a recordset as ADODB...I have a loop that searches for a record in a table using the MoveNext command until the search is satisfied.

TableName = tblAgency
The field on the form that the search is done to is called txtAgencyId

When it finds the record how do I make that record the current record so it's data appear in the fields on a form?

Thank you.
 
I assume you have a form that does not have a RecordSource but does have unbound controls on it? If so, you write code to set the value of the controls to the values in the recordset.
 
Try this bit of code: Set it on your form's "On Open" event

Me.RecordsetClone.MoveLast
Me.Bookmark = Me.RecordsetClone.Bookmark

jbehrne If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
 
Sorry,

That returns the last record! I pulled it from the wrong form in my db...

Try this instead:
- You will have to rename FormName to your form's name in the code
- You will have to rename YourVariableHoldingValue to whatever the name of your variable is that holds the value returned from your loop
**********************************************************
Dim RecNum

RecNum = YourVariableHoldingValue
Requery
Forms!FormName.RecordsetClone.FindFirst "FormName.txtAgencyId
= " & RecNum
Forms!FormName.Bookmark = Forms!FormName.RecordsetClone.Bookmark
**********************************************************

HTH,

jbehrne If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top