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.
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.