mike60smart
Registered User.
- Local time
- Today, 03:02
- Joined
- Aug 6, 2017
- Messages
- 1,994
Hi Everyone
I am trying to use Allan Browne's Audit Trail Code (http://allenbrowne.com/AppAudit.html) and I am getting the following error:-
The code on the Subform is as follows:-
Option Compare Database
Option Explicit
When I click a Command button to open another form I get the error message, hit Debug and it highlights Line 100
Does anyone have any thoughts on a solution for this?
Any helpappreciated
I am trying to use Allan Browne's Audit Trail Code (http://allenbrowne.com/AppAudit.html) and I am getting the following error:-
The code on the Subform is as follows:-
Option Compare Database
Option Explicit
Code:
Sub AuditChangesSub(IDField As String, UserAction As String)
10 On Error GoTo AuditChangesSub_Err
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim ctl As Control
Dim datTimeCheck As Date
Dim strUserID As String
20 Set cnn = CurrentProject.Connection
30 Set rst = New ADODB.Recordset
40 rst.Open "SELECT * FROM tblAuditTrail", cnn, adOpenDynamic, adLockOptimistic
50 datTimeCheck = Now()
60 strUserID = Environ("USERNAME")
70 Select Case UserAction
Case "EDIT"
80 For Each ctl In Screen.ActiveControl.Parent.Controls
90 If ctl.Tag = "Audit" Then
100 If Nz(ctl.Value) <> Nz(ctl.OldValue) Then
110 With rst
120 .AddNew
130 ![DateTime] = datTimeCheck
140 ![UserName] = strUserID
150 ![FormName] = Screen.ActiveControl.Parent.Form.Name
160 ![Action] = UserAction
170 ![RecordID] = Screen.ActiveControl.Parent.Form(IDField).Value
180 ![FieldName] = ctl.ControlSource
190 ![OldValue] = ctl.OldValue
200 ![NewValue] = ctl.Value
210 .Update
220 End With
230 End If
240 End If
250 Next ctl
260 Case Else
270 With rst
280 .AddNew
290 ![DateTime] = datTimeCheck
300 ![UserName] = strUserID
310 ![FormName] = Screen.ActiveControl.Parent.Form.Name
320 ![Action] = UserAction
330 ![RecordID] = Screen.ActiveControl.Parent.Form(IDField).Value
340 .Update
350 End With
360 End Select
AuditChangesSub_Exit:
370 On Error Resume Next
380 rst.CLOSE
390 cnn.CLOSE
400 Set rst = Nothing
410 Set cnn = Nothing
420 Exit Sub
AuditChangesSub_Err:
430 MsgBox Err.Description, vbCritical, "ERROR!"
440 Resume AuditChangesSub_Exit
End Sub
When I click a Command button to open another form I get the error message, hit Debug and it highlights Line 100
Does anyone have any thoughts on a solution for this?
Any helpappreciated