I have created a DateModified and TimeModified field in the SQL database and
created the Datemodified and TimeModified boxes in the Access Form. I cannot
get this Microsoft example to work with my current Event Procedure. I can
get the Macro to work but then I cannot run the current Event Procedure.
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo BeforeUpdate_Err
' Set bound controls to system date and time.
DateModified = Now()
TimeModified = Time()
BeforeUpdate_End:
Exit Sub
BeforeUpdate_Err:
MsgBox Err.Description, vbCritical & vbOKOnly, _
"Error Number " & Err.Number & " Occurred"
Resume BeforeUpdate_End
End Sub
Change the two lines to
Me!DateModified = Date
Me!TimeModified = Time
where DateModified and TimeModified are the names of controls - textboxes - on
your form, bound to the SQL fields.
Note that Now does ***NOT*** return the current date. It returns the current
date *and time*, accurate to the second. If your DateModified field is
formatted to show only the date, you may get unexpected results when
searching. The time portion will still be there, even if it's not visible!
Also, Time() returns the time on December 30, 1899. You should really consider
just using a WhenModified date/time field (in Access JET or in SQL, makes no
difference) and setting it to Now, to get the date and time all in one field.
John W. Vinson [MVP]