I have a form that updates the last modified time and by which user when the Save and Close button is clicked but I am trying to prevent it from updating these fields if no other fields have been updated. For example, a user opens the form and doesn't make any changes at all and clicks on Save and Close vs. Cancel, this updates the modified by and date fields when it shouldn't.
I thought that I could write in an If statement to look at the .value and .oldvalue for the fields that should be changed in order for the Modified by/date should be updated, but I keep getting a Run Time 424 error.
Here is the code I'm using and I'm hoping someone can help (See the ElseIf line for the If Statement I spoke of above):
Code:
Private Sub Command10_Click()
Dim intMissInfo As String
Dim Admin As Variant
Dim ID As Variant
Dim Name As Variant
Dim Security As Variant
ID = Me.ID
Name = Me.UserName
Security = Me.SecurityLevel
Admin = Forms!Dashboard_Form.UserName
If (IsNull(ID) Or IsNull(Name) Or IsNull(Security)) Then
GoTo MissingInfo
ElseIf ((ID.Value = ID.OldValue) And (Name.Value = Name.OldValue) And (Security.Value = Security.OldValue)) Then
GoTo NoChange
Else
Me.ModifiedBy = Admin
Me.ModifiedDate = Now()
Forms!Security_Main_Form.Requery
If Me.Dirty Then Me.Dirty = False
DoCmd.Close
End If
Exit Sub
MissingInfo:
'Display message that can't be saved without an ID
intMissInfo = MsgBox("All fields are required to add a new user to the database. Please make sure you have entered a valid ID, User Name, and selected the appropriate Security Level before proceeding.", vbOKOnly, "Missing Required Fields")
Exit Sub
NoChange:
Exit Sub
End Sub