Automatic update of a field

  • Thread starter Thread starter Jon
  • Start date Start date
J

Jon

I would like a date field in a record (Form) to
automatically update when i make a change to any field in
that record.
 
The form's BeforeUpdate event will fire if you have made changes, just
before those changes are saved. In this event, set the control with the date
field to Now or Date, whichever you're using.

Me.txtDateField = Date
 
Jon said:
I would like a date field in a record (Form) to
automatically update when i make a change to any field in
that record.

The only way I know to do that is to use the form's BeforeUpdate event
to set the value of the field. For example, you could have a VBA event
procedure like this:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Me.LastUpdated = Date ' or use Now, if you want the time, too.

End Sub

Note that this event will still fire even if the user only changes
fields to their current values; for example, if a value of "X" is
replaced by a value of "X". But that's not all that common. If you
need to detect whether any field actually has a different value than
previously, you have to write more elaborate code.
 
Back
Top