StuLux
Well-known Member
- Joined
- Sep 14, 2005
- Messages
- 682
- Office Version
- 365
- Platform
- Windows
I am using the following code (adapted from the Microsoft article on Access Audit trail).
The code writes values to text boxes (txtMeasure, txtOldData, txtNewData) on the form and then the query "qAudit" uses the values from these text boxes to append to an audit table. A record is not created when the existing value is Blank or Null, I have tried many combinations of code to get this to happen but am failing somewhere? My latest attempt is indicated below.
The code writes values to text boxes (txtMeasure, txtOldData, txtNewData) on the form and then the query "qAudit" uses the values from these text boxes to append to an audit table. A record is not created when the existing value is Blank or Null, I have tried many combinations of code to get this to happen but am failing somewhere? My latest attempt is indicated below.
Code:
Function Audit()
On Err GoTo Err_Handler
Dim myForm As Form, ctl As Control
Set myForm = Screen.ActiveForm
'Check each data entry control for change and record old value of Control
For Each ctl In myForm.Controls
'Only check data entry type controls.
Select Case ctl.ControlType
Case acTextBox, acComboBox, acListBox, acOptionGroup, acCheckBox
'Skip fields used to collate changes
If ctl.Name <> "txtMeasure" Or ctl.Name <> "txtOldData" Or _
ctl.Name <> "txtNewData" Then
myForm!txtMeasure = ctl.Name 'Applys the name of the ctl to txtMeasure
'If control had previous value, record previous value
If ctl.Value <> ctl.OldValue Then
myForm!txtOldData = ctl.OldValue
If IsNull(ctl.OldValue) Or ctl.OldValue = "" Then myForm!txtOldData = "Blank" 'This is the line I am trying to get to work
myForm!txtNewData = ctl.Value 'Applys new value to txtNewData
'Runs the qAudit append query to create a new record in tblAUDIT
DoCmd.SetWarnings False
DoCmd.OpenQuery "qAudit"
DoCmd.SetWarnings True
End If
End If
End Select
Next ctl
trynextctl:
Exit Function
Err_Handler:
If Err.Number <> 64535 Then
MsgBox "Error #: " & Err.Number & vbCrLf & "Description: " & Err.Description
End If
Resume trynextctl:
End Function