Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Solution to Stopping Program Execution

One way is to use Functions instead of subs, then check check the return
value:

Private Sub CommandButton1_Click()
If Routine1 = False Then
Exit Sub
Else
Call Routine2
End If
End Sub

Private Function Routine1() As Boolean
Routine1 = (Rnd() 0.5)
End Function

Private Function Routine2() As Boolean
Routine2 = (Rnd() 0.5)
End Function

You can also use erorr handling with Err.Raise, as VBA errors "bubble up"

Private Sub CommandButton1_Click()
'Initialte an error handler
On Error GoTo Handler

Call Routine1

Exit Sub
Handler:
Debug.Print Err.Number, Err.Description
End Sub

Private Function Routine1() As Boolean
'No error handler here
Call Routine2
End Function

Private Function Routine2() As Boolean
Dim i As Long
'No error handler here
'Some code that causes an error
i = 1 / 0
End Function

NickHK

"ALATL" wrote in message
...
Hi Nick.... I read the *consequences*....heh..... and tried using Stop
instead. I had the same result as before. The user form unloads but code

in
all the following subs continues to execute.

I'm open to any more ideas.

Best,
ALATL

"NickHK" wrote:

You are aware of the consequences of using End ?
If not, read the help.

NickHK

"ALATL" wrote in message
...
This one was pretty simple, once I found it. :-P

If Ans = vbCancel Then End --Instead of Exit Sub
End If

"Exit Sub immediately exits the Sub procedure in which it appears.

Execution
continues with the statement following the statement that called the

Sub
procedure."

..... which is why my application continued to execute & bug out.

Best,
ALATL




"ALATL" wrote:

I would like for the application to stop processing if the user

selects
vbCancel. Right now, the application does not exit & continues to

bug
out
since the Sub stops processing. Thanks for any feedback!

Dim Ans As String

Ans = MsgBox("Data columns must occur in the following order: " &

vbNewLine
& vbNewLine & _

"User Name (A)" & vbNewLine & _
"Set of Books (B)" & vbNewLine & _

"Click OK to continue. Click Cancel to correct data.", vbOKCancel +
vbQuestion, "Confirm Column Order")

If Ans = vbCancel Then Exit Sub






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Application.quit OlieH Excel Programming 3 March 15th 07 12:26 PM
difference application.quit & application.close Pierre via OfficeKB.com[_2_] Excel Programming 4 November 8th 05 07:55 PM
Exit-quit sub Tom Excel Programming 3 March 11th 05 03:50 PM
macro to close excel application other than application.quit mary Excel Programming 1 September 14th 04 03:43 PM
application.quit will not shut off application john Excel Programming 0 January 9th 04 11:29 PM


All times are GMT +1. The time now is 01:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"