Pass Variables into Form's code

  • Thread starter Thread starter Stuart
  • Start date Start date
S

Stuart

How do I pass a variable from a standard module into
the code behind a form, please?

Eg I would like to pass "Global_HideSameCols" which
is dimmed as Boolean, to the form
"GetUserWkbk_PrintOptions" and use it in the initialise
event:
Private Sub UserForm_Initialize
'Fill the ListBox
With GetUserWkbk_PrintOptions.ListBox1
If Global_HideSameCols = False Then
.RowSource = ""
etc

Regards.
 
Stuart,

Declare it as a public variable in the Declarations section of a normal code
module, and it will be available to the userform.
 
Hi Stuart,

There are several approaches. One is to define a property in the Form.
Something like:

Dim m_HideSameCols As Boolean

Public Property Set HideSameCols(byval a_bHideAs Boolean)
m_HideSameCols = a_bHide
End Property

Then from your caller you would use:

Load GetUserWkbk_PrintOptions
GetUserWkbk_PrintOptions.HideSameCols = Global_HideSameCols
GetUserWkbk_PrintOptions.Show

Alternatively if you define Global_HideSameCols in a code module as:

Global Global_HideSameCols As Boolean

it will also be visible in your form.

I would generally use the second method, because it involves less typing
(and also because your variable name says it global <g>), although the good
design mafia (who deprecate global variables) would no doubt advocate the
first.

HTH

Peter Beach
 
Peter used it as part of the name--not the variable itself. And Peter did it to
make sure the next person (him in 2 weeks?) recognizes that it's available to
all the modules.
 
Back
Top