View Full Version : Trouble with Date Modified Code


triscuit83
08-27-2007, 10:33 AM
I am trying to insert a time stamp of when a form was last updated. I added a DateModified field to my table and added that field to my form. Here is a copy of my code

Private Sub DateModified_BeforeUpdate(Cancel As Integer)
On Error GoTo BeforeUpdate_Err

'set bound controls to system date and time
DateModified = Date

BeforeUpdate_Err:
MsgBox Err.Description, vbCritical & vbOKOnly, _
"Error Number " & Err.Number & " Occured"
Resume BeforeUpdate_End
End Sub


Nothing happens, And Ialso tried using a macro with SetValue [dateModified] Date() and that did not work either.

Any ideas why?

WayneRyan
08-27-2007, 10:50 AM
Triscuit,

Use the form's BeforeUpdate event, not your date modified.



Private Sub DateModified_BeforeUpdate(Cancel As Integer) <-- Change to form's event
On Error GoTo BeforeUpdate_Err

'set bound controls to system date and time
DateModified = Date <-- Need an Exit Sub after this line, or you'll "fall" into
your error handler.

BeforeUpdate_Err:
MsgBox Err.Description, vbCritical & vbOKOnly, _
"Error Number " & Err.Number & " Occured"
Resume BeforeUpdate_End <-- Label does not exist, remove this line to just exit
the Sub.
End Sub



Wayne

triscuit83
08-27-2007, 11:00 AM
Thank you!!!

Added to your rep wayne

WayneRyan
08-27-2007, 11:14 AM
Triscuit,

Glad to help, for further info you can use the Search Facility here and look
for "audit trail" ... there's a very popular ghudson example of this type of
software.

Wayne