Getting error message, but code works?

writer2000

Registered User.
Local time
Today, 08:14
Joined
Jun 16, 2015
Messages
20
I installed an Audit Trail on my database. It works throughout the entire database. However, in one section of the database, on a single form, I keep getting an error message: Object doesn't support this property or method. Now, the audit still works. But i keep getting this message. What gives?
 
Yes. I haven't found anything wrong with it. Here's the code for the module:

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
Set cnn = CurrentProject.Connection
Set rst = New ADODB.Recordset
rst.Open "SELECT * FROM tblAuditTrail", cnn, adOpenDynamic, adLockOptimistic
datTimeCheck = Now()
strUserID = Environ("USERNAME")
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
![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

Here's the code I put on the form (before update-event procedure):


Private Sub Form_BeforeUpdate(Cancel As Integer)
Call AuditChanges("PersonnelID")

End Sub

I then put "Audit" on the Tag box under the Other section under properties for each field I want to track. This works in every section of the database, except for this section. The error is:

ERROR! Object doesn't support this property or method.

You click ok and then that's it.

I took the "Audit" off of every tag in the form and it still gave me the error message. When I take out the code from the before update, the error message stops appearing.
 
The first step to debugging is knowing what line causes the error. To do that, temporarily comment out the "On Error GoTo..." line and run the code. You should be given the option to debug, which should take you to the offending line.

Edit: you should also be able to hover over variables to see their current values.
 
Odd. When I do that I no longer get the error message. However, only the first field (the first name) gets recorder by my audit trail table. None of the other fields are being recorded when changes are made.
 
Well I recreated the form from the ground up and now it works fine. So weird. Still no clue as to what was causing the issue, but thanks everyone for your help!
 
My gut was that something had the audit tag that shouldn't but who knows. Glad you got it sorted.
 
My gut was that something had the audit tag that shouldn't but who knows. Glad you got it sorted.

Your gut served you well! I found an empty cell that had the audit tag on it!@ That was causing all the fuss! Thank you so much!!!!!!!!!!!!!!!!!!!!!!!!! :D
 
Cool! Probably a label or something that doesn't have a Value or OldValue property.
 

Users who are viewing this thread

Back
Top Bottom