Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

referencing a subform

Status
Not open for further replies.

gwilym40

Programmer
May 2, 2002
31
GB
I've got some access code which has been working fine - not now though!!!
on my main form, a pop-up form appears which when a field upon the pop-up is clicked, it adds data to a subform on the main form - below is part of the code - it now doesn't like the docmd.gotocontrol "frmPAIS_links_SECT" line, despite that being the name of the sub-form. its worked fine before, nothing has changed!!!

DoCmd.OpenForm "frmactions_SECT"
DoCmd.GoToControl "frmPAIS_links_SECT"
DoCmd.GoToControl "ID_link"
DoCmd.GoToRecord acActiveDataObject, , acNewRec
 
Try something like this:

Forms("MainForm").Controls("SubformControl").Form.Controls("ControlName").SetFocus

You have to reference the name of the subform control, not the name of the subform itself, in order to reference the subform's controls.

Since you can use the default properties for each object, you can reduce the preceding statement to this:

Forms("MainForm")("SubformControl")("ControlName").SetFocus

If you need to use the reference more than once, try using a variable:

Dim ctl As Control

Set ctl = Forms("MainForm")("SubformControl")("ControlName")

ctl.SetFocus
ctl = <Value>
Set ctl = Nothing

I've never liked using the GotoControl method. You'll get more predictable results using a direct reference.

VBSlammer
redinvader3walking.gif
 
thats great thanks - unfortunately, it now doesn't like the
DoCmd.GoToRecord acActiveDataObject, , acNewRec??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top