ACC2000: How to Set Focus to a Subform Control Using GoToControl (209689)



The information in this article applies to:

  • Microsoft Access 2000

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).

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

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.

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.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbhowto kbProgramming kbusage KB209689