0
votes

I'm trying to have a code that would save the last modified date/user in a main form when a change has been made in the record including all the subforms I have.

Currently, This code works perfectly only for records in the main form but not for records in subforms. How would I include the last modified date/user for the subforms?

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Dirty Then
Me.LastModifiedDate = Now
Me.LastModifiedUser = Environ$("username")
End If
End Sub
1

1 Answers

0
votes

Do you mean that you want to update the LastModified information on the main form if any subform data changes? If so, I would start by looking at adding similar code to the subform's before update event:

Private Sub Form_BeforeUpdate(Cancel As Integer)

    If Me.Dirty Then
        Me.Parent.LastModifiedDate = Now
        Me.Parent.LastModifiedUser = Environ$("username")
    End If

End Sub

I haven't tested this though, and you might start getting messages about data having been changed by another user if you update multiple subform records before saving the main form record.