ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   question about exiting a procedure (https://www.excelbanter.com/excel-programming/355119-question-about-exiting-procedure.html)

Gary Keramidas

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




Jim Cone

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

Gary Keramidas

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




Jim Cone

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




Gary Keramidas

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






Bob Phillips[_6_]

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







All times are GMT +1. The time now is 02:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com