+ Reply to Thread
Results 1 to 9 of 9

using err.raise works first time but subsequently produces and automation error

  1. #1
    Registered User
    Join Date
    06-10-2011
    Location
    Mansfield, England
    MS-Off Ver
    Excel 2007
    Posts
    10

    Question using err.raise works first time but subsequently produces and automation error

    Hi All,
    I have a generic function I use to validate if a value is within a drop down list. I recently decided to make it error within the function rather than passing it back to the calling proc, and I decided to do this by raising a custom error. This works as expected the first time it is invoked, but second and subsequent times produce an Automation error on the err.raise line. The complete sequence of events are:
    1. user presses "Validate" button to start validation code
    2. A user entered value fails the lookup and the expected error msgbox in the error handler is displayed
    3. Usr clicks OK in msgbox and validation ends
    4. User corrects the error (or not) and then again presses the validate button
    5. Either the same value or another value fails the lookup function, but this time a "Run-time error '-2147220503 (800403e9)' Automation error is thrown
    6. pressing debg takes me to the err.raise line
    Full procedure shown below - Any advice welcome
    Please Login or Register  to view this content.
    Last edited by edwar368; 09-18-2014 at 10:34 AM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: using err.raise works first time but subsequently produces and automation error

    Do you need to raise an error?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    06-10-2011
    Location
    Mansfield, England
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: using err.raise works first time but subsequently produces and automation error

    Hi,
    I think I know where you are going with this. I have toyed around with not raising an error and simply displaying the error message within the "If LookupFound = False Then" (And have also tested it and that works fine .... however the pureist in me is keen to find out why this is occuring, because a lot of online material makes reference to using the err.raise to keep things "neat" and also provide a single point of exit. So whilst this problem is not a showstopper for me, I am keen from a developer perspective to understand where I have gone wrong, as I was considering using this err.raise technique throughout numerous workbooks I maintain

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,286

    Re: using err.raise works first time but subsequently produces and automation error

    Why are you using End on its own in real code?

    I suspect that because of that, this line doesn't run:
    Please Login or Register  to view this content.
    (since your global variable has been reset) and you don't have any error handling in place.
    Remember what the dormouse said
    Feed your head

  5. #5
    Registered User
    Join Date
    06-10-2011
    Location
    Mansfield, England
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: using err.raise works first time but subsequently produces and automation error

    Hi,
    I am using End on its own in this specifc function, because that is exactly what I want to happen. If this procedure fails, I want to present the user with a meaningfull enough message to identify where they have entered invaluid data (which is what the msgbox text does"), but then exit any further processing, thereby forcing the user to correct the error, before re-validating

  6. #6
    Registered User
    Join Date
    06-10-2011
    Location
    Mansfield, England
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: using err.raise works first time but subsequently produces and automation error

    Thanks Rory, not sure if you edited your first response, but I originally only saw the question about "why using end", but I now think I know what you are getting at. Because I used "end" on its own, it has reset the global variables
    Thanks you very much

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,286

    Re: using err.raise works first time but subsequently produces and automation error

    Yes, sorry I did edit for clarification. Using End on its own is extremely dangerous. Given that you are using a function without a current return value, I'd return a Boolean indicating whether or not to continue, so that the calling code can check that and exit if need be.

  8. #8
    Registered User
    Join Date
    06-10-2011
    Location
    Mansfield, England
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: using err.raise works first time but subsequently produces and automation error

    Thanks a lot for the very quick response

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,286

    Re: using err.raise works first time but subsequently produces and automation error

    Glad to help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Macro for Replacing Text Produces Run-Time Error 91
    By bryanmarks in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-30-2014, 10:22 AM
  2. Simple polynomial produces error ONLY for a certain input, otherwise works
    By anna86 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-15-2014, 01:57 PM
  3. [SOLVED] ComboList produces errors run-time error...
    By radgrad in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-13-2014, 09:24 PM
  4. [SOLVED] Excel produces Error when the code works
    By WadeLair in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-09-2012, 11:15 PM
  5. Clicking Red X on UserForm produces run-time error '91'
    By ChrisMattock in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-10-2008, 04:38 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1