I have always been under the understanding that in VBA we are unable to pass variables to a userform upon its creation/initialization. However, I had placed an opening parenthesis after the object name and a tooltip came up suggesting that this may not necessarily be true (or more likely I am simply just misinterpreting it):
So out of curiosity I attempted to see if I could pass a variable to the userform using varg
:
but to no surprise it didn't work.
So ultimately the question is what is the purpose of varg
? To me it actually looks like it would be used for indexing multiple separate instances of the userform since it actually appears to be an argument for the property .Item()
and not for the actual object itself, but the only way I've ever known to create multiple userform objects is by setting them to a variable, such as:
Dim uf1 As MyUserForm, uf2 as MyUserform
Set uf1 = New MyUserform
set uf2 = New Myuserform
Can userforms actually be serialized and indexed a different way that would make use of this varg
variable?
Note: This is not a question about how to pass external variables to a Userform - I am aware of numerous ways to accomplish this after its initialization (by passing via a Public Property, Function, or Variable within the object's code module or even less preferably an external global/public variable in a standard module).
CodePudding user response:
UserForm
has a default property Controls
. It returns an instance of Controls
class.
The Controls
class, in turn, has a default property Item(varg) As Object
.
So With New udfVendorDrillDown(varg)
is the same as With New udfVendorDrillDown.Controls.Item(varg)
, which is probably not what you hoped it was.
You still cannot pass arguments to UserForms constructors. Or any class constructors in fact.