Audit Log Error Message - Help (1 Viewer)

wchelly

Registered User.
Local time
Yesterday, 19:49
Joined
Mar 1, 2010
Messages
146
I've been using an the Audit Trail module for almost a year and have had no problems until now. It is giving me an error message

"The expression you entered has a field, control, or property nam that Microsoft Access can't find 2424. "

If I remove the procedure from "Before-Update", it doesn't give me the message.

What could be causing this?
 

pr2-eugin

Super Moderator
Local time
Today, 03:49
Joined
Nov 30, 2011
Messages
8,494
Did you try debugging? It would take you to the LOC where the error was raised !!
 

wchelly

Registered User.
Local time
Yesterday, 19:49
Joined
Mar 1, 2010
Messages
146
Thanks for your response, and yes I did try debugging, and I just tried it again. It didn't find a bug.
 

pr2-eugin

Super Moderator
Local time
Today, 03:49
Joined
Nov 30, 2011
Messages
8,494
No I did not mean Compile -> Debug in the VB Editor.. When you run the code, you would be given an option like..



If you click Debug, it should take you to the error? highlighting you which line you have the error at..
 

Attachments

  • nullErr.png
    nullErr.png
    17.8 KB · Views: 514

boblarson

Smeghead
Local time
Yesterday, 19:49
Joined
Jan 12, 2001
Messages
32,059
If I remove the procedure from "Before-Update", it doesn't give me the message.

What could be causing this?
Well, if it doesn't give you the error if you remove that, then the odds are that it is that which is causing the error. Care to post the code for it so we can take a look?
 

wchelly

Registered User.
Local time
Yesterday, 19:49
Joined
Mar 1, 2010
Messages
146
I don't get a message box

like that. I get...

Error x
The expression you entered has a field, control, or property name that Microsoft Access can't find.

OK

That is all the text and the only option is to click oK or close the box.
 

boblarson

Smeghead
Local time
Yesterday, 19:49
Joined
Jan 12, 2001
Messages
32,059
Well, if it doesn't give you the error if you remove that, then the odds are that it is that which is causing the error. Care to post the code for it so we can take a look?

Posting again -

Care to post the code for it so we can take a look?

Oh, and make sure you aren't putting your code in the event PROPERTY but in the actual VBA window.
 

wchelly

Registered User.
Local time
Yesterday, 19:49
Joined
Mar 1, 2010
Messages
146
Yes, that's how I figured out what was causing it. I just started deleting things.

Here is the code in the Audit Trail module.
Code:
Option Compare Database
Const cDQ As String = """"
Sub AuditTrail(frm As Form, ShipperID As Control)
'Track changes to data.
'recordid identifies the pk field's corresponding
'control in frm, in order to id record.
    Dim ctl As Control
    Dim varBefore As Variant
    Dim varAfter As Variant
    Dim strControlName As String
    Dim strSql As String
    On Error GoTo ErrHandler
    'Get changed values.
    For Each ctl In frm.Controls
        With ctl
            'Avoid labels and other controls with Value property.
            If .ControlType = acTextBox Then
                If .value <> .OldValue Then
                    varBefore = .OldValue
                    varAfter = .value
                    strControlName = .Name
                    'Build INSERT INTO statement.
                    strSql = "INSERT INTO " _
                           & "Audit (EditDate, User, ShipperID, SourceTable, " _
                           & " SourceField, BeforeValue, AfterValue) " _
                           & "VALUES (Now()," _
                           & cDQ & Environ("username") & cDQ & ", " _
                           & cDQ & ShipperID.value & cDQ & ", " _
                           & cDQ & frm.RecordSource & cDQ & ", " _
                           & cDQ & .Name & cDQ & ", " _
                           & cDQ & varBefore & cDQ & ", " _
                           & cDQ & varAfter & cDQ & ")"
                    'View evaluated statement in Immediate window.
                    Debug.Print strSql
                    DoCmd.SetWarnings False
                    DoCmd.RunSQL strSql
                    DoCmd.SetWarnings True
                End If
            End If
        End With
    Next
    Set ctl = Nothing
    Exit Sub
ErrHandler:
    MsgBox Err.Description & vbNewLine _
         & Err.Number, vbOKOnly, "Error"
End Sub

AND here's the procedure that calls the module...

Public Sub Form_BeforeUpdate(Cancel As Integer)
Call basAuditTrail.AuditTrail(Me, ShipperID)
End Sub
 
Last edited by a moderator:

boblarson

Smeghead
Local time
Yesterday, 19:49
Joined
Jan 12, 2001
Messages
32,059
Does it compile? Can you go to DEBUG > COMPILE and no errors appear? If not, can you put a breakpoint and do a change in the form and then when it hits the breakpoint you F8 through until you get to the part it doesn't like.
 

boblarson

Smeghead
Local time
Yesterday, 19:49
Joined
Jan 12, 2001
Messages
32,059
It compliles ...strange
No, it isn't strange. It is just that we are tracking it down. So run it with a breakpoint at the start of that procedure and then F8 through it until the error appears.
 

wchelly

Registered User.
Local time
Yesterday, 19:49
Joined
Mar 1, 2010
Messages
146
OK..I used debug.print (see below). When Ran it, The immediate window showed it appears to loop through Bug9 and Bug10 repeatedly.

And then it tripped the debugger at Bug2. What it means, I don't know?

If .ControlType = acTextBox Then
Debug.Print "Bug1"
If .Value <> .OldValue Then
Debug.Print "Bug2"
varBefore = .OldValue
varAfter = .Value
Debug.Print "Bug3"
strControlName = .Name
Debug.Print "Bug4"
'Build INSERT INTO statement.
strSql = "INSERT INTO " _
& "Audit (EditDate, User, ShipperID, SourceTable, " _
& " SourceField, BeforeValue, AfterValue) " _
& "VALUES (Now()," _
& cDQ & Environ("username") & cDQ & ", " _
& cDQ & ShipperID.Value & cDQ & ", " _
& cDQ & frm.RecordSource & cDQ & ", " _
& cDQ & .Name & cDQ & ", " _
& cDQ & varBefore & cDQ & ", " _
& cDQ & varAfter & cDQ & ")"
Debug.Print "Bug5"
'View evaluated statement in Immediate window.
Debug.Print strSql
Debug.Print "Bug6"
DoCmd.SetWarnings False
DoCmd.RunSQL strSql
Debug.Print "Bug7"
DoCmd.SetWarnings True
End If
Debug.Print "Bug8"
End If
Debug.Print "Bug9"
End With
Debug.Print "Bug10"
Next
Set ctl = Nothing
Debug.Print "Bug11"
Exit Sub
Debug.Print "Bug12"

ErrHandler:
MsgBox Err.Description & vbNewLine _
& Err.Number, vbOKOnly, "Error"
End Sub
 

wchelly

Registered User.
Local time
Yesterday, 19:49
Joined
Mar 1, 2010
Messages
146
When I step through the code with f8,

It prints the following bugs in the immediate window.
Bug1
Bug8
Bug9
Bug10
 

wchelly

Registered User.
Local time
Yesterday, 19:49
Joined
Mar 1, 2010
Messages
146
http://support.microsoft.com/kb/184664?wa=wsignin1.0
Well, I don't think this is a problem because my form is based on one query from one table with a project number parameter. I have several subforms that are based on other related tables however, but it doesn't seem like this is what the article is talking about. I could be wrong, but I don't understand how this would be happening if what causes it is having multiple tables feeding a query.
 

wchelly

Registered User.
Local time
Yesterday, 19:49
Joined
Mar 1, 2010
Messages
146
Sorry, I don't know much about debugging...is this what you are looking for?

When I set a breakpoint at
For Each ctl In frm.Controls

It highlights the following:
If .ControlType = acTextBox Then
Then it skips to
End If
 

wchelly

Registered User.
Local time
Yesterday, 19:49
Joined
Mar 1, 2010
Messages
146
I set a breakpoint at
On Error GoTo ErrHandler

It steps through each line until
If .ControlType = acTextBox Then

Then skips to
End If

So, I guess what that means is that it doesn't recognize my textbox as acTextBox
 

boblarson

Smeghead
Local time
Yesterday, 19:49
Joined
Jan 12, 2001
Messages
32,059
Any chance you can upload a copy of the database with fake data so we can see what we can find?
 

wchelly

Registered User.
Local time
Yesterday, 19:49
Joined
Mar 1, 2010
Messages
146
Well, I wouldn't mind but I think I've found the solution. I appologize, but I didn't see this thread before. It appeared at the bottom of the screen so I clicked on it and after I read through the solution, I then went to my form and started deleting text boxes. I found one hidden box that was sort of a "Ghost box" that was not assigned a valid field. When I deleted this box, the code miraculously worked. Thank you so much for troubleshooting with me!
http://www.access-programmers.co.uk/forums/showthread.php?t=59870
 

Users who are viewing this thread

Top Bottom