R
Robert Neville
My record stamping code keeps returning an error when updating a value
in place. I would like to record stamp the creation date and an
updated date. The creation occurs once and the updated value change
with each edit. This objective seems straight forward, yet I am still
having trouble after searching numerous record stamping posts. The
code executes without incident when records do not have a value in the
updated field. Please let me know where my code went awry.
Complete Error below
Update or CancelUpdate without AddNew or Edit. [3020]
FYI
This code was previously more complex adding the current user's name
to the record stamp. This functionality may come back, yet I excluded
the comment code for post simplicity. Plus, each form and underlying
table has different names for the updating and creation fields thus
the reason to pass the control arguments to the procedure.
*******Code Starts**********
Public Sub FrmRecStamp(ctlUpdated As Control, _
ctlCreated As Control)
' Purpose: Timestamp current form record, called from
Form_BeforeUpdate
' Arguments: ctlUpdated: = as updated control on the form
' Arguments: ctlCreated:= as created control on the form
' Example: Call FrmRecStamp(Me!txtCompUpdated, Me!txtCompCreated)
Const cstrProc As String = "FrmRecStamp"
On Error GoTo FrmRecStamp_Err
If Len(ctlUpdated.Value) > 0 Then
ctlUpdated = Now()
Else
ctlUpdated = Now()
End If
If IsNull(ctlCreated) Then
ctlCreated = Now
End If
FrmRecStamp_Exit:
Exit Sub
FrmRecStamp_Err:
Call ErrMsgStd(mcstrMod & "." & cstrProc, Err.Number,
Err.Description, True)
Resume FrmRecStamp_Exit
End Sub
*******Code End**********
in place. I would like to record stamp the creation date and an
updated date. The creation occurs once and the updated value change
with each edit. This objective seems straight forward, yet I am still
having trouble after searching numerous record stamping posts. The
code executes without incident when records do not have a value in the
updated field. Please let me know where my code went awry.
Complete Error below
Update or CancelUpdate without AddNew or Edit. [3020]
FYI
This code was previously more complex adding the current user's name
to the record stamp. This functionality may come back, yet I excluded
the comment code for post simplicity. Plus, each form and underlying
table has different names for the updating and creation fields thus
the reason to pass the control arguments to the procedure.
*******Code Starts**********
Public Sub FrmRecStamp(ctlUpdated As Control, _
ctlCreated As Control)
' Purpose: Timestamp current form record, called from
Form_BeforeUpdate
' Arguments: ctlUpdated: = as updated control on the form
' Arguments: ctlCreated:= as created control on the form
' Example: Call FrmRecStamp(Me!txtCompUpdated, Me!txtCompCreated)
Const cstrProc As String = "FrmRecStamp"
On Error GoTo FrmRecStamp_Err
If Len(ctlUpdated.Value) > 0 Then
ctlUpdated = Now()
Else
ctlUpdated = Now()
End If
If IsNull(ctlCreated) Then
ctlCreated = Now
End If
FrmRecStamp_Exit:
Exit Sub
FrmRecStamp_Err:
Call ErrMsgStd(mcstrMod & "." & cstrProc, Err.Number,
Err.Description, True)
Resume FrmRecStamp_Exit
End Sub
*******Code End**********