Excel VBA: Pass value when clicking button

  • Thread starter Thread starter Milli
  • Start date Start date
M

Milli

I have a problem with a Procedure Declaration to capture a value in
variable when clicking a button in a Dialog Box. I’m pretty fluent i
VBA as such but I’ve hardly ever worked with Dialog Boxes.
I’m trying to pass the value of blnSwitch when clicking Commandbutton_
to Sub Status() and further to BaseRoutine().
Does anybody have a solution?

Milli

Sub BaseRoutine()
----
Call Status(blnSwitch)

Select Case blnSwitch

Case = ”1”

Do something 1

Case = ”2”

Do something 2

End Select

End Sub

Sub Status(blnSwitch as Boolean)
----
Call ShowForm(I guess this is where blnSwitch should be passed)

End Sub

Sub ShowForm()

MissingAnswersForm.Show

End Sub

Private Sub MissingAnswersForm_Initialize(vntReturnCriteria A
Variant)

Call BaseRoutine

End Sub

Private Sub CommandButton1_Click()

Unload Me
blnSwitch = ”1”

End Sub

Private Sub CommandButton2_Click()

Unload Me

End Su
 
Make blnSwitch a public variable at the top of a general module. (remove
anywhere else it might be declared)

Then it will be visible to all the modules in the project.
 
That works perfect. Thanks.

Are there alternative routes?

Regards
Milli
 
You could declare blnSwitch as a public variable in the Userform module then

Userform1.Load ' not required - as soon as you reference it
' if it doesn't exist, it is loaded.
userform1.blnSwitch = True
Userform1.Show
 

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

Back
Top