question about exiting a procedure

G

Gary Keramidas

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
 
J

Jim Cone

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
 
G

Gary Keramidas

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

Jim Cone

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
 
G

Gary Keramidas

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
 
B

Bob Phillips

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top