• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 484
  • Last Modified:

How do get focus to a particular field

I have a form that contains a sub form which contains another subform.  I need to get focus to a particular field on the 2nd sub form.  The user could be any where in the main form, sub form or the sub-sub form.  

How can I code in a way to get to a text box in the sub-sub-form?  I know there is me and me.parent (??) but it isn't always working depending on where the user is when the present code is executed.

Thank you.
0
thandel
Asked:
thandel
  • 3
  • 2
1 Solution
 
harfangCommented:
Depends on where your coding takes place. Let's imagine it's the main form:

    Me.subControlName.SetFocus
    Me.subControlName.Form.subSubControlName.SetFocus
    Me.subControlName.Form.subSubControlName.Form.ControlName.SetFocus

(°v°)
0
 
thandelAuthor Commented:
I guess that is the issue.... I don't know where the user is when the macro is executed.
0
 
harfangCommented:
It isn't. The question is only from where the code will be run. If it's a macro, your safest bet is to fully specify everything. Replace Me. with the full reference Forms!frmYourMainForm. and you will be ok.

(°v°)
0
 
thandelAuthor Commented:
OK, but I"m not using VB but rahter the Macro gui... is your solution possible?
0
 
harfangCommented:
There is no SetFocus method in macros, but GotoControl seems to work.

SelectObject
    Object Type: Form
    Object Name: frmMainForm
    In Database Window: No

GotoControl
    Control Name: subControlName

GotoControl
    Control Name: subSubControlName.

GotoControl
    Control Name: txtYourTarget

I tried this with the focus in various controls, and it seems to work. If you run this macro from a button on the main form, the first command is superfluous; if you run this from a button on the innermost subform, then you can jump directly to the target control, as pressing the button will already set the focus to that form.

You will notice that it's the same logic: select down from the main form, using the names of the subform controls, and not the names of the forms.

Good luck!
(°v°)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now