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

ID: Q95014


The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0, 7.0, 97


SUMMARY

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

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 files, FrmSampl.exe (for Microsoft Access for Windows 95 version 7.0) and FrmSmp97.exe (for Microsoft Access 97). For information about how to obtain these sample files, please see the following articles in the Microsoft Knowledge Base:

Q150895 ACC95: Microsoft Access Sample Forms Available in Download Center

Q175066 ACC97: Microsoft Access 97 Sample Forms Available in Download Center


MORE INFORMATION

The macro action GoToControl does not allow you to use the full syntax for the ControlName argument as:


   Forms![orders]![orders subform]![ProductID]

   NOTE: In versions 1.x and 2.0, there is a space in Product ID field
   name. 


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.

The following example uses the sample database Northwind.mdb (or NWIND.MDB in version 2.0 or earlier) to demonstrates this technique.

CAUTION: Following the steps in this example will modify the sample database Northwind.mdb (or NWIND.MDB in version 2.0 or earlier). You may want to back up the Northwind.mdb (or NWIND.MDB) file and perform these steps on a copy of the database.
  1. Open the sample database Northwind.mdb (or NWIND.MDB in version 2.0 or earlier).


  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 (or Product ID in version 1.x or 2.0) 


  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 (or OnPush in 1.x): GoToSubform 


  5. Open the Orders form in Form view. Click the Enter/Modify Orders button and note that the insertion point moves to the Product field (or the Prod ID field in version 1.x or 2.0) on the Orders subform.



REFERENCES

For more information about moving to a specific control, search for "GotoControl action" using the Microsoft Access 97 Help Index.

Additional query words: how to

Keywords : kbusage McrActn
Version : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Issue type : kbhowto


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