?
Solved

How do get focus to a particular field

Posted on 2007-10-16
5
Medium Priority
?
480 Views
Last Modified: 2013-11-28
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
Comment
Question by:thandel
  • 3
  • 2
5 Comments
 
LVL 58

Expert Comment

by:harfang
ID: 20090571
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
 

Author Comment

by:thandel
ID: 20090610
I guess that is the issue.... I don't know where the user is when the macro is executed.
0
 
LVL 58

Expert Comment

by:harfang
ID: 20090692
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
 

Author Comment

by:thandel
ID: 20090727
OK, but I"m not using VB but rahter the Macro gui... is your solution possible?
0
 
LVL 58

Accepted Solution

by:
harfang earned 2000 total points
ID: 20093066
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

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question