modifying the Userform_Initialize event handler

  • Thread starter Thread starter thomas donino
  • Start date Start date
T

thomas donino

Can this sub be modified to take a parameter?
ie, UserForm_Initialize(byVal iModetoInit as Long)

This way I can set 2,3,4 or whatever many different initialization modes I
might require by passing it a parameter depending on how I want the form
initialized
 
No you can't. If you change the syntax then it won't run when the form loads.
(you could have just tried it and got your answer)

You can assign a value to the UserForm.Tag and then access that value in the UserForm_Activate event
or after the form is displayed...
'--
'Standard module
Sub abcd()
UserForm1.Tag = "2"
UserForm1.Show
End Sub
'--
'Form module
Private Sub UserForm_Activate()
If Me.Tag = CStr(2) Then
'do something
End If
End Sub
--
Jim Cone
Portland, Oregon USA
(free xl add-in to remove excess styles or cond. formatting...
http://excelusergroup.org/media/p/4861.aspx )




"thomas donino" <[email protected]>
wrote in message Can this sub be modified to take a parameter?
ie, UserForm_Initialize(byVal iModetoInit as Long)

This way I can set 2,3,4 or whatever many different initialization modes I
might require by passing it a parameter depending on how I want the form
initialized
 
No, but just before .Show in your normal code you could either set a Public
variable to such a value and examine that variable's value to decide what to
do during initialization. By creating the Public variable, you make it
visible to the form as well as any other code in the project.

Another way, not quite as neat, would be to write the value to a cell on a
worksheet and have the initialization routine retrieve the value, examine it,
and take action based on its value. I like the previous way better.
 
Back
Top