ACC: Macro to Enter Date When a Record Was Last Modified

Last reviewed: April 2, 1997
Article ID: Q96103
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0, 7.0, 97

SUMMARY

Novice: Requires knowledge of the user interface on single-user computers.

This article explains how to write a macro that will place the current date into a LastModified field in your table each time a record is modified. You can use this method when you are editing records on a form.

MORE INFORMATION

When you use a form to edit records, you can date stamp the record by attaching a macro to the BeforeUpdate property of the form. This example uses the Customers table in the sample database Northwind.mdb (or NWIND.MDB in versions 1.x and 2.0).

  1. Add a new field to the Customers table.

          Table: Customers
          ------------------------
          Field Name: DateModified
    
             Data Type: Date/Time
    
    

  2. Create a macro called LastModified as follows:

          Macro Name            Action
          ------------------------------
          LastModified          SetValue
    
          LastModified Actions
          --------------------
          Item: [DateModified]
          Expression: Date()
    
       NOTE: There is no equal sign (=) in front of the Date() function.
       If you put an equal sign in front of the Date() function, the macro
       will always put the date 12/30/99 into the [DateModified] control
       even though the macro step window shows the correct date in the
       argument section.
    
    

  3. Create a form called Modify Customers based on the Customers table. Add a few of the fields to the form as follows:

          Form Name: Modify Customers
          ---------------------------
          ControlSource: DateModified
          ControlSource: CustomerID
          ControlSource: CompanyName
          ControlSource: Address
    

          NOTE: In versions 1.x and 2.0, there is a space in Customer ID and
          in Company Name.
    

  4. Enter the macro name, LastModified, into the BeforeUpdate property of the Modify Customers form. Switch the form to Form view. Note that any time you modify the record, the current date is placed in the DateModified control.


Keywords : kbusage McrActn
Version : 1.0 1.1 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: April 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.