Before Update Event Sequence

hi there

Registered User.
Local time
Yesterday, 21:23
Joined
Sep 5, 2002
Messages
171
hi all,

i have a couple of simple audit trail fields used to track when a record has been modified and by who. the code uses the Environ("UserName") variable to avoid workgroup security (i.e. CurrentUser property). the code fires on the BeforeUpdate form event on a subform.

here's the code.

********************************************
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim sUser As String

sUser = Environ("UserName")

Me.ModifiedBy = sUser
Me.Modified = Now

End Sub


********************************************

This code works fine, however it fires during an initial record insert. i'm trying to figure out why.

Any ideas for how to ensure the routine only executes when the record has been modified and not upon initial insert? do i have to open a recordset and check to see if the record PK already exists before executing the code?

Many thanks for the help.
 
Actually the Before Update event fires whenever a record is being saved, a new record or changes to an existing record. If you only want when it is changed, you should be able to use:
Code:
If Not Me.NewRecord Then
... put your code here
End If
 
thanks bob!

worked perfectly.

thanks for demystifying the BeforeUpdate event for me.
 

Users who are viewing this thread

Back
Top Bottom