View Full Version : [SOLVED:] Pass Params on Activate event
ksilenio
11-19-2019, 02:41 PM
Hi everyone. How to pass some params in an activate event procedure? For example , in the Forms module i have this statement "Sub UserForm_Activate (param1,param2)" , now how can i call this procedure and pass the params from another module?
Thank you for your time.
Regards Kostas
paulked
11-19-2019, 11:38 PM
Code module
Option Explicit
Public txt1 As String, txt2 As String
Sub FrmLd()
txt1 = "Hello"
txt2 = "World"
UserForm1.Show
End Sub
Userform module
Option Explicit
Private Sub UserForm_Activate()
TextBox1 = txt1
TextBox2 = txt2
End Sub
You can't have arguments in Private Sub UserForm_Activate()
Why do you need 'arguments' in Private Sub UserForm_Activate() ?
I seldom use Private Sub UserForm_Activate().
Use Private Sub UserForm_Initialize() instead.
@Paulked
Avoid Public variables.
In the Userform module
Dim c00
Private Sub UserForm_Inirialize()
c00="snb's suggestion"
End Sub
Private Sub UserForm_Activate()
msgbox c00
Edn Sub
paulked
11-20-2019, 03:10 AM
I assumed he wanted to pass variables from his sub to the userform on showing it. But I agree to avoid public var's wherever possible. I could be done with Tag:
'Code module
Sub FrmLd()
UserForm1.Tag = "Hello World"
UserForm1.Show
End Sub
'Userform module
Private Sub UserForm_Activate()
Dim txt
txt = Split(Tag, " ")
TextBox1 = txt(0)
TextBox2 = txt(1)
End Sub
If you use one of the userform's properties I'd prefer:
Private Sub UserForm_Inirialize()
Tag="snb's suggestion"
End Sub
Private Sub UserForm_Activate()
msgbox Tag
Edn Sub
The proper Method is to use User Defined Form Properties.
UserForm Code
Option Explicit
Dim fParam1 As Something
Dim fParam2 as something
' It is customary to prefix these variables with "f" or "p" for Form or Property variables
' In Class modules, it is customary to prefix with "m", "c", or "p" for Class Module or Property Variable
' In Sheet Modules, use "s" or "p" as the prefix. Some coders like to add an underscore: "p_VarName".
' Whatever style you use, use it in all similar Property Variables
Property Let Param1(Var as Something)
fParam1 = Var
'Do something with fParam1
'Or call some sub
End Property
Property let Param2(var as something)
fParam2 = Var
Init_Me
End Property
Private Sub Init_Me()
If fParam1 <> "" And fPAram2 <> "" Then
'Do Something with fparam1 and fParam2
End Sub
Other module code
Load Userform1
' Triggers Sub UserForm_initialize
UserForm1.Param1 = something 'Form must be loaded so Property Lets are available
UserForm1.Param2 = Something
UserForm1.Show
' Triggers Sub UserForm_Activate
ksilenio
11-20-2019, 01:11 PM
OK thank you very much for your answer
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.