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. To create a field that automatically records the date each time the record is modified, follow these steps:
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.
- Start Microsoft Access and open the sample database Northwind.mdb.
- In the Database window, click Tables, select the Customers table, and then click Design to open the table in Design view. Add the following field to the Customers table:
Field Name: DateModified
Data Type: Date/Time
- Save the Customers table and close it.
- In the Database window, click Macros, and then click New to create the following macro:
Action: SetValue
Item: [DateModified]
Expression: Date()
NOTE: There is no equal sign (=) in front of the Date() function.
- Save the macro as LastModified, and then close it.
- In the Database window, click Forms, and then click New. Create a new form based on the Customers table. Add the following fields to the form by dragging them from the Customers field list box onto the form:
- DateModified
- CustomerID
- CompanyName
- Address
- Save the form as ModifyCustomers.
- Click the square to the left of the ruler on the form in Design view to select the form.
- If the property sheet is not visible, click Properties on the View menu.
- In the BeforeUpdate property of the ModifyCustomers form, select the LastModified macro.
- On the View menu, click Form View.
- Modify the address for the first record by typing any characters in the Address box. Go to the next record, and then return to the record that you just modified.
Note that the current date is placed in the DateModified control.