set focus to subform?

W

Wayne Morgan

Forms!NameOfMainForm!NameOfSubformControlOnMainForm.Form!NameOfControl.SetFocus

When a form is open as a subform, it doesn't show up as itself. You have to get to it
through the main form that holds it. Once you are at the main form, you then need to refer
to the control on the main form that holds the subform.
 
G

G Lam

Hi,
How can I set focus to a field in a subform?
I wrote a line of code like this:
Forms!NameOfSubform!FidInSubForm.SetFocus
But I got "Can't find subform name" error.
Any idea?
Gary
 
G

G Lam

Wayne,
Thank you for your reply.
I got it done by setting up two variables and then set the control by two
steps.
Yours is only one line of code - that's good.
My main form is PickMain and my subform is PickSub. Where can I find the
NameOfSubFormControlOnMainForm?
Thank you again.
Gary
 
W

Wayne Morgan

To get the name of the control holding the subform, open the main form in design mode,
open the Properties sheet, and click on the subform ONE time. The properties sheet should
show the name of the subform control. If you click twice you'll be in the subform and the
properties sheet will show the name of the form, not the control holding it.
 
D

Dirk Goldgar

Wayne Morgan said:
Forms!NameOfMainForm!NameOfSubformControlOnMainForm.Form!NameOfControl.S
etFocus

When a form is open as a subform, it doesn't show up as itself. You
have to get to it through the main form that holds it. Once you are
at the main form, you then need to refer to the control on the main
form that holds the subform.

I think Gary will have to first set the focus to the subform control (on
the main form), and *then* set the focus to the specified control on the
subform; e.g.,

Forms!NameOfMainForm!NameOfSubformControlOnMainForm.SetFocus


Forms!NameOfMainForm!NameOfSubformControlOnMainForm.Form!NameOfControl.S
etFocus

(correct for line wrap)
 
W

Wayne Morgan

Yep, you're right. It takes 2 statements. Go to the subform, then the control.
 

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