RickHunter84
Registered User.
- Local time
- Today, 00:57
- Joined
- Dec 28, 2019
- Messages
- 85
Hello forum friends,
I hope everyone is doing fine.
I'm trying to get pass over an error I'm encountering within my module. When function is called to record the entry in the tblAuditTrail, i get an error on
![FieldName] = ctl.ControlSource - Error 91 - Object Variable or With block variable not set
any idea what could be causing this error?
Here is my code:
As always, any help or clue would be greatly appreciated.
Rick
I hope everyone is doing fine.
I'm trying to get pass over an error I'm encountering within my module. When function is called to record the entry in the tblAuditTrail, i get an error on
![FieldName] = ctl.ControlSource - Error 91 - Object Variable or With block variable not set
any idea what could be causing this error?
Here is my code:
Code:
Public Function AuditChanges(RefID As String, UserAction As String)
On Error GoTo auditerr
Dim db As Database
Dim rs As Recordset
Dim ctl As Control
Dim UserID As String
Set db = CurrentDb
Set rs = db.OpenRecordset("Select * from tblAuditTrail", adOpenDynamic)
UserID = DLookup("[ShortName]", "[tblUser]", "[LcompanyID_FK]=" & TempVars("gtvCompanyID").Value & " and [UserID]=" & TempVars("gtvUserName").Value)
Select Case UserAction
Case "New"
With rs
.AddNew
![DateTime] = Now()
![UserName] = UserID
![FormName] = Screen.ActiveForm.Name
![Action] = UserAction
![RecordID] = Screen.ActiveControl.Parent.Form(RefID).Value
![FieldName] = ctl.ControlSource
.Update
End With
Case "Delete"
With rs
.AddNew
![DateTime] = Now()
![UserName] = UserID
![FormName] = Screen.ActiveForm.Name
![Action] = UserAction
![RecordID] = Screen.ActiveControl.Parent.Form(RefID).Value
.Update
End With
Case "Edit"
For Each ctl In Screen.ActiveForm.Controls
If (ctl.ControlType = acTextBox) Or (ctl.ControlType = acComboBox) Or (ctl.ControlType = acCheckBox) Then
If Nz(ctl.Value) <> Nz(ctl.OldValue) Then
With rs
.AddNew
![DateTime] = Now()
![UserName] = UserID
![FormName] = Screen.ActiveForm.Name
![Action] = UserAction
![RecordID] = Screen.ActiveControl.Parent.Form(RefID).Value
![FieldName] = ctl.ControlSource
![OldValue] = ctl.OldValue
![newValue] = ctl.Value
.Update
End With
End If
End If
Next ctl
End Select
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
auditerr:
MsgBox Err.Description & " : " & Err.Number
End Function
As always, any help or clue would be greatly appreciated.
Rick