Macro to move focus from a subform to mainform

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

I have a form with 2 nested subforms(a form with a
subform (first level) and a subform (second level) within
the subform (first level)). I would like to move the
focus from the second level subform to the first level
subform. The "GoToControl" is effective in moving the
focus downward through the subforms, but I don't know how
to move the focus upward from the second level subform to
the first level subform. Thank you.
 
i couldn't figure out a way to do it with a macro, either.
but if you don't mind using a smidgen of VBA, go to the
place you wanted to call a macro and substitute an event
procedure. then put this line of code in the event
procedure:

Me.Parent!ControlName.SetFocus

change ControlName to the name of the control, in the
first level subform, that you want to "land" on.

hth
 
Thanks Tina, Please excuse my ignorance in this matter,
but I am having trouble with the me.parent statement.
The name of the main form is frmprmaster, the name of the
first level subform is frmpr and the name of the conrol
on this form I would like to recieve the focus is
VendorNumber, the name of the second level subform is
AccountDistribution. Can you help me with the syntax of
the statment when name the "ControlName" because I keep
getting an error message. Dan.
 
try:

Me.Parent!VendorNumber.SetFocus

did you set this up as an event procedure? i'll try to
explain how w/o being too wordy. you call a macro from an
event property, such as a command button's On Click event,
right? ok, go to the event property where you wanted to
call your macro. click on the line, then click on the
ellipsis (...) button at the right of the line. select
Code Builder from the dialog box. Access creates a sub
procedure for that event, and takes you to it. put the
above line of code in the sub procedure, between the
Private Sub and End Sub lines.

if that line of code won't work for you, try this one:

Forms!frmprmaster!frmpr!VendorNumber.SetFocus

this long form can be tricky, because the subform control
in frmprmaster might not be named frmpr, you'll have to
check it.

hth
 
Back
Top