Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50070

Stop procedure completely without error

$
0
0
Hello,

When we want to end a procedure (that's been called by another sub routine) within an error handler, we just use END. This prevents the error handler from passing back up to the original sub routine that called the procedure in the first place. This is great.

However when we use End from within a form, it doesn't end, it continues on executing code (see example below). After our app presents a user form, if the user hits cancel we want to END the entire procedure and execute no more code. Putting "END" in the code for the cancel button still passes the procedure back up to the main system and continues executing code. We want to end everything at that point without continuing. Here's the code:

Code:

Sub main()

Call writeToExecutionLog
Call createBackup
'Show user form:
ReportSelector.Show
' If the user clicks on Cancel from the userform shown above,
' we do NOT want the following code to execute:
Call updateSystemExecutedDate
Call writeToExecutionLogSuccess

End Sub

We tried calling a sub routine from the cancel button back in the main system module that just contained "END" but that didn't work either.

Here's our cancel button code:

Code:

Private Sub cmdCancel_Click()
    Unload Me
    End
End Sub

Any ideas on how to just flat out end all code from the form?

Viewing all articles
Browse latest Browse all 50070

Trending Articles