Move Focus to a Record on Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If I have a standard form attached to a table, and I want to open that form
and move to a specific record, how do I accomplish this?

I understand how to use a where condition to filter the form to the record I
want, but seem to be a bit daft on the whole moving to the record I want
part...

It is Friday after all...

Thanks,

-David
 
doCmd.openform "frmMyForm"

and im trying to filter by a specific Id which I have on the calling form.
so I could
doCmd.openform "frmMyForm",,,"Id = " & me.Id

but that of course filters the result set to the single record, whereas I
simply want that record selected, but the user able to navigate to the rest
of the result set.

-David
 
OK - you can do what you want by a slight variation with your approach.

Let's pass the "filter" string as the OpenArgs argument for the OpenForm
action:
DoCmd.OpenForm "frmMyForm", OpenArgs:="Id = " & me.Id

Now, in the frmMyForm form, let's add code in the form's Load event that
will move it to the desired record:

Private Sub Form_Load()
If Len(Me.OpenArgs & "") > 0 Then
With Me.RecordsetClone
.FindFirst Me.OpenArgs
If .NoMatch = False Then Me.Bookmark = .Bookmark
End With
End If
End Sub


--

Ken Snell
<MS ACCESS MVP>
 
Excellent thanks, I actually made a slight variation which I've added for the
benefit of anyone reading the thread...

strId = "Id = " & me.Id
If (CurrentProject.AllForms("frmMyForm").IsLoaded) Then
Form_frmMyForm.PopData strId
Form_frmMyForm.SetFocus
Else
DoCmd.OpenForm "frmMyForm", OpenArgs:=strId
End If

In frmMyFrm in the onload I have the check for openArgs
which calls PopData if openArgs is set.
Otherwise if the form is open we just call PopData.

PopData runs the other parts of the code you included.

Thanks again!

-David
 
Back
Top