Getting to a control from a subform

J

Jack G

I have a form ("frmMain") with a subform in it ("frmSubForm") which in turn
has another subform in it ("frmSubSubForm").

If my cursor is in the frmSubForm and I click on a button on the frmMain,
the button works as planned (finding a record by going to a control called
"ctlNumber"); but if my cursor is in the frmSubSubForm and I click the
button in frmMain, I get an error message stating, "There is no field named
'ctlNumber' in the current record." I've tried every "DoCmd.GoToControl"
and "SetFocus" variation I could think of and just keep getting that error.

Can anyone help?

Jack
 
J

Jack G

This is what works unless the cursor is in frmSubSubForm when the button is
clicked:

Private Sub cmdNext_Click()
DoCmd.GoToControl "frmSubForm" 'This is where the ctlNumber is.
DoCmd.GoToControl "ctlNumber" 'This is where it gets stuck.
DoCmd.GoToRecord , , acNext
Forms!frmMain!ctrGoTo = Me!ctlNumber
CurrentDb.Properties("CurrentNumber") = Me!frmSubform!ctlNumber
End Sub

Jack
 
K

Ken Snell \(MVP\)

It's likely a timing issue; the code may be running before the form's focus
is fully resolved.

In situations such as this, it's best to use explicit referencing to the
subform and its controls; try this:

Private Sub cmdNext_Click()
Me.frmSubForm.SetFocus
Me.frmSubFormForm.ctlNumber.SetFocus
DoCmd.GoToRecord , , acNext
Forms!frmMain!ctrGoTo = Me!ctlNumber
CurrentDb.Properties("CurrentNumber") = Me!frmSubform!ctlNumber
End Sub
 

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

Top