Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default question about exiting a procedure


let's say i have a form with a command button
when clicked it runs a procedure in one module
when that's done it runs a second one

Private Sub CommandButton1_Click()
Application.Run ("1st sub")
Application.Run ("2nd sub")
end sub


if there is an error at a particular place in the 1st sub, i want to exit and
make sure the 2nd sub doesn't run

how do i do that? exit sub exits the 1st one and then the 2nd one runs


--


Gary



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default question about exiting a procedure

Gary,
Call the 2nd sub from the 1st sub.
If the 1st sub errors and exits then it can't call the 2nd sub.
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"Gary Keramidas" <GKeramidasATmsn.com wrote in message ...

let's say i have a form with a command button
when clicked it runs a procedure in one module
when that's done it runs a second one

Private Sub CommandButton1_Click()
Application.Run ("1st sub")
Application.Run ("2nd sub")
end sub


if there is an error at a particular place in the 1st sub, i want to exit and
make sure the 2nd sub doesn't run
how do i do that? exit sub exits the 1st one and then the 2nd one runs
Gary
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default question about exiting a procedure

thanks for the info jim. was wondering if this would be the best way or not.

--


Gary


"Jim Cone" wrote in message
...
Gary,
Call the 2nd sub from the 1st sub.
If the 1st sub errors and exits then it can't call the 2nd sub.
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...

let's say i have a form with a command button
when clicked it runs a procedure in one module
when that's done it runs a second one

Private Sub CommandButton1_Click()
Application.Run ("1st sub")
Application.Run ("2nd sub")
end sub


if there is an error at a particular place in the 1st sub, i want to exit and
make sure the 2nd sub doesn't run
how do i do that? exit sub exits the 1st one and then the 2nd one runs
Gary



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default question about exiting a procedure

Best way to do what?
You could pass a boolean flag to the first sub and if it is
returned as True then the second sub would run.
Jim Cone

'---------------
Private Sub CommandButton1_Click()
Dim blnFlag As Boolean
Call First(blnFlag)
If blnFlag Then Call Second
End Sub

Sub First(ByRef blnContinue As Boolean)
'code
blnContinue = True
End Sub

Sub Second()
'code
End Sub
'--------------




"Gary Keramidas" <GKeramidasATmsn.com wrote in message ...
thanks for the info jim. was wondering if this would be the best way or not.
Gary


"Jim Cone" wrote in message
...
Gary,
Call the 2nd sub from the 1st sub.
If the 1st sub errors and exits then it can't call the 2nd sub.
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...

let's say i have a form with a command button
when clicked it runs a procedure in one module
when that's done it runs a second one

Private Sub CommandButton1_Click()
Application.Run ("1st sub")
Application.Run ("2nd sub")
end sub


if there is an error at a particular place in the 1st sub, i want to exit and
make sure the 2nd sub doesn't run
how do i do that? exit sub exits the 1st one and then the 2nd one runs
Gary



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default question about exiting a procedure

if your first suggestion would be the best way. i used your suggestion in the
past but figured i would ask for another opinion. your 1st suggestion works
fine. i try to keep things simple, so your 2nd suggestion is stored away for
future use.


thanks again
--


Gary


"Jim Cone" wrote in message
...
Best way to do what?
You could pass a boolean flag to the first sub and if it is
returned as True then the second sub would run.
Jim Cone

'---------------
Private Sub CommandButton1_Click()
Dim blnFlag As Boolean
Call First(blnFlag)
If blnFlag Then Call Second
End Sub

Sub First(ByRef blnContinue As Boolean)
'code
blnContinue = True
End Sub

Sub Second()
'code
End Sub
'--------------




"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
thanks for the info jim. was wondering if this would be the best way or not.
Gary


"Jim Cone" wrote in message
...
Gary,
Call the 2nd sub from the 1st sub.
If the 1st sub errors and exits then it can't call the 2nd sub.
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...

let's say i have a form with a command button
when clicked it runs a procedure in one module
when that's done it runs a second one

Private Sub CommandButton1_Click()
Application.Run ("1st sub")
Application.Run ("2nd sub")
end sub


if there is an error at a particular place in the 1st sub, i want to exit and
make sure the 2nd sub doesn't run
how do i do that? exit sub exits the 1st one and then the 2nd one runs
Gary







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default question about exiting a procedure

Make those two subs functions and pass a return code back indicating success
or not

If Sub1 Then
If Sub2 Then
'all okay
Else
MsgBox "Sub2 failed"
End If
Else
MsgBox "Sub 1 failed"
End If

Why are you using Application.Run, this is only required if they are in
another project.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...

let's say i have a form with a command button
when clicked it runs a procedure in one module
when that's done it runs a second one

Private Sub CommandButton1_Click()
Application.Run ("1st sub")
Application.Run ("2nd sub")
end sub


if there is an error at a particular place in the 1st sub, i want to exit

and
make sure the 2nd sub doesn't run

how do i do that? exit sub exits the 1st one and then the 2nd one runs


--


Gary





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
Exiting a procedure with a userform jumpjump[_4_] Excel Programming 2 August 30th 05 09:04 AM
Creating an event procedure question bhofsetz[_6_] Excel Programming 2 June 8th 05 07:03 PM
Worksheet_Change procedure question Grant Excel Programming 0 October 1st 04 01:17 AM
Worksheet_Change procedure question Grant Excel Programming 0 September 28th 04 08:41 PM
VBA question - calling Procedure from userform ajliaks[_3_] Excel Programming 2 April 14th 04 09:11 PM


All times are GMT +1. The time now is 11:11 PM.

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

About Us

"It's about Microsoft Excel"