GoToRecord on another form

  • Thread starter Thread starter BruceM
  • Start date Start date
B

BruceM

I am trying to go to the first record on a subform from another form under
certain conditions. I have an unbound instructions form that contains a
button that when clicked will take me to the first record on the subform. I
can get to the first record on the main form:

DoCmd.GoToRecord acDataForm, "frmMain", acFirst

but I cannot find a way to make it work for the subform. Any ideas?
 
Hi Bruce

Subforms are not directly accessible in the same way as main forms, because
they are not members of the Forms collection. The only way to reference a
subform from another form is by way of the subform control that contains it.

Say you have a form, frmCustomers, and it contains a subform,
frmCustOrderList, in a subform control named sbfOrderList.

You could use code like this:

Dim frm as Form
Set frm = Forms("frmCustomers")("sbfOrderList").Form
With frm.RecordsetClone
.MoveFirst
frm.Bookmark = .Bookmark
End With
 
Thanks, Graham, that did the trick perfectly.

Graham Mandeno said:
Hi Bruce

Subforms are not directly accessible in the same way as main forms,
because they are not members of the Forms collection. The only way to
reference a subform from another form is by way of the subform control
that contains it.

Say you have a form, frmCustomers, and it contains a subform,
frmCustOrderList, in a subform control named sbfOrderList.

You could use code like this:

Dim frm as Form
Set frm = Forms("frmCustomers")("sbfOrderList").Form
With frm.RecordsetClone
.MoveFirst
frm.Bookmark = .Bookmark
End With

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand


BruceM said:
I am trying to go to the first record on a subform from another form under
certain conditions. I have an unbound instructions form that contains a
button that when clicked will take me to the first record on the subform.
I can get to the first record on the main form:

DoCmd.GoToRecord acDataForm, "frmMain", acFirst

but I cannot find a way to make it work for the subform. Any ideas?
 

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

Back
Top