Passing In Arguments

It is possible to pass information to a userform however you cannot use the Userform_Initalise event.
The Userform_Initailize event does not allow arguments to be passed to it.
There are a number of different ways you can work around this


Creating a Userform Property

Creating a userform property is the best approach because it means that your code is self-contained (encapsulation principles)


Public DisplayUserForm() 
Dim oMyForm As UserForm1
   Set oMyForm = New UserForm1
   oMyForm.Property_CaptionTitle = "some text"
   oMyForm.Show
End Sub

Private m_sCaptionTitle As String
Property Let Property_CaptionTitle(ByVal sValue As String)
   m_sCaptionTitle = sValue
End Property

Alternatives

Global variable
Using Tag property



© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext