#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 460
Default Exit 2 Sub

I have a button that calls for a proceedure. There is a message box to exit
the proceedure if condition is not met. How do I exit the balance of the
first proceedure so it doesn't continue to the end?

The code I have is:

Private Sub cmdEnterPledge_Click()
Call FillPledgeInfo
' more code '( this is where I want to end this sub so it doesn't
continue & save)
ActiveWorkbook.Save
End Sub

Private Sub FillPledgeInfo()
If txtBox1.Value = "" Then
MsgBox ("Donor Number Must be Entered Before Entering Pledge")
Exit Sub
End If
' more code
End Sub

I hope this is enough info so you can figure out what I'm trying to do.
Thanks for your help.
Doug
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Exit 2 Sub

Based on what you have posted, all you would have to do is remove the

ActiveWorkbook.Save

But I do not think that is what you want to do. I believe the message box
you referred to is missing. So, what I would normally do with the message
box is something like this:

choice = MsgBox("Do you want to continue?", vbYesNo, "CHOOSE")
If choice = vbYes Then
Else
Exit Sub
End If


"Doug" wrote in message
...
I have a button that calls for a proceedure. There is a message box to
exit
the proceedure if condition is not met. How do I exit the balance of the
first proceedure so it doesn't continue to the end?

The code I have is:

Private Sub cmdEnterPledge_Click()
Call FillPledgeInfo
' more code '( this is where I want to end this sub so it doesn't
continue & save)
ActiveWorkbook.Save
End Sub

Private Sub FillPledgeInfo()
If txtBox1.Value = "" Then
MsgBox ("Donor Number Must be Entered Before Entering Pledge")
Exit Sub
End If
' more code
End Sub

I hope this is enough info so you can figure out what I'm trying to do.
Thanks for your help.
Doug



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Exit 2 Sub

Doug

The conditions must be checked within the main procedure itself like below..

Private Sub cmdEnterPledge_Click()
If txtBox1.Value = "" Then
MsgBox ("Donor Number Must be Entered Before Entering Pledge")
Exit Sub
Else
Call FillPledgeInfo
End If

' more code

ActiveWorkbook.Save
End Sub

Private Sub FillPledgeInfo()
' more code
End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"Doug" wrote:

I have a button that calls for a proceedure. There is a message box to exit
the proceedure if condition is not met. How do I exit the balance of the
first proceedure so it doesn't continue to the end?

The code I have is:

Private Sub cmdEnterPledge_Click()
Call FillPledgeInfo
' more code '( this is where I want to end this sub so it doesn't
continue & save)
ActiveWorkbook.Save
End Sub

Private Sub FillPledgeInfo()
If txtBox1.Value = "" Then
MsgBox ("Donor Number Must be Entered Before Entering Pledge")
Exit Sub
End If
' more code
End Sub

I hope this is enough info so you can figure out what I'm trying to do.
Thanks for your help.
Doug

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Exit 2 Sub

Since I am not sure whether the previous replies really addressed your
question I want to throw in my five cents as well. I would suggest you turn
the FillPledgeInfo() subroutine into a boolean-type function like so:

Private Function FillPledgeInfo() as Boolean
If txtBox1.Value = "" Then
MsgBox ("Donor Number Must be Entered Before Entering Pledge")
FillPledgeInfo = False
Exit Sub
End If
' more code
FillPledgeInfo = True
End Sub

I you do it this way you can include a line like this in your calling routine:

If FillPledgeInfo() = False Then Exit Sub

Hope this helped.


"Jacob Skaria" wrote:

Doug

The conditions must be checked within the main procedure itself like below..

Private Sub cmdEnterPledge_Click()
If txtBox1.Value = "" Then
MsgBox ("Donor Number Must be Entered Before Entering Pledge")
Exit Sub
Else
Call FillPledgeInfo
End If

' more code

ActiveWorkbook.Save
End Sub

Private Sub FillPledgeInfo()
' more code
End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"Doug" wrote:

I have a button that calls for a proceedure. There is a message box to exit
the proceedure if condition is not met. How do I exit the balance of the
first proceedure so it doesn't continue to the end?

The code I have is:

Private Sub cmdEnterPledge_Click()
Call FillPledgeInfo
' more code '( this is where I want to end this sub so it doesn't
continue & save)
ActiveWorkbook.Save
End Sub

Private Sub FillPledgeInfo()
If txtBox1.Value = "" Then
MsgBox ("Donor Number Must be Entered Before Entering Pledge")
Exit Sub
End If
' more code
End Sub

I hope this is enough info so you can figure out what I'm trying to do.
Thanks for your help.
Doug

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
Exit Field vs Exit Button...... roy_ware Excel Programming 2 October 10th 07 04:05 PM
Exit Sub Raman325[_38_] Excel Programming 4 May 25th 06 08:13 PM
Help with For Next and Exit For Jacqui Excel Programming 6 November 3rd 05 11:17 AM
exit while? Steven Deng Excel Programming 1 November 6th 04 12:14 AM
If a called sub exit, how to the caller exit right away? luvgreen[_4_] Excel Programming 4 February 24th 04 05:06 PM


All times are GMT +1. The time now is 08:16 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"