Microsoft KB Archive/104683

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 16:45, 20 July 2020 by X010 (talk | contribs) (Text replacement - ">" to ">")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Article ID: 104683

Article Last Modified on 5/6/2003



APPLIES TO

  • Microsoft Access 1.0 Standard Edition
  • Microsoft Access 1.1 Standard Edition
  • Microsoft Access 2.0 Standard Edition



This article was previously published under Q104683

SUMMARY

Advanced: Requires expert coding, interoperability, and multiuser skills.

The navigation (VCR) buttons that appear on a form's horizontal scroll bar provide a convenient way of navigating among records.

The following information describes how to create custom navigation buttons on your own forms.

This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information on Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x, or the "Building Applications" manual in version 2.0.

MORE INFORMATION

The following sample module demonstrates Access Basic functions that can be used to create custom buttons for navigating among first, last, previous, and next records on a form. Functions are provided to navigate through forms as well as subforms.

To create custom navigation buttons on a form, create a new module with the following Access Basic code:

   '*******************************************
   ' MODULE DECLARATION SECTION
   '*******************************************
   Option Explicit
   Dim RetVal As Variant

   '*******************************************
   ' MODULE FUNCTIONS
   '*******************************************

   Function GotoFirstRecord ()
      RetVal = GotoRecord(A_FIRST)
   End Function

   Function GotoLastRecord ()
      RetVal = GotoRecord(A_LAST)
   End Function

   Function GotoNextRecord ()
      RetVal = GotoRecord(A_NEXT)
   End Function

   Function GotoPrevRecord ()
      RetVal = GotoRecord(A_PREVIOUS)
   End Function

   Function GotoFirstSubRecord (SubControlName As String)
      DoCmd GoToControl SubControlName
      RetVal = GotoFirstRecord()
   End Function

   Function GotoLastSubRecord (SubControlName As String)
      DoCmd GoToControl SubControlName
      RetVal = GotoLastRecord()
   End Function

   Function GotoNextSubRecord (SubControlName As String)
      DoCmd GoToControl SubControlName
      RetVal = GotoNextRecord()
   End Function

   Function GotoPrevSubRecord (SubControlName As String)
      DoCmd GoToControl SubControlName
      RetVal = GotoPrevRecord()
   End Function

   Function GotoRecord (Direction)
      On Error Resume Next
      DoCmd GoToRecord , , Direction
   End Function
                

How to Use the Custom Navigation Functions on a Form

The steps listed below demonstrate how to use the Access Basic functions detailed above to add custom navigation buttons to the Orders and the Orders Subform forms in the sample database NWIND.MDB included with Microsoft Access:

  1. Open the Orders form in Design view.
  2. Create four buttons on the form to facilitate navigation among the Orders records. Place these buttons side by side, with the following properties:

          Command Button : btnGotoFirstRecord
             Caption: <<
             OnClick: =GotoFirstRecord()
    
             NOTE: In version 1.x, the OnClick property is called the OnPush
             property.
    
          Command Button : btnGotoPrevRecord
             Caption: <
             OnClick: =GotoPrevRecord()
    
          Command Button : btnGotoNextRecord
             Caption: >
             OnClick: =GotoNextRecord()
    
          Command Button : btnGotoLastRecord
             Caption: >>
             OnClick: =GotoLastRecord()
                            
  3. Create four buttons on the Orders Subform form to facilitate navigation among the records. Place these buttons side by side, with the following properties:

          Command Button : btnGotoFirstSubRecord
             Caption: <<
             OnClick: =GotoFirstSubRecord("Orders Subform")
    
          Command Button : btnGotoPrevSubRecord
             Caption: <
             OnClick: =GotoPrevSubRecord("Orders Subform")
    
          Command Button : btnGotoNextSubRecord
             Caption: >
             OnClick: =GotoNextSubRecord("Orders Subform")
    
          Command Button : btnGotoLastSubRecord
             Caption: >>
             OnClick: =GotoLastSubRecord("Orders Subform")
                            

NOTE: These buttons can be placed on the main form or on the subform. The argument being passed to the function ("Orders Subform") is the name of the subform control.


Additional query words: scrollbar navigate goto

Keywords: kbhowto kbusage KB104683