+ Reply to Thread
Results 1 to 3 of 3

Exit Sub Procedure when called on Sub Procedure Exits

  1. #1
    Forum Contributor onmyway's Avatar
    Join Date
    09-03-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    2013
    Posts
    386

    Exit Sub Procedure when called on Sub Procedure Exits

    Hi all,

    I hope you can help me.

    Is there a way to cancel the "main" sub procedure calling on another sub procedure to do a task, when the called on sub procedure is cancelled due to validation not met?

    Let me explain:

    1. I have a Private Sub btnSave_click() procedure that calls on a Private Sub Validations() procedure to validate certain fields and data in my userForm.

    Please Login or Register  to view this content.
    2. When a validation fails in my Sub Validations() the sub exits. But this does not stop the Private Sub btnSave_click() from running the rest of the code.

    Please Login or Register  to view this content.
    3. How can I get both subs to exit in such a case?

    Thank you in advance!
    Last edited by onmyway; 05-29-2015 at 08:18 AM.
    Sharing knowledge, can be likened to taking another person's hand, and pulling them up to a higher level -- onmyway

    If I was helpful, please remember to click on * Add Reputation below

  2. #2
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Exit Sub Procedure when called on Sub Procedure Exits

    Declare a global variable that you change in the sub validations and check after returning to the sub that called it.

    example:
    Please Login or Register  to view this content.
    Please click the * below if this helps

  3. #3
    Forum Contributor onmyway's Avatar
    Join Date
    09-03-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    2013
    Posts
    386

    Re: Exit Sub Procedure when called on Sub Procedure Exits

    Hi JasperD,

    Perfect. Thank you!

+ 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. Procedure skips portion of code when called from another procedure
    By abkar in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-26-2014, 05:14 PM
  2. to exit main procedure from procedure called by yhe main
    By kmlprtsngh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-27-2010, 02:46 PM
  3. Find Method within a called procedure
    By Neal Zimm in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-10-2006, 05:45 PM
  4. [SOLVED] procedure continuously being called
    By nathan in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-19-2006, 04:45 PM
  5. [SOLVED] private sub- which procedure called it
    By Sunil in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-27-2005, 08:05 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