Hello,
I have a form which records tool information. I set up a basic audit trail for this form using the information provided here: http://www.fontstuff.com/access/acctut21.htm
My code for the module ended up looking very similar:
Code:
Sub AuditChanges(IDField As String) On Error GoTo AuditChanges_Err
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim ctl As Control
Dim datTimeCheck As Date
Dim strUserID As String
Dim strCompID As String
Set cnn = CurrentProject.Connection
Set rst = New ADODB.Recordset
rst.Open "SELECT * FROM tblAuditTrail", cnn, adOpenDynamic, adLockOptimistic
datTimeCheck = Now()
strUserID = Environ("USERNAME")
strCompID = Environ("ComputerName")
For Each ctl In Screen.ActiveForm.Controls
If ctl.Tag = "Audit" Then
If Nz(ctl.Value) <> Nz(ctl.OldValue) Then
With rst
.AddNew
![DateTime] = datTimeCheck
![UserName] = strUserID
![ComputerName] = strCompID
![FormName] = Screen.ActiveForm.Name
![recordID] = Screen.ActiveForm.Controls(IDField).Value
![FieldName] = ctl.ControlSource
![OldValue] = ctl.OldValue
![NewValue] = ctl.Value
.Update
End With
End If
End If
Next ctl
AuditChanges_Exit:
On Error Resume Next
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
Exit Sub
AuditChanges_Err:
MsgBox Err.Description, vbCritical, "ERROR!"
Resume AuditChanges_Exit
End Sub
I have the tags set up, and am calling the procedure from the before update event on the form in question.
It had been working, but recently started throwing a Run-Time Error 2475. When I go to debug, the bolded/underlined section of code above is highlighted. Any and all help is appreciated. Thank you!