Passing variables between Sub and Userform

  • Thread starter Thread starter jose luis
  • Start date Start date
J

jose luis

Hi All,

I have a sub that assigns a true value to a Boolean Variable. That sub
fires a Userform that needs that boolean value to see if a condition
was met in the sub and then assign certain value to other variable.

I tryed to declare it (Public SwdeLista as Boolean) in Thisworkbook to
make it global (even that i read this is not adviceable, i couldn't
figure another way!), but doesn't work. The SwdeLista boolean variable
keeps "empty".

Could you direct me on how to pass a variable (boolean) from a sub to a
Userform?

Thanks in advance

Jose Luis
 
since the sub seems to be the caller of the form, the proper way may be
to make a special sub : this one will receive the boolean value and
decide the values of the form, and then shows the form.

An other way could be to mask (visible false) a check box but this box
could keep a boolean value from an other code.
 
Thank you Both,

I'll try that Dave, But that's going to be tomorow cause I'm tired and
sleepy.

Thanks again for your help.

See you around

Jose Luis
 
in the userform code, have this:

Option Explicit
Public SwdeLista As Boolean

in a code module have this:

Option Explicit
Sub ShowMyForm()
' load the form into memory
Load UserForm1
'adjust any values
UserForm1.SwdeLista = True
'show the form
UserForm1.Show
End Sub
 
In the UserForm1 forms module have this:

Public Sub Myshow (strVal1 as string, bVal2 as boolean)

' do your stuff
Me.show
End sub

In a global module somewhere

UserForm1.MyShow string1,bool2

DM Unseen

PS this can me amended with Property Get/Let/Set procedures and whatnot
 
Thank you both, for your advice. Now I ll code it.

Read you around

Thanks again

Jose Luis
 
Thank you both, for your advice. Now I ll code it.

Read you around

Thanks again

Jose Luis
 
Thank you both, for your advice. Now I ll code it.

Read you around

Thanks again

Jose Luis
 
Back
Top