ACC2002: How to Navigate to a Particular Record on a Data Access Page (306148)



The information in this article applies to:

  • Microsoft Access 2002

This article was previously published under Q306148
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

SUMMARY

On a Microsoft Access form, you can enter the record number in the navigation bar to move to a particular record. Data access pages do not have this feature. However, you can simulate this functionality on data access pages by using script to respond to a number that is typed in a text box.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

  1. Start Microsoft Access.
  2. On the Help menu, point to Sample Databases, and then click Northwind Sample Database.
  3. On the Insert menu, click Page.
  4. In the New Data Access Page dialog box, click AutoPage: Columnar, click Orders in the Choose the table or query where the objects data comes from box, and then click OK.
  5. On the View menu, click Design View.
  6. If the toolbox is not visible, click Toolbox on the View menu.
  7. Add a text box control to the page.
  8. Right-click the text box, and then click Element Properties.
  9. On the Other tab, change the Id property to txtNavRecord.
  10. On the Tools menu, point to Macro, and then click Microsoft Script Editor.
  11. Click txtNavRecord in the Client Objects & Events list.
  12. Click onkeydown in the list of events.
  13. Type the following code in the event between the
    'Trap the ENTER key.
    If window.event.keyCode = 13 Then
        'Make sure the number entered is greater than zero.
        If txtNavRecord.value > 0 Then
    	'Move to the specified record.
    	MSODSC.DefaultRecordset.AbsolutePosition = txtNavRecord.value
    	'Clear the text box.
    	txtNavRecord.value = ""
    	'Suppress the Enter key to avoid moving
            'to a new line in the text box.
    	window.event.returnValue = False
        Else
            'Clear the text box and suppress the Enter key.
    	txtNavRecord.value = ""
    	window.event.returnValue = False
        End If
    End If
    					
  14. Save the page, and then close the Microsoft Script Editor to return to the page in Design view.
  15. On the View menu, click Page View.
  16. Type the following numbers into the text box, and press ENTER after each number:

    50
    71
    410
    11

    Note that the data access page moves to the specified record number after each entry.

Modification Type:MinorLast Reviewed:9/27/2006
Keywords:kbhowto KB306148