FindRecord problem

P

PeteVTX

Can anyone help?

I am opening a form with subforms and I want to move to a specific record
upon opening. The underlying table includes an integer field which is the
Primary Key and I would like to use this field to find the record i.e.
DoCmd.GoToControl "empID" [primary key integer field]
DoCmd.FindRecord empID, , True, , True, , True [empID set to target record
when form opened]

But this doesn't work!

However:
DoCmd.GoToControl "userName" [string field that SHOULD be unique but on user
error may not be]
DoCmd.FindRecord userName, , True, , True, , True [userName set to target
record when form opened]

Does work!!

I don't really want to use userName to locate the record because there is a
chance of duplicated value in this field. I want to use empID to locate the
record.

Amy thoughts on why the first option doesn't work would be most welcome.

Best regards

Pete
 
S

strive4peace

Hi Pete,

try this method to find a record:

'~~~~~~~~~~~~~~
'find the first value that matches
Me.RecordsetClone.FindFirst "EmpID = " & variableEmpID

'if a matching record was found, then move to it
If Not Me.RecordsetClone.NoMatch Then
Me.Bookmark = Me.RecordsetClone.Bookmark
End If
'~~~~~~~~~~~~~~

WHERE
-- variableEmpID contains the value of the EmpID you wish to find (than
name of your variable should NOT be the same as the name of your field
or a control)
-- you are finding a record in the form you are behind

you can use a control to find a record, such as an unbound control --
but, once again, the name of the unbound control should not be the same
as the name of your field

Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top