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

Goto Record in recordset

Status
Not open for further replies.

Digsys

Technical User
Jun 27, 2002
170
AU
I have called a form from a procedure using DoCmd.openform and in the newly opened form on the OPEN event, I want to go to a specific record, so I use the following code:
Dim rs as recordset
set rs=me.recordset
rs.findfirst "fieldname = value etc
but I get the message method or data memeber not found. Can anyone please help.
I have access 2000
 
Well how should the form know which record you want.

Are selecting a record in Combo Box or do you have a field where you enter the record number. The message you are getting is 100% correct me.recordset is not set to anything when the form opens.

So let me know how are you telling the form which record you want, when you open it.
 
In addition to zevw comments - just point out that 'IF' you have references set to both ADO and DAO then Sample1 below can produce the error you described. It can be resolved by indicating the reference you wish to use in the dimensioning of the variables as shown in Sample2.

Sub Sample1()
Dim dbSample As Database
Dim rsSample As Recordset
Set dbSample = CurrentDb
Set rsSample = dbSample.OpenRecordset("AcctTable", dbOpenDynaset)
rsSample.FindFirst "Age = " & 23
MsgBox rsSample.Fields(2).Value
End Sub

Sub Sample2()
Dim dbSample As DAO.Database
Dim rsSample As DAO.Recordset
Set dbSample = CurrentDb
Set rsSample = dbSample.OpenRecordset("AcctTable", dbOpenDynaset)
rsSample.FindFirst "Age = " & 23
MsgBox rsSample.Fields(2).Value
End Sub
 
Follow KevinClarks advice and make the references to any data object explicit, either DAO or ADO whichever you intend to use.

The reason for your error is that Access 2000 defaults to ADO and there is no FindFirst method in ADO. The Find method will work in ADO, or Filter both will do what you need.

ie.
rs.Find "fieldname = value etc
rs.Filter "fieldname = value etc
rs.Filter = adFilterNone '- turn off filter.

 
Hi

so u want to go at particular record in form
try this coding

sub sample()
dim db as database
dim rst as recordset
dim varbook as variant
set rst = db.openrecordeset("select * from table")

rst.findfirst "[fieldnmae] = value"
varbook = rst.bookmark
'go to the particular record
if rst.nomatch = false then
me.bookmark = rst.bookmark
end if
end sub

okay best luck!!!
 
shital78

I agree but why not use the recordsetclone of me and not jerk the records in your form around.

Rollie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top