Updates

bugsy

Registered User.
Local time
Today, 14:10
Joined
Oct 1, 2007
Messages
99
I see forms have even After Update
IS there a way for me to see which field was updated and what was is the new and the old value ?
 
You can search this forum for several threads that deal with an Audit Trail or Log. When a form saves a record, *all* of the bound controls that have been changed are saved; not just the ActiveControl.
 
Tou would use the Form_BeforeUpdate event for this, not the AfterUpdate event. You don't say to what end you want to do this, but the general scheme would be something like this.


Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctrl As Control

For Each ctrl In Me.Controls
 If TypeOf ctrl Is TextBox Then
  If ctrl.OldValue <> ctrl.Value Then
    MsgBox "For " & ctrl.Name & "  Old Value is " & ctrl.OldValue & "  and New Value is  " & ctrl.Value
  End If
 End If
Next
End Sub

If you wanted to review the changes, then decide whether or save them or go back and change one or more of them


Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctrl As Control

For Each ctrl In Me.Controls
 If TypeOf ctrl Is TextBox Then
  If ctrl.OldValue <> ctrl.Value Then
    MsgBox "For " & ctrl.Name & "  Old Value is " & ctrl.OldValue & "  and New Value is  " & ctrl.Value
  End If
 End If
Next
If MsgBox("Do You Want To Save This Record as Is?", vbYesNo) = vbNo Then
  Cancel = True
End If
End Sub

This code could easily be modified for controls other than textboxes, and it could also be modified to simply dump all the changes.
 
missinglinq
Thanks ! it works graet !
(i substituted "msgbox" for insert statement)
 

Users who are viewing this thread

Back
Top Bottom