Finding a Specific record problem

  • Thread starter Thread starter trekgoes2malaysia
  • Start date Start date
T

trekgoes2malaysia

I am trying to go to a specific record on a form that opens when a
user clicks on a certain control on a parent form. Problem is I
can't get it to go to the specific record. Instead I get the following
error "Microsoft Office Access can't move the focus to the control
id.". Below are 2 methods of code I used but both return the same
error. What am I doing wrong???

Method 1:
Dim stDocName As String
Dim getathlete As Integer

getathlete = Me![athleteid1]
stDocName = "Cyclists"

DoCmd.OpenForm stDocName ' open form when control is
clicked
[Forms]![Cyclists]!id.SetFocus ' goto record number
control
DoCmd.FindRecord id = getathlete ' find record

Method 2:
Dim stDocName As String
Dim stcontrol As String
Dim getathlete As Integer

getathlete = Me![athleteid1]
stcontrol = "id"

stDocName = "Cyclists"
DoCmd.OpenForm stDocName ' open form when control is clicked
DoCmd.GoToControl stcontrol ' goto record number control
DoCmd.FindRecord getathlete ' find record
 
Do you HAVE a control with that name?
Is it hidden?

If you do and its isn't hidden then maybe "id" is a "reserved word" (there
are so many of those I can't keep track)

You might want to rename that field.
hth
 
The problem is that the Cyclist form is not yet in a state where a control
can accept the focus. You need to do it a different way. There are a couple
of options. You can pass the key to the record in the OpenArgs argument of
the OpenForm method and go to the record in the form Load event or you can
open the form using the Where argument of the OpenForm method to identify the
record.
 
Back
Top