decent_boy
Board Regular
- Joined
- Dec 5, 2014
- Messages
- 130
- Office Version
- 2016
- Platform
- Windows
Hi,
I have downloaded below codes from
Tracking data changes in Access
As per given instruction on this web site I created table but I don't understand that how should I call/run this function in my multiple tables. Please guide me how could it be done in a better way.
I have downloaded below codes from
Tracking data changes in Access
VBA Code:
Function LogChanges(lngID As Long, Optional strField As String = "")
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim varOld As Variant
Dim varNew As Variant
Dim strFormName As String
Dim strControlName As String
varOld = Screen.ActiveControl.OldValue
varNew = Screen.ActiveControl.Value
strFormName = Screen.ActiveForm.Name
strControlName = Screen.ActiveControl.Name
Set dbs = CurrentDb()
Set rst = dbs.TableDefs("ztblDataChanges").OpenRecordset
With rst
.AddNew
!FormName = strFormName
!ControlName = strControlName
If strField = "" Then
!FieldName = strControlName
Else
!FieldName = strField
End If
!RecordID = lngID
!UserName = Environ("username")
If Not IsNull(varOld) Then
!OldValue = CStr(varOld)
End If
!NewValue = CStr(varNew)
.Update
End With
'clean up
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
End Function
Private Sub txtAddress1_BeforeUpdate(Cancel As Integer)
Call LogChanges(CustomerID, "Address1")
End Sub
As per given instruction on this web site I created table but I don't understand that how should I call/run this function in my multiple tables. Please guide me how could it be done in a better way.