ACC1x: Checking for Last or First Record in a MacroLast reviewed: April 2, 1997Article ID: Q95807 |
The information in this article applies to:
SUMMARYIn a macro, you cannot check the result of an action just performed. As a result, you can run into a problem when using a macro to move to the next record or the previous record. There is no record previous to the first record and no next record following the last record. If you attempt to go to the previous or last record when there is none, Microsoft Access displays error messages that may confuse users of a custom application. 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.
MORE INFORMATIONYou can work around this on a form by using Access Basic functions to move from record to record. For example, use the following custom MoveToNext() function to move to the next record or previous record on a form:
Option Explicit Function MoveToNext (DisplayMsg$, MoveForward%) Dim MyDyna As Dynaset Set MyDyna = Screen.ActiveForm.Dynaset MyDyna.Bookmark = Screen.ActiveForm.Bookmark If MoveForward% Then MyDyna.MoveNext Else MyDyna.MovePrevious End If If MyDyna.EOF Or MyDyna.BOF Then MsgBox DisplayMsg$ Else Screen.ActiveForm.Bookmark = MyDyna.Bookmark End If End FunctionTo use the MoveToNext() function, specify the following:
OnPush: =MoveToNext("You are at the end of the record set", True) |
Keywords : kbusage McrOthr
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |