Solved Appending records into history table of changes made to customer info

  • Thread starter Thread starter Deleted Bruce 182381
  • Start date Start date
D

Deleted Bruce 182381

Guest
Every time users update any information about a customer, in the form's after update event I am appending a copy of the customer record with the date/time the change was made, and the user who made the change to a customer history table. However, when a new customer is first added, it's also appending that record to the history table. What is the best way to prevent that initial record from being added to the history table?

Code:
Private Sub Form_AfterUpdate()

   On Error GoTo locErrorHandler
   cmdSave.Transparent = True
   cmdUndo.Transparent = True

   CurrentDb.Execute "qryCustomerHistory_AppendAfterChange", dbSeeChanges
   lstCustomerHistorySIID.Requery
   lstCustomerHistorySIID = lstCustomerHistorySIID.ItemData(0)
   DisplayCaption_HistoryTab
   txtDisplayCustomer.Requery

locExitHere:
   Exit Sub

locErrorHandler:
   ErrorHandler Me.Name, "Form_AfterUpdate"
   If gErrorResponse = 1 Then Resume
   If gErrorResponse = 2 Then Resume Next
   Resume locExitHere
End Sub

AppendCustomerHistoryTable.png
 
Without claiming this is the best way...
Code:
Private isNew_ As Boolean

Private Sub Form_Current()
    isNew_ = Me.NewRecord
End Sub

Private Sub Form_AfterUpdate()
    If isNew_ Then Exit Sub
    ....
End Sub
 
you can also use the the Form's BeforeInsert event to Set a Variable to true.
then Reset it on the Form's AfterUpdate
 
The attached little demo file illustrates the use of functions which identify whether the values of data have actually been changed in a row, rather than merely that the row has been updated. The AfterUpdate event procedure can be executed if no actual changes have been made, e.g. if a user accidentally edits a value and then corrects the amended value back to the original rather than undoing the edit.
 

Attachments

Users who are viewing this thread

Back
Top Bottom