Goto help

K

KPE

I want to go to a specific record using ClientID, when i do as follows
the code brings up the 706th record Can you tell me how to correct my code?
Thank you,
DoCmd.GoToRecord acDataForm, "frmClients", , 706
 
M

Mr B

You need to first set the focus to the ClientID field on your form. (In many
cases, this field may be hidden. This would mean that you would first need to
make the field visible, then set the focus.)

Once you have set the focus you can find the value you are looking for. Your
code might look somegthing like:

Me.txtClientID.SetFocus
DoCmd.FindRecord ClientIdValue

The "txtClientID" above will be the name of the actual ClientID control on
your form)
"ClientIdValue" above is the ClientID value that you want to find.

If you needed to make the control visible before setting the focus to it,
then you will need to set the focus to another control prior to making the
ClientID controls not visible again.
 
M

Marshall Barton

KPE said:
I want to go to a specific record using ClientID, when i do as follows
the code brings up the 706th record Can you tell me how to correct my code?
Thank you,
DoCmd.GoToRecord acDataForm, "frmClients", , 706


That's what GoToRecord does. You probably intended to use
FindRecord.

Either way, those menu item simulations are not the
recommended way to locate a record that matches a value. It
takes more than one line of code, but it's more precise and
more flexible:

With Me.RecordsetClone
.FindFirst "ClientID = 706"
If Not .MoMatch Then Me.Bookmark = .Bookmark
End With

If you want to use a text box in the form's header to enter
the ID, then use this kind of FindFirst:
.FindFirst "ClientID = " & Me.sometextbox
 
Top