Avatar of Milewskp
MilewskpFlag for Canada

asked on 

On Error statement syntax

This VBA statement:
  On Error gcfHandleErrors Then GoTo PROC_ERR

occurs in the EE question:
https://www.experts-exchange.com/questions/22129974/How-to-find-the-name-of-the-calling-routine.html.

But I couldn't get it to work. Does VBA actually allow this syntax? If so, how do you get it to work?
Microsoft Access

Avatar of undefined
Last Comment
Milewskp
Avatar of jefftwilley
jefftwilley
Flag of United States of America image

this appears to be

2. The global variable gcfHandleErrors is set to FALSE during development so crashes stop at the offending line rather than it going into the global error handler.

Do you have a global boolean variable called gcfHandleErrors?
SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Milewskp
Milewskp
Flag of Canada image

ASKER

Hi Jeff,
Yes, I have set up a global boolean constant called gcfHandleErrors. Here is my code:

Public Const gcfHandleErrors As Boolean = False
Function test()
    Dim a As Integer
   
    On Error gcfHandleErrors Then GoTo PROC_ERR
    a = 1 / 0
    Exit Function
   
PROC_ERR:
   
End Function

But the statement won't even compile. Does it compile on your PC?
Avatar of jefftwilley
jefftwilley
Flag of United States of America image

No, When I paste that into a module it immediately changes the On Error statement to red
Avatar of jefftwilley
jefftwilley
Flag of United States of America image

this seems to get it past the edit error but is it the same? Not Sure

    If gcfHandleErrors Then GoTo PROC_ERR
Avatar of jefftwilley
jefftwilley
Flag of United States of America image

Seems redundant. It's like a global "stop in your tracks" thing I think that Luke came up with to build his array for error debugging. I believe, and don't quote me, that this is a part of some application that he sells...but I can't be sure. Are you trying to implement a larger error handling solution than a hardcoded Module/function name error description solution?
J
Avatar of Milewskp
Milewskp
Flag of Canada image

ASKER

Hi Jeff,
I've very seen this syntax before, and was just wondering if it is valid.
Avatar of jefftwilley
jefftwilley
Flag of United States of America image

I'm trying it, like you are, in VBA. Perhaps it's meant for a VB app...but I can't tell you if there's a difference. What I know is the on error statement doesn't execute on any condition other than if there IS an error. So the method seems wrong to me. And if it's testing for the boolean value, then what's it supposed to do if the boolean is false?

I would suggest e-mailing Luke...and have him tell you the ins and outs...and whether it's something specific to his pre-rolled app, or if it can or will work with any old Database.

My testing of it.....Failed.

J
Avatar of jefftwilley
jefftwilley
Flag of United States of America image

I've asked other experts to have a look as well.
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Luke states:

<quote>
.. It basically works like this:

Sub MyName()
  PushStack "MyName"
  On Error gcfHandleErrors Then GoTo PROC_ERR

  < procedure code goes here >

PROC_EXIT:
  PopStack
  Exit Sub

PROC_ERR:
  GlobalErrorHandler
  Resume PROC_EXIT
End Sub  
</quote>

As is, it doesn't work. So either Luke wrote it as a kind of skeleton or he is wrong; even experts may make errors from time to time ...

/gustav
Avatar of Milewskp
Milewskp
Flag of Canada image

ASKER

Does anyone have Luke's email?
ASKER CERTIFIED SOLUTION
Avatar of jefftwilley
jefftwilley
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Milewskp
Milewskp
Flag of Canada image

ASKER

Thanks Jeff, I'll try that.
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Did you find a solution?

/gustav
Avatar of Milewskp
Milewskp
Flag of Canada image

ASKER

No, I never got a response from Luke.
SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Milewskp
Milewskp
Flag of Canada image

ASKER

The consensus is that VBA doesn't allow this syntax. I will split points equally between all participants. Thanks everyone from your input!
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo