I'm trying to track data changes on my database. On form I create a procedure on Before Update event to track data changes, here it is: (It also puts the username who changes the record.
Dim ctl As Control
For Each ctl In Controls
If TypeOf ctl Is TextBox Then
If ctl.Value <> ctl.OldValue Then
Dim ans As Integer
ans = MsgBox("A record has changed." & vbcrkf + vbCrLf & _
"Do you want to save the record.", vbYesNo)
If ans = vbYes Then
Me.txtUpdatedBy.Value = fOSUserName
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Else
Cancel = True
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
End If
End If
Next ctl
When I move to another record this procedure runs, It's ok if I say No to the prompt, but when I say Yes, it gives me an error that says I cannot save the data.
Just for a test I place a Save button on the form. When I changed something on the record and clicked that Save button, it gives me an error.
What's wrong with my codes?