Variable in Textbox Event

helivw

New Member
Joined
Oct 6, 2018
Messages
25
I make a selection in a Userform.Listbox with data coming form the Textbox in a Userform
Can I pass a variable to the Textbox Sub ..._Change event
ie. Sub TextBx_Change(ByRef ....)
I don't want to use a Public variable
Thanks
 

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
7,412
Office Version
2016
Platform
Windows
I make a selection in a Userform.Listbox with data coming form the Textbox in a Userform
Can I pass a variable to the Textbox Sub ..._Change event
ie. Sub TextBx_Change(ByRef ....)
I don't want to use a Public variable
Thanks
Can you use the TextBox Tag Property to store the data ?
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
22,688
What is the data type of the array?
A delimited string and an array are pretty much the same information.
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
22,688
That would be a long delimited string. A module wide variable would be the easiest way to pass it. What is your concern about using a public variable?
 

helivw

New Member
Joined
Oct 6, 2018
Messages
25
That would be a long delimited string. A module wide variable would be the easiest way to pass it. What is your concern about using a public variable?
Because I read everywhere, you have to avoid using public variables and I use a lot of userforms (very handy) and each time I'm fighting of finding a easy way to transfer variables between my subroutine and parts (listbox, textbox, ...) of the userform and vv
 

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
7,412
Office Version
2016
Platform
Windows
Can't you use module level variables instead of Public global variables - Each variable declared at the top of each userform module so you can use them throughout the entire userform lifetime and scope.
 
Last edited:

helivw

New Member
Joined
Oct 6, 2018
Messages
25
Can't you use module level variables instead of Public global variables - Each variable declared at the top of each userform module so you can use them throughout the entire userform lifetime and scope.
Thanks a lot Jaafar.
I really never thought that way, shame on me.

And what would be te best way to transfer my array to a userform Sub i.e. the userform initialize or whathever before my command
Userform.Show
 

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
7,412
Office Version
2016
Platform
Windows
The userform Initialize event fires before showing the userform so that's a good place to populate the array.
 

Forum statistics

Threads
1,077,849
Messages
5,336,736
Members
399,100
Latest member
darcob

Some videos you may like

This Week's Hot Topics

Top