Pass a Function Value thru several Subs

R

RyanH

I currently have a toolbar that has 4 Controls:

Control1 - Sorts Data
Control2 - Prints Data
Control3 - Copies Data to Other Worksheets
Control4 - Prints those Worksheets.

If Control1 is fired it will sort the data and use a MsgBox to ask the user
if they want to print. If Control2 is fired it will sort the data and bypass
the MsgBox, because the user has already demanded to print.

Sub Control1Macro(Optional ByVal StopCode As Boolean)

' sort data on data worksheet

' if StopCode = False ask to print, if print automatically
If StopCode = False Then
' ask if user wants to print
strPrompt = "The Ready Schedule has been produced, would you like to
print?"
intButtons = vbYesNo + vbQuestion
strTitle = "Ready Schedule"
If MsgBox(strPrompt, intButtons, strTitle) = vbYes Then
Application.Dialogs(xlDialogPrint).Show
End If
Else
Application.Dialogs(xlDialogPrint).Show
End If
End Sub

Public Sub PrintReadySchedule()
Call ReadySchedule(True)
End Sub

Control3 and Control4 relate a little differently. Here is my question.
How do I pass the StopCode Value from Control3 to Control4? This is the
procedure setup:

Sub Control3Macro(Optional ByVal StopCode As Boolean)
' Activate UserForm1 (Userform1 is a make shift progress bar)
End Sub

Sub Activate_Userform()
Call CompileSchedules
End Sub

Sub CompileSchedules()
' Copies Data to Other Worksheets
' makes updates to userform while compiling

If StopCode = False then
' Ask User to Print
Else
' print those worksheets
End If

End Sub

Sub Control4Macro()
Call Control3Macro(True)
End Sub


Thanks in Advance!!
 
P

paul.robinson

Hi
Make Stopcode a public Variable in one of two ways
1. If all your subs are in one code module then put this at the top of
the code module outside any sub. Do not declare it in any sub or its
value will be overwritten.
Dim StopCode as Boolean

2. If your subs are in different code modules then put this at the top
of the code module outside any sub. Do not declare it in any sub or
its value will be overwritten.
Public StopCode as Boolean

This variable will last as long as Excel is open. Note that any code
error will destroy the value of a public variable.
regards
Paul
 

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