+ Reply to Thread
Results 1 to 9 of 9

Stop routine with error handling

  1. #1
    Registered User
    Join Date
    08-31-2016
    Location
    Appingedam, Netherlands
    MS-Off Ver
    2013
    Posts
    7

    Stop routine with error handling

    Can someone give me a hint in the rigth direction.
    I have a routine which give a check on a certain state in my excel sheet. Based on that state the routine will give an error.
    I would like to use this error to stop the following routine which shouldn’t run after this error.
    These are to separate routine which are called after each other with another routine.
    I have something like this in the first code:
    Please Login or Register  to view this content.
    The second code has this:
    Please Login or Register  to view this content.
    So the first routine should stop the second one on error from running.
    However this code isn’t working.

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Stop routine with error handling

    Hi,

    How are these two codes related? I do not see either one call the other. Further, nothing after the Exit Sub in the second code will ever run.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Registered User
    Join Date
    08-31-2016
    Location
    Appingedam, Netherlands
    MS-Off Ver
    2013
    Posts
    7

    Re: Stop routine with error handling

    Thanks for your swift reply.
    The first code calls the second one with Call second sub.

    As for the Exit Sub. This should be the case only when the error has occured
    So that's not good.
    I'm pretty new to vba so i'm trying but I need some help with this.

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Stop routine with error handling

    I'm afraid it is unclear as to how or where the first routine calls the second and indeed what exactly you wish to happen. Your initial post suggests that there is in fact a third piece of code that calls both of the supplied codes- is that correct?

  5. #5
    Registered User
    Join Date
    08-31-2016
    Location
    Appingedam, Netherlands
    MS-Off Ver
    2013
    Posts
    7

    Re: Stop routine with error handling

    Yes ther is a third piece of code.

    Please Login or Register  to view this content.
    The "Sheet#" routine calls the "Finalize" routine. When the stae of one cell in the excel sheet is "vbNoPermissionFinalization" the last "boxcheck" routine should not run.
    However the state of the cell rad during the start of the "finalize" routine and changed later in the code by the "finalize" routine. Therefore the "OKButton" routine should be stooped by the finalize routine.
    Maybe I should do something with "function" but I'm a newbee on vba so I was happy to get this far already.
    I hope it's a bit more clear now. Thanks for your patience anyway.

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Stop routine with error handling

    What is the code for createError?

    Since there is no error handler in the OK button code, any errors raised that are not handled by the routines it calls should cause the OK button code to stop with an error.

  7. #7
    Registered User
    Join Date
    08-31-2016
    Location
    Appingedam, Netherlands
    MS-Off Ver
    2013
    Posts
    7

    Re: Stop routine with error handling

    Sub createError(ByVal errorType As Integer)
    If errorType = vbNoPermissionSubmission Then MsgBox ("Submitting is not permitted"), vbExclamation
    If errorType = vbNoPermissionRejection Then MsgBox ("Rejection is not permitted"), vbExclamation
    If errorType = vbNoPermissionFinalization Then MsgBox ("Finalization is not permitted"), vbExclamation
    If errorType = vbMissingOrderNumber Then MsgBox ("Order Number is required"), vbExclamation
    If errorType = vbProjectManagerMissing Then MsgBox ("Project Manager is required"), vbExclamation
    If errorType = vbSalesEngineerMissing Then MsgBox ("Sales Force Member is required"), vbExclamation
    If errorType = vbClientMissing Then MsgBox ("Client is required"), vbExclamation
    If errorType = vbRevisionError Then MsgBox ("Revision number in the filename is wrong, revision number from Excel Workbook will be used instead"), vbExclamation
    If errorType = vbProtected Then MsgBox ("The IPO is protected, unprotect to proceed"), vbExclamation
    If errorType = vbUnprotected Then MsgBox ("The IPO is already unprotected"), vbExclamation
    If errorType = vbInvalidPath Then MsgBox ("Please save the IPO on the network, it is now saved on your PC"), vbExclamation
    End Sub

  8. #8
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Stop routine with error handling

    In that case the Finalize routine is not actually raising an error, it is merely providing a message box and then existing that routine, at which point the next routine is called. If you wish to prevent further code from running, you can either have the Finalize routine actually raise an error before it exits, or convert it into a function that returns some indicator of success or failure. The calling routine can then simply test whether the function succeeded and react appropriately.

    I'm afraid it is not possible for me to be clearer than that without being able to see precisely how all this code fits together.

  9. #9
    Registered User
    Join Date
    08-31-2016
    Location
    Appingedam, Netherlands
    MS-Off Ver
    2013
    Posts
    7

    Re: Stop routine with error handling

    That's true it's a message box. I'haven't worked with the function parts so I have to figure that out.
    Thanks for putting me back to the start . This saves me a lot of time hidding ht worng way.

+ 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. barcodes handling as daily routine
    By jacohauritz in forum Excel Formulas & Functions
    Replies: 17
    Last Post: 08-09-2016, 12:43 PM
  2. Error handling inside error handling
    By grantastley in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-06-2015, 03:43 AM
  3. Error Handling to Stop Run-time Errors
    By Nulladave in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-18-2014, 08:42 AM
  4. [SOLVED] Error checking routine - check range values on various worksheets and report if error
    By TheRobsterUK in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-29-2014, 06:36 AM
  5. How do I stop a routine?
    By cmcgath in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-20-2009, 02:32 PM
  6. [SOLVED] ClearContents command causes routine to stop
    By Peter Ekstrom in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-11-2005, 04:06 PM
  7. Error handling with a handling routine
    By ben in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-15-2005, 11:06 AM

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