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

Last reviewed: October 24, 1997
Article 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 macro action to move first to the subform, which is a type of a control, and then use 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:

   ARTICLE-ID: Q150895
   TITLE     : ACC95: Microsoft Access Sample Forms Available on MSL

   ARTICLE-ID: Q175066
   TITLE     : ACC97: Microsoft Access 97 Sample Forms Available on MSL

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.

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 demonstrates this technique using the sample database Northwind.mdb (or NWIND.MDB in version 2.0 or earlier).

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.

  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 : McrActn kbusage
Version : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Hardware : x86
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 24, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.