Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing a date field in a form 1

Status
Not open for further replies.

Kindi

Programmer
Jan 31, 2001
54
GB
I have a form that has a date field. When the user enters a new record the date is automatically entered because i have used the default value for that field to be today's date (date()). However when the users modifys the record in a form, when they close the form or go to the next record how can the date field change automatically to today's/current date
 
I take it this is a "date last modified" field, and you want it to be set automatically to the current date whenever the current record is modified, right?

Create a Form_BeforeUpdate event procedure. In it, change the value of the field to the current date. For example, if the date control is named datLastChanged, you want:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Me!datLastChanged = Date()
End Sub

The form's BeforeUpdate event occurs whenever a record is about to be saved (whether it's a new record or a change to an existing record). It only occurs if some field in the form has been edited, so it won't have any effect on records that are viewed but not changed. Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top