Error on audit trail (1 Viewer)

syedadnan

Access Lover
Local time
Today, 11:41
Joined
Mar 27, 2013
Messages
315
i have a module which i have copied, but in other forms it is working ok but in my form sales form it is working and filling audit trail table with updates but with a error msg "Operation is not supported for this type of object" even this message when escape then audit trail table update also means this message is not disturbing anything just else a message pop up but i am fearing may be this will create trouble ahead, kindly see the module below and suggest what to do,

Option Compare Database
Option Explicit
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
 

JHB

Have been here a while
Local time
Today, 09:41
Joined
Jun 17, 2012
Messages
7,732
Comment out the errorhandling and show which codeline cause the problem.
 

syedadnan

Access Lover
Local time
Today, 11:41
Joined
Mar 27, 2013
Messages
315
Comment out the errorhandling and show which codeline cause the problem.

it is not referring me to the line of error just showing me msg box which i attached, else if i ignore msg box then it is working ok
 

Attachments

  • error.png
    error.png
    24.2 KB · Views: 53

JHB

Have been here a while
Local time
Today, 09:41
Joined
Jun 17, 2012
Messages
7,732
it is not referring me to the line of error just showing me msg box which i attached, else if i ignore msg box then it is working ok
As I wrote comment out the errorhandling!!
Code:
[B][SIZE=4][COLOR=Red]'[/COLOR][/SIZE][/B]On Error GoTo AuditChanges_Err
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 08:41
Joined
Jul 9, 2003
Messages
16,282
Some controls don't have an "OldValue".

This raises the error message "operation not supported by this type of object"

To test to see if this is causing your problem, remove the "Audit" flag from the tag property of the controls.

Run the code. If the error has gone add the Audit flag back in until the error occurs. This will find the offending control.

Sent from my SM-G925F using Tapatalk
 

syedadnan

Access Lover
Local time
Today, 11:41
Joined
Mar 27, 2013
Messages
315
As I wrote comment out the errorhandling!!
Code:
[B][SIZE=4][COLOR=Red]'[/COLOR][/SIZE][/B]On Error GoTo AuditChanges_Err

I am not getting what you saying ? are you saying me to do this or asking me something ?
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 08:41
Joined
Jul 9, 2003
Messages
16,282
Placing a comma at the beginning of a line turns the line into a comment.

In other words it no longer functions as code in your routine.

If you follow JHB's Instructions you should get a different error situation which might provide more information about the problem.

Sent from my SM-G925F using Tapatalk
 

JHB

Have been here a while
Local time
Today, 09:41
Joined
Jun 17, 2012
Messages
7,732
Placing a comma at the beginning of a line turns the line into a comment.
Sorry Uncle Gizmo, it is not a comma but an apostrophe!
syedadnan - if you place an apostrophe where I show you, then user-created errorhandling is out of function and the program will stop at the codeline which cause the error.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 08:41
Joined
Jul 9, 2003
Messages
16,282
Sorry Uncle Gizmo, it is not a comma but an apostrophe!
syedadnan - if you place an apostrophe where I show you, then user-created errorhandling is out of function and the program will stop at the codeline which cause the error.

Oh yeah my bad!!! I didn't do too well in English at school!!! My teacher Mrs Patterson (John O'Gaunt School Hungerford Berkshire) that's where Michael Ryan shot everyone (I wasn't there).... She used to say "HINE" this is spelt wrong!! I would say "you can read it can't you" --- what's a problem..

My punctuation grammar everything really is severely lacking... I was speaking to my sister a few months ago she said that the government did an experiment in the 70's in a few schools. They decided not to teach Grammar.

I happened to be in a year and class that this happened. I don't know if there's any truth in it, but that's what she was told...
 

syedadnan

Access Lover
Local time
Today, 11:41
Joined
Mar 27, 2013
Messages
315
Sorry Uncle Gizmo, it is not a comma but an apostrophe!
syedadnan - if you place an apostrophe where I show you, then user-created errorhandling is out of function and the program will stop at the codeline which cause the error.

WOW that's done ...Thanks a lot
 

Users who are viewing this thread

Top Bottom