ACC: How to Determine If the Current Record Is the New Record

Last reviewed: May 14, 1997
Article ID: Q112292
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0

SUMMARY

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

Microsoft Access has no built-in macro action or function to determine if the current record on the form is the new record. This article demonstrates a sample function called IsNewRecord() that you can use to determine whether the current record on the form is the new record.

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.

NOTE: In Microsoft Access for Windows 95 there is a new form property called NewRecord that can be used to determine if the current record is a new record or not.

MORE INFORMATION

To use the IsNewRecord() function, add the following code to a new or existing module:

   '********************************************************************
   ' FUNCTION: IsNewRecord()
   '
   ' PURPOSE:
   '   Determines if the record in the active form is the new record.
   '
   ' RETURNS:
   '   True - If the record is the new record.
   '   False - If the record is not the new record.
   '
   '********************************************************************
   Function IsNewRecord ()
       Const NO_CURRENT_RECORD = 3021
       Dim RetVal
       On Error Resume Next

       ' Try to reference the bookmark property of the current record.
       RetVal = Screen.ActiveForm.Bookmark

       If Err = NO_CURRENT_RECORD Then
           IsNewRecord = True
       Else
           IsNewRecord = False
       End If
   End Function

How to Use the IsNewRecord() Function

The following example demonstrates how to use the IsNewRecord() function with the Employees form in the sample database NWIND.MDB to display the message "In the new record!" whenever you navigate into the new record:

  1. Create the following new macro and save it as CheckForNewRecord:

          Macro Name          Condition       Action
          ------------------------------------------
          CheckForNewRecord   IsNewRecord()   MsgBox
    
          CheckForNewRecord Actions
          -------------------------
          MsgBox
             Message: "In the new record!"
    
    

  2. Open the Employees form in Design view.

  3. Change the form's OnCurrent property to read as follows:

          CheckForNewRecord
     
    
    
    	
    	


Keywords : FmsHowto kbusage
Version : 1.0 1.1 2.0
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: May 14, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.