Hi Guys
I have been trying to add audit trail functionality to my database.
I have written following code on the Add button on form:
	
	
	
		
The following code is present in a module. I am getting compile error at the following Red line. 
	
	
	
		
 I have been trying to add audit trail functionality to my database.
I have written following code on the Add button on form:
		Code:
	
	
	If Me.NewRecord Then
        Call AuditChanges(me.txtGenMeetingID, "NEW")
    Else
        Call AuditChanges(me.txtGenMeetingID, "EDIT")
End If
	
		Code:
	
	
	[COLOR=red]Sub AuditChanges(IDField As Number, UserAction As String)
[/COLOR]   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
    'Set cnn = CurrentProject.Connection
    Set rst = New ADODB.Recordset
    'rst.Open "SELECT * FROM tblAuditTrail", cnn, adOpenDynamic, adLockOptimistic
    Set rst = CurrentDb.OpenRecordset("tblAuditTrail")
    datTimeCheck = Now()
     strUserID = Environ("USERNAME")
    Select Case UserAction
        Case "EDIT"
            For Each ctl In Screen.ActiveForm.Controls
                If ctl.Tag = "C" Then
                    If Nz(ctl.Value) <> Nz(ctl.OldValue) Then
                        With rst
                            .AddNew
                            ![DateTime] = datTimeCheck
                            ![UserName] = strUserID
                            ![FormName] = Screen.ActiveForm.Name
                            ![Action] = UserAction
                            ![RecordID] = Screen.ActiveForm.Controls(IDField).Value
                            ![FieldName] = ctl.ControlSource
                            ![OldValue] = ctl.OldValue
                            ![NewValue] = ctl.Value
                            .Update
                        End With
                    End If
                End If
            Next ctl
        Case Else
            With rst
                .AddNew
                ![DateTime] = datTimeCheck
                ![UserName] = strUserID
                ![FormName] = Screen.ActiveForm.Name
                ![Action] = UserAction
                ![RecordID] = Screen.ActiveForm.Controls(IDField).Value
                .Update
            End With
    End Select
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
	
			
				Last edited: