Hello All,
I have a module that is called in the BeforeUpdate event of most of my forms (See code below)
There is a button that will open a query with the table information so i can see the log entries. I've noticed that when I have this query open it will cause a read-only error when there is new or edited information being entered into the forms and it will not capture those instances into the table.
Is there a way to be able to see the real-time entries without disrupting the data entry happening in the forms being monitored? Im a little lost as to whether there is something in the code that can be changed to fix this or what I can do to make sure there is no interruption to data entry when the form
Module:
I have a module that is called in the BeforeUpdate event of most of my forms (See code below)
There is a button that will open a query with the table information so i can see the log entries. I've noticed that when I have this query open it will cause a read-only error when there is new or edited information being entered into the forms and it will not capture those instances into the table.
Is there a way to be able to see the real-time entries without disrupting the data entry happening in the forms being monitored? Im a little lost as to whether there is something in the code that can be changed to fix this or what I can do to make sure there is no interruption to data entry when the form
Module:
SQL:
Option Compare Database
Sub AuditChanges(IDField As String, UserAction 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
Set cnn = CurrentProject.Connection
Set rst = New ADODB.Recordset
rst.Open "SELECT * FROM tblAuditTrail", cnn, adOpenDynamic, adLockOptimistic
datTimeCheck = Now()
strUserID = CurrentUser()
Select Case UserAction
Case "EDIT"
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
![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 by a moderator: