By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,689 Members | 1,759 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,689 IT Pros & Developers. It's quick & easy.

Form After_Update Event Firing after Undo

P: 13
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.html">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_Update() 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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  
  3. If Not (Me.NewRecord) Then
  4.      If MsgBox("Would You Like To Save The Changes To This Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save Changes to Record ???") = vbNo Then
  5.  
  6.         Me.Undo
  7.  
  8. Exit Sub
  9. End If
  10.  
  11.     Else
  12.  
  13.     If MsgBox("Would You Like To Save This Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save This Record ???") = vbNo Then
  14.  
  15.     Me.Undo
  16.  
  17. Exit Sub
  18. End If
  19.  
  20. End If
  21.  
  22. bWasNewRecord = Me.NewRecord
  23.    Call AuditEditBegin("tblMaster_Records", "tblTempRecordChangeHistory", "Rec_Num", Nz(Me.Rec_Num, 0), bWasNewRecord)
  24.  
  25. End Sub
  26.  
  27. Private Sub Form_AfterUpdate()
  28.  
  29. Call AuditEditEnd("tblMaster_Records", "tblTempRecordChangeHistory", "tblRecordChangeHistory", "Rec_Num", Nz(Me!Rec_Num, 0), bWasNewRecord)
  30.  
  31. End Sub
Feb 15 '08 #1
Share this Question
Share on Google+
2 Replies


MindBender77
100+
P: 234
This is an untested theory but, you might want to try:
DoCmd.CancelEvent

Bender
Feb 15 '08 #2

P: 13
This is an untested theory but, you might want to try:
DoCmd.CancelEvent

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
Feb 15 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.