Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: How to Set Focus to a Subform Control Using GoToControl


View products that this article applies to.

This article was previously published under Q209689
Novice: Requires knowledge of the user interface on single-user computers.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

↑ Back to the top


Summary

To set the focus to a control on a subform, you can create a macro that uses the GoToControl action to first move to the subform (which is a type of a control), and then uses the GoToControl action again to move to a particular control on the subform.

NOTE: This article explains a technique demonstrated in the sample file, FrmSmp00.mdb. For information about how to obtain this sample file, please see the following article in the Microsoft Knowledge Base:
233324� ACC2000: Microsoft Access 2000 Sample Forms Database Available in Download Center

↑ Back to the top


More information

The GoToControl macro action does not allow you to use the full syntax for the ControlName argument as:
   Forms![orders]![orders subform]![ProductID]
				
If you use this syntax, you may receive the following error message:
There is no field named 'Forms![Orders]![Orders subform]![ProductID]' in the current record.
To work around this behavior, you need to set up a macro that first sets the focus to the subform control, and then sets the focus to a specific control on the subform.

CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

  1. Open the sample database Northwind.mdb.
  2. Create the following new macro called GoToSubform:
       Macro Name      Macro Actions
       -----------------------------
       GoToSubform     GoToControl
                       GoToControl
    
       GoToSubform Actions
       -------------------------------
       GoToControl
       Control Name: Orders Subform
       GoToControl
       Control Name: ProductID
    					
  3. Open the Orders form in Design view.
  4. Add a command button to the form and set the following properties:
       Caption: Enter/Modify Orders
       OnClick: GoToSubform
    					
  5. Open the Orders form in Form view. Click the Enter/Modify Orders button. Note that the insertion point moves to the Product field on the Orders subform.

↑ Back to the top


References

For more information about moving to a specific control, click Microsoft Access Help on the Help menu, type GotoControl action in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB209689, kbusage, kbprogramming, kbhowto

↑ Back to the top

Article Info
Article ID : 209689
Revision : 4
Created on : 10/11/2006
Published on : 10/11/2006
Exists online : False
Views : 344