Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Pass a variable to a different sub

I have a 2 command buttons on a userform. cmbCalculate and cmbAddToQuote.
cmbCalculate has code that confirms all textboxes have data before
calculating a price. cmbAddToQuote adds the price to a worksheet. How can I
pass a variable value from cmbCalculate code to cmbAddToQuote code. Here is
what I have for an example. I want to stop Sub cmbAddToQuote_Click() if the
variable StopCode = True. IS this possible?

Public Sub cmbCalculate_Click()

Dim StopCode as Boolean

If textbox1 = "" Then
MsgBox "Try Again."
StopCode = True
Exit Sub
End If
End Sub

Private Sub cmbAddToQuote_Click()

Call cmbCalculate_Click

If StopCode = True Then Exit Sub

'.....additional code
End Sub

Thanks in Advance, Ryan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Pass a variable to a different sub

Did you see the responses to your other post?

RyanH wrote:

I have a 2 command buttons on a userform. cmbCalculate and cmbAddToQuote.
cmbCalculate has code that confirms all textboxes have data before
calculating a price. cmbAddToQuote adds the price to a worksheet. How can I
pass a variable value from cmbCalculate code to cmbAddToQuote code. Here is
what I have for an example. I want to stop Sub cmbAddToQuote_Click() if the
variable StopCode = True. IS this possible?

Public Sub cmbCalculate_Click()

Dim StopCode as Boolean

If textbox1 = "" Then
MsgBox "Try Again."
StopCode = True
Exit Sub
End If
End Sub

Private Sub cmbAddToQuote_Click()

Call cmbCalculate_Click

If StopCode = True Then Exit Sub

'.....additional code
End Sub

Thanks in Advance, Ryan


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Pass a variable to a different sub

You have a few answers on your previous post.

"RyanH" wrote:

I have a 2 command buttons on a userform. cmbCalculate and cmbAddToQuote.
cmbCalculate has code that confirms all textboxes have data before
calculating a price. cmbAddToQuote adds the price to a worksheet. How can I
pass a variable value from cmbCalculate code to cmbAddToQuote code. Here is
what I have for an example. I want to stop Sub cmbAddToQuote_Click() if the
variable StopCode = True. IS this possible?

Public Sub cmbCalculate_Click()

Dim StopCode as Boolean

If textbox1 = "" Then
MsgBox "Try Again."
StopCode = True
Exit Sub
End If
End Sub

Private Sub cmbAddToQuote_Click()

Call cmbCalculate_Click

If StopCode = True Then Exit Sub

'.....additional code
End Sub

Thanks in Advance, Ryan

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Pass a variable to a different sub

Ryan,

You can declare the variable StopCode at the module level (before and
outside of any Sub or Function procedure) so that its value is preserved and
it is accessible from any procedure within the module. Don't declare the
variable within a Sub or Function procedure.

See http://www.cpearson.com/Excel/Scope.aspx for a discussion of variable
and procedure "scope".


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



"RyanH" wrote in message
...
I have a 2 command buttons on a userform. cmbCalculate and cmbAddToQuote.
cmbCalculate has code that confirms all textboxes have data before
calculating a price. cmbAddToQuote adds the price to a worksheet. How
can I
pass a variable value from cmbCalculate code to cmbAddToQuote code. Here
is
what I have for an example. I want to stop Sub cmbAddToQuote_Click() if
the
variable StopCode = True. IS this possible?

Public Sub cmbCalculate_Click()

Dim StopCode as Boolean

If textbox1 = "" Then
MsgBox "Try Again."
StopCode = True
Exit Sub
End If
End Sub

Private Sub cmbAddToQuote_Click()

Call cmbCalculate_Click

If StopCode = True Then Exit Sub

'.....additional code
End Sub

Thanks in Advance, Ryan


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
Pass a Variable from one sub to another sub RyanH Excel Programming 4 March 14th 08 08:20 PM
Pass Variable to another Sub CSUS_CE_Student[_2_] Excel Programming 5 February 27th 08 01:24 AM
pass a variable to activate brzak Excel Programming 4 January 29th 08 02:49 PM
pass a variable to a public sub Joanne Excel Programming 4 August 11th 07 10:33 PM
Pass the variable into the sub function Richard Excel Programming 4 December 28th 06 10:58 AM


All times are GMT +1. The time now is 06:18 AM.

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"