Need help with code

  • Thread starter Thread starter Kathy
  • Start date Start date
K

Kathy

I want to select a record from a datasheet that opens with
a command button on my main form and have the main form go
to the selected record. I want to use the On Click event,
so the user can click in the EmpID field of a particular
record in the datasheet and have the main form also go to
that record. The datatsheet form and the main form are
related by this field and this field is an Auto Number in
the Main Form. I think I can use the DoCmd.FindRecord,
but I am unsure of the language after that. Or should I
try Do.CmdGoToRecord? Again, I am not familiar with the
language after that. Any suggestions?

Also, is there a way to select an Auto Number control,
enter a number and have the current record become the
record number you entered? When I put the focus in my
AutoNumber field on my form, it will not let me enter
anything because an AutoNumber cannot be edited. I don't
want to edit it, I just want to make it the current
record. Any suggestions there?

Any help will be truly appreciated,
Kathy
 
this is code from another forum found 'here'
(http://www.accessvba.com/showthread.php?s=&threadid=8253)

you can use this code to do what you are looking for:

Code:
--------------------

Dim rs As Object

Set rs = Me.Parent.Recordset.Clone
rs.FindFirst "[EmpID] = " & Me.EmpID
Me.Parent.Bookmark = rs.Bookmark

set rs=nothing

--------------------

just put the above code into the OnClick event of the subform's EmpID
field.

As for you other question, you can't use the AutoNumber field to bring
up a record. if you have bound a control to the autonumber, it will
only accept data entry. you need to create a search method by using an
unbound control. you can use the code above as well for this. just
change this line:

Code:
--------------------

rs.FindFirst "[EmpID] = " & Me.EmpID

--------------------


to this:


Code:
 
Yakule,

Hey, thanks for the response. I tried entering the code
you suggested and I get the following error:

Run-time error '2452':

The expression you entered has an invalid reference to the
Parent property.

I tried changing the rs to rst and I tried changing
Recordset.Clone to RecordsetClone and neither of those
works. I also went to the website you mentioned and
browsed the POSTS there. Great website. Any sugegstions
on the error?
Thanks again, Kathy
 
Back
Top