object doesn't support this property or method when calling a function (1 Viewer)

dcf1999

Registered User.
Local time
Today, 10:58
Joined
Dec 19, 2018
Messages
26
So I found a good function by Allen Browne that records any errors to a table. I copied everything exactly and put the following code into a global module I have in my database:

Code:
Function LogError(ByVal lngErrNumber As Long, ByVal strErrDescription As String, _
    strCallingProc As String, Optional vParameters, Optional bShowUser As Boolean = True) As Boolean
    
On Error GoTo Err_LogError
    ' Purpose: Generic error handler.
    ' Logs errors to table "tLogError".
    ' Arguments: lngErrNumber - value of Err.Number
    ' strErrDescription - value of Err.Description
    ' strCallingProc - name of sub|function that generated the error.
    ' vParameters - optional string: List of parameters to record.
    ' bShowUser - optional boolean: If False, suppresses display.
    ' Author: Allen Browne, [EMAIL="allen@allenbrowne.com"]allen@allenbrowne.com[/EMAIL]
    Dim strMsg As String      ' String for display in MsgBox
    Dim rst As DAO.Recordset  ' The tLogError table
    Select Case lngErrNumber
    Case 0
        Debug.Print strCallingProc & " called error 0."
    Case 2501                ' Cancelled
        'Do nothing.
    Case 3314, 2101, 2115    ' Can't save.
        If bShowUser Then
            strMsg = "Record cannot be saved at this time." & vbCrLf & _
                "Complete the entry, or press <Esc> to undo."
            MsgBox strMsg, vbExclamation, strCallingProc
        End If
    Case Else
        If bShowUser Then
            strMsg = "Error " & lngErrNumber & ": " & strErrDescription
            MsgBox strMsg, vbExclamation, strCallingProc
        End If
        Set rst = CurrentDb.OpenRecordset("tLogError", , dbAppendOnly)
        rst.AddNew
            rst![ErrNumber] = lngErrNumber
            rst![ErrDescription] = Left$(strErrDescription, 255)
            rst![ErrDate] = Now()
            rst![CallingProc] = strCallingProc
            rst![UserName] = CurrentUser()
            rst![ShowUser] = bShowUser
            If Not IsMissing(vParameters) Then
                rst![Parameters] = Left(vParameters, 255)
            End If
        rst.Update
        rst.Close
        LogError = True
    End Select
Exit_LogError:
    Set rst = Nothing
    Exit Function
Err_LogError:
    strMsg = "An unexpected situation arose in your program." & vbCrLf & _
        "Please write down the following details:" & vbCrLf & vbCrLf & _
        "Calling Proc: " & strCallingProc & vbCrLf & _
        "Error Number " & lngErrNumber & vbCrLf & strErrDescription & vbCrLf & vbCrLf & _
        "Unable to record because Error " & Err.Number & vbCrLf & Err.Description
    MsgBox strMsg, vbCritical, "LogError()"
    Resume Exit_LogError
End Function
I created the table to the exact specs (field names, types) he listed and put this code at the bottom of all my subs:

Code:
ExitProc:
    Exit Sub
errhandler:
    Call LogError(Err.Number, Err.descripton, "Incidents - check_values")
    Resume ExitProc
I like this method because it logs the errors in a table and I can view them as the program gets beta tested.

I tried testing it by coding a string variable to null when a form opens thus should trip the LogError event for "invalid use of null" error but when I open the form, instead I get the error 438 (Object doesn't support this property or method). when I hit debug, it highlights this line:

Code:
    Call LogError(Err.Number, Err.descripton, "Incidents - Form_Open")
Anyone help me with this. I can't understand why it's saying this. I tried to see if it's something in the actual function but it doesn't even run the function.

The website that describes this is:
http://allenbrowne.com/ser-23a.html

Thanks.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:58
Joined
Aug 30, 2003
Messages
36,125
Potentially stupid question, but before the line setting the string to Null do you have

On Error GoTo errhandler
 

dcf1999

Registered User.
Local time
Today, 10:58
Joined
Dec 19, 2018
Messages
26
Potentially stupid question, but before the line setting the string to Null do you have

On Error GoTo errhandler

My first thought: "Yea duh, of course I did"....
but then I thought: "What a second, Did I?"

I checked... yes I do :D
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:58
Joined
Aug 30, 2003
Messages
36,125
So it's never getting to Allen's code? Is this a db you can attach here?
 

dcf1999

Registered User.
Local time
Today, 10:58
Joined
Dec 19, 2018
Messages
26
The subs calling for the function are under the "incidents" and "incidents_sub" form.

The function is under the Global Function module

I will apologize in advance that I'm not as advanced as some of you guys are in terms of design and coding. I know there are a lot of errors and I plan on cleaning them up at a future time.

If you need to "log in", you can select any name and the password is mfd2018
 

Attachments

  • FD.zip
    394.3 KB · Views: 344

Gasman

Enthusiastic Amateur
Local time
Today, 16:58
Joined
Sep 21, 2011
Messages
14,288
Doesn't the function have to be declared Public?
 

dcf1999

Registered User.
Local time
Today, 10:58
Joined
Dec 19, 2018
Messages
26
Doesn't the function have to be declared Public?

I didn’t think it had to be because it was in a module. I believe I have other functions that are not declared public in there and they get called from all the forms, and work. I’ll look at it and give it a try when I get back to my desk.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:58
Joined
Oct 29, 2018
Messages
21,473
I didn’t think it had to be because it was in a module. I believe I have other functions that are not declared public in there and they get called from all the forms, and work. I’ll look at it and give it a try when I get back to my desk.
Hi. I think without explicitly declaring it as public, it's implicitly declared as so (by default).
 

Gasman

Enthusiastic Amateur
Local time
Today, 16:58
Joined
Sep 21, 2011
Messages
14,288
I didn’t think it had to be because it was in a module. I believe I have other functions that are not declared public in there and they get called from all the forms, and work. I’ll look at it and give it a try when I get back to my desk.

Ah, OK, sorry. I have always made my functions in my module Public.:banghead:
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:58
Joined
Oct 29, 2018
Messages
21,473
The subs calling for the function are under the "incidents" and "incidents_sub" form.

The function is under the Global Function module

I will apologize in advance that I'm not as advanced as some of you guys are in terms of design and coding. I know there are a lot of errors and I plan on cleaning them up at a future time.

If you need to "log in", you can select any name and the password is mfd2018
Hi. I had to step through your code to find the source of the problem; and unfortuntely, it's coming from your form validation code, and it's choking up on your Multi-Value Field (MVF). If you want to make sure the user selected a personnel from the MVF, you'll have to use a different method than ctl.Value & "" = "".
 

dcf1999

Registered User.
Local time
Today, 10:58
Joined
Dec 19, 2018
Messages
26
Hi. I had to step through your code to find the source of the problem; and unfortuntely, it's coming from your form validation code, and it's choking up on your Multi-Value Field (MVF). If you want to make sure the user selected a personnel from the MVF, you'll have to use a different method than ctl.Value & "" = "".

I need fix that MVF... You mentioned that in another post I did a few days ago..

Question about that... the form validation code doesn't trigger until the user clicks "Save" on the form. Why would that be causing the form not opening at all if the form validation function doesn't get called until "save" is clicked.

I disabled the calling of the form validation code on the form events, it still gives the error... how can that form validation code give the error if it doesn't get called?

Not arguing with you, just trying to learn
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:58
Joined
Oct 29, 2018
Messages
21,473
Hi. Okay. Maybe the problem I found is separate from what you originally posted. Because I had no idea how to duplicate your issue, I just went through the motion of opening your file, logging in as a user, and then tried to enter an incident to try to produce an error. If that's not what you were doing, could you please give us a step-by-step instruction on how to duplicate your specific situation? Thanks.
 

dcf1999

Registered User.
Local time
Today, 10:58
Joined
Dec 19, 2018
Messages
26
Hi. Okay. Maybe the problem I found is separate from what you originally posted. Because I had no idea how to duplicate your issue, I just went through the motion of opening your file, logging in as a user, and then tried to enter an incident to try to produce an error. If that's not what you were doing, could you please give us a step-by-step instruction on how to duplicate your specific situation? Thanks.

I just click on "call / incident" and it pops up with the error... maybe I sent a bad copy of the database that I messed around and disabled something to try to figure out the problem. I reattached the file that I verified makes the error.
 

Attachments

  • fd2.zip
    529.2 KB · Views: 344

dcf1999

Registered User.
Local time
Today, 10:58
Joined
Dec 19, 2018
Messages
26
Yea sorry... the file I originally sent has the code modified to skip the error... I must have been trying to figure it out and was playing around disabling certain code.... the one I just sent is the one that's broken.

After tracing around, it seems like the error actually gets called when it gets to the check_values() under incidents. Which is where I set a string to null (which I did on purpose to make an error)

If I comment out the function call and just do a msgbox err.description, it will pop a message "invalid use of null" which is what I want put into the table tLogError... which the function called in errhandler is supposed to do.

Sorry for all the confusion... I feel stupid for posting the wrong DB.... I'm at work and I'm working on this on my breaks.
 
Last edited:

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:58
Joined
Aug 30, 2003
Messages
36,125
This didn't make any sense, it's like the function call was throwing its own error. I tested with hard-coded values and the function was fine. For chuckles I tried this and it worked...don't ask me why.

Code:
errhandler:
    Dim lngErr                As Long
    Dim strDesc               As String
    lngErr = Err.Number
    strDesc = Err.Description
    Call LogError(lngErr, strDesc, "Incidents - check_values")
    Resume ExitProc
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:58
Joined
Aug 30, 2003
Messages
36,125
Oh, and you misspelled description in the table.
 

dcf1999

Registered User.
Local time
Today, 10:58
Joined
Dec 19, 2018
Messages
26
This didn't make any sense, it's like the function call was throwing its own error. I tested with hard-coded values and the function was fine. For chuckles I tried this and it worked...don't ask me why.

Code:
errhandler:
    Dim lngErr                As Long
    Dim strDesc               As String
    lngErr = Err.Number
    strDesc = Err.Description
    Call LogError(lngErr, strDesc, "Incidents - check_values")
    Resume ExitProc

Ok yea that works now... Is there a reason why it's not working the old way? I'm confused why I have to do the extra coding... the newly declared variables are the same type as well.
 

dcf1999

Registered User.
Local time
Today, 10:58
Joined
Dec 19, 2018
Messages
26
Can I declare lngErr and strDesc as global variables so I don't have to declare them on every sub? Or is that stupid to do that?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:58
Joined
Aug 30, 2003
Messages
36,125
is that stupid to do that?

I think it's stupid to have to use the variables at all, but for some reason Access isn't liking the err values used directly (I used 2010 for my testing).

I would certainly declare them as global if nobody has some better solution making them unnecessary. I just did it that way as a test.
 

Users who are viewing this thread

Top Bottom