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

ID: Q209689


The information in this article applies to:
  • Microsoft Access 2000

Novice: Requires knowledge of the user interface on single-user computers.

This article applies to a Microsoft Access database (.mdb) and 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.


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: Following the steps in this example will modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and perform these steps on a copy of the database.

  1. Open the sample database Northwind.mdb.


  2. Create the following new macro called GoToSubform:


  3. 
       Macro Name      Macro Actions
       -----------------------------
       GoToSubform     GoToControl
                       GoToControl
    
       GoToSubform Actions
       -------------------------------
       GoToControl
       Control Name: Orders Subform
       GoToControl
       Control Name: ProductID 
  4. Open the Orders form in Design view.


  5. Add a command button to the form and set the following properties:


  6. 
       Caption: Enter/Modify Orders
       OnClick: GoToSubform 
  7. 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.

Additional query words: how to

Keywords : kbusage kbdta McrActn
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: November 13, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.