Hi all,
I am a VBA newb. I know probably just enough to be dangerous. :)
Anyway, I have a Form that I am using [HTML]<a href="http://allenbrowne.com/AppAuditCode.ht ml">Allen Brown's Audit Trail</a> [/HTML] code on in order to track user changes to records. The code works outstanding (thanks Allen!), but I have made some modifications to force the user to confirm any changes before updating the record. I seem to have successfully abort any changes to the record and prevent the the Before Update part of the Audit Trail code from executing.
My problem is that the Form_After_Upda te() event continues to fire after the record changes have been aborted. I am at a loss as to why this is happening. My understanding is that Me.Undo should reset the Form to Clean and the After_Update event should not fire.
What ends up happening if you choose not to update the record is, the record is not changed (good), an Edit From record is not added to the audit table (good) and an Edit To record IS added to the audit table (bad).
Thanks in advance for any advice you can give.
Garrett
Here is the code as it is now:
I am a VBA newb. I know probably just enough to be dangerous. :)
Anyway, I have a Form that I am using [HTML]<a href="http://allenbrowne.com/AppAuditCode.ht ml">Allen Brown's Audit Trail</a> [/HTML] code on in order to track user changes to records. The code works outstanding (thanks Allen!), but I have made some modifications to force the user to confirm any changes before updating the record. I seem to have successfully abort any changes to the record and prevent the the Before Update part of the Audit Trail code from executing.
My problem is that the Form_After_Upda te() event continues to fire after the record changes have been aborted. I am at a loss as to why this is happening. My understanding is that Me.Undo should reset the Form to Clean and the After_Update event should not fire.
What ends up happening if you choose not to update the record is, the record is not changed (good), an Edit From record is not added to the audit table (good) and an Edit To record IS added to the audit table (bad).
Thanks in advance for any advice you can give.
Garrett
Here is the code as it is now:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not (Me.NewRecord) Then
If MsgBox("Would You Like To Save The Changes To This Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save Changes to Record ???") = vbNo Then
Me.Undo
Exit Sub
End If
Else
If MsgBox("Would You Like To Save This Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save This Record ???") = vbNo Then
Me.Undo
Exit Sub
End If
End If
bWasNewRecord = Me.NewRecord
Call AuditEditBegin("tblMaster_Records", "tblTempRecordChangeHistory", "Rec_Num", Nz(Me.Rec_Num, 0), bWasNewRecord)
End Sub
Private Sub Form_AfterUpdate()
Call AuditEditEnd("tblMaster_Records", "tblTempRecordChangeHistory", "tblRecordChangeHistory", "Rec_Num", Nz(Me!Rec_Num, 0), bWasNewRecord)
End Sub
Comment