ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Pass Variables into Form's code (https://www.excelbanter.com/excel-programming/275095-pass-variables-into-forms-code.html)

Stuart[_5_]

Pass Variables into Form's code
 
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.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.512 / Virus Database: 309 - Release Date: 19/08/2003



Bob Phillips[_5_]

Pass Variables into Form's code
 
Stuart,

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

--

HTH

Bob Phillips

"Stuart" wrote in message
...
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.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.512 / Virus Database: 309 - Release Date: 19/08/2003





Peter Beach

Pass Variables into Form's code
 
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

"Stuart" wrote in message
...
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.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.512 / Virus Database: 309 - Release Date: 19/08/2003





Dave Peterson[_3_]

Pass Variables into Form's code
 
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.



Stuart wrote:

Many thanks to you both.....Global statements then,
I think.

I thought a variable beginning 'Global...' might not be
considered advisable!

Regards.


--

Dave Peterson



All times are GMT +1. The time now is 02:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com