andrew.abaye
New member
- Local time
- Today, 11:56
- Joined
- Jun 22, 2024
- Messages
- 14
Good Morning Folks,
I have implemented an Audit Trail for my Access Database following an example I saw on Tech Republic. It is working well for other forms except for my payroll form. It gives an error: Operation is not supported for this type of object. Number" 3251 as attached even though the data get saved in the Audit Trail Table. I have also posted my VBA codes here:
Const cDQ As String = """"
Sub AuditTrail(frm As Form, recordid As Control)
' Track changes to data.
' recordid identifies the PK field's corresponding
' control in frm, in order to identify the record.
Dim ctl As Control
Dim varBefore As Variant
Dim varAfter As Variant
Dim strControlName As String
Dim strSQL As String
On Error GoTo ErrHandler
' Loop through each control in the form.
For Each ctl In frm.Controls
With ctl
' Check if the control is a TextBox, CheckBox, OptionGroup, Currency, or Number.
Select Case .ControlType
Case acTextBox, acCheckBox, acOptionGroup, acComboBox, acCalculated, acCurrency, acNumber
' Check if the value has changed from the old value.
If .OldValue <> .Value Then
varBefore = .OldValue
varAfter = .Value
strControlName = .Name
' Build the INSERT INTO statement.
strSQL = "INSERT INTO ztblDataChanges (EditDate, [User], RecordID, SourceTable, SourceField, BeforeValue, AfterValue) " _
& "VALUES (Now(), " _
& cDQ & Environ("username") & cDQ & ", " _
& cDQ & recordid.Value & cDQ & ", " _
& cDQ & frm.RecordSource & cDQ & ", " _
& cDQ & strControlName & cDQ & ", " _
& cDQ & Nz(varBefore, "") & cDQ & ", " _
& cDQ & Nz(varAfter, "") & cDQ & ")"
' View evaluated statement in Immediate window.
Debug.Print strSQL
' Execute the SQL statement.
CurrentDb.Execute strSQL, dbFailOnError
End If
End Select
End With
Next ctl
' Clear the control variable.
Set ctl = Nothing
Exit Sub
ErrHandler:
' Display the error message.
MsgBox "Error: " & Err.Description & vbNewLine & "Number: " & Err.Number, vbOKOnly, "Error"
' Ensure warnings are turned back on in case of an error.
DoCmd.SetWarnings True
End Sub
I have implemented an Audit Trail for my Access Database following an example I saw on Tech Republic. It is working well for other forms except for my payroll form. It gives an error: Operation is not supported for this type of object. Number" 3251 as attached even though the data get saved in the Audit Trail Table. I have also posted my VBA codes here:
Const cDQ As String = """"
Sub AuditTrail(frm As Form, recordid As Control)
' Track changes to data.
' recordid identifies the PK field's corresponding
' control in frm, in order to identify the record.
Dim ctl As Control
Dim varBefore As Variant
Dim varAfter As Variant
Dim strControlName As String
Dim strSQL As String
On Error GoTo ErrHandler
' Loop through each control in the form.
For Each ctl In frm.Controls
With ctl
' Check if the control is a TextBox, CheckBox, OptionGroup, Currency, or Number.
Select Case .ControlType
Case acTextBox, acCheckBox, acOptionGroup, acComboBox, acCalculated, acCurrency, acNumber
' Check if the value has changed from the old value.
If .OldValue <> .Value Then
varBefore = .OldValue
varAfter = .Value
strControlName = .Name
' Build the INSERT INTO statement.
strSQL = "INSERT INTO ztblDataChanges (EditDate, [User], RecordID, SourceTable, SourceField, BeforeValue, AfterValue) " _
& "VALUES (Now(), " _
& cDQ & Environ("username") & cDQ & ", " _
& cDQ & recordid.Value & cDQ & ", " _
& cDQ & frm.RecordSource & cDQ & ", " _
& cDQ & strControlName & cDQ & ", " _
& cDQ & Nz(varBefore, "") & cDQ & ", " _
& cDQ & Nz(varAfter, "") & cDQ & ")"
' View evaluated statement in Immediate window.
Debug.Print strSQL
' Execute the SQL statement.
CurrentDb.Execute strSQL, dbFailOnError
End If
End Select
End With
Next ctl
' Clear the control variable.
Set ctl = Nothing
Exit Sub
ErrHandler:
' Display the error message.
MsgBox "Error: " & Err.Description & vbNewLine & "Number: " & Err.Number, vbOKOnly, "Error"
' Ensure warnings are turned back on in case of an error.
DoCmd.SetWarnings True
End Sub