Form After_Update Event Firing after Undo

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maxx429
    New Member
    • Feb 2008
    • 13

    Form After_Update Event Firing after Undo

    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:
    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
  • MindBender77
    New Member
    • Jul 2007
    • 233

    #2
    This is an untested theory but, you might want to try:
    DoCmd.CancelEve nt

    Bender

    Comment

    • maxx429
      New Member
      • Feb 2008
      • 13

      #3
      Originally posted by MindBender77
      This is an untested theory but, you might want to try:
      DoCmd.CancelEve nt

      Bender
      Bingo! Thank you sir. That coupled with Me.Undo cancels the changes and stops the After_Update event from firing.

      You guys are awesome. :)

      Thanks again,

      Garrett

      Comment

      Working...