ACC: How to Move from Subform to Main Form Using TAB or ENTER

Last reviewed: October 24, 1997
Article ID: Q154893
The information in this article applies to:
  • Microsoft Access versions 2.0, 7.0, 97

SUMMARY

Moderate: Requires basic macro, coding, and interoperability skills.

This article demonstrates how you can press the Tab key or Enter key to move from the last control on the last record of a subform to a specified control on the main form.

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

By default, Microsoft Access allows you to press the Tab key or Enter key to move the focus from one control to another on a form, according to the form's tab order. This includes moving to subform controls. However, Tab or Enter keystrokes do not move the focus from a subform control back to the main form.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access version 2.0. For more information about Access Basic, please refer to the "Building Applications" manual.

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

NOTE: In the example below, you can remove the line of code that uses the Requery method of the subform control if you are using version 2.0. It is there for compatibility with the form's Cycle property, which is a new feature in version 7.0.

  1. Open the Northwind sample database.

  2. Click the Forms tab and open the Orders Subform in Design view.

  3. Set the OnExit property of the form's Discount control to the following event procedure:

          Private Sub Discount_Exit(Cancel As Integer)
    

          On Error Goto Error_Routine
    

          Dim RS As Recordset
          Set RS = Me.RecordsetClone
          RS.MoveLast
          If StrComp(Me.Bookmark, rs.Bookmark, 0) = 0 Then
    
             Forms![Orders]![Freight].SetFocus
             ' The following line may be removed in version 2.0
             Forms![Orders]![Orders Subform].Requery
          End If
          Exit Sub
    
          Error_Routine:
             MsgBox "You must be on a record with data"
          Exit Sub
          End Sub
    
    

  4. Save the Orders Subform and close it.

  5. Open the Orders form in Form view and press the Tab key or the Enter key to move from one control to the next on the form. Notice that the form's Freight control receives the focus when you press Tab or Enter from the Discount control of the last record displayed on the subform.

REFERENCES

For more information about setting a form's tab order, search for "tab order in forms," and then "Change tab order in a form" using the Microsoft Access 97 Help Index.

For more information about the Bookmark property, search on the phrase "Bookmark," and then view "Bookmark Property (Microsoft Access)" using the Microsoft Access for Windows 97 Help Index.


Additional query words: navigate programmatically
Keywords : kbusage FmsHowTo FmsSubf
Version : 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.