pass value to excel userform - is there a constructor? how to pass

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In my Excel app I have a button on a worksheet which opens a UserForm. I
need to pass a value to the userform. I was thinking the Initialize event of
the userform operated similar to a constructor. So I tried passing a value
as follows - which did not work:

frm1.Show "test1"

------------------------------------
Private Sub frm1_Initialize(s1 as string)
debug.print s1
End Sub

how to pass a value to the userform from the calling control?

Thanks,
Rich
 
With frm1
.Initialize "test1"
.Show
End With

Private Sub Initialize(s1 as string)
debug.print s1
End Sub


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
That sure would be nice but alas it is just not to be. You can not pass an
argument to a userfrom. Instead you need to store the value and have the
userform read the value when it initializes.
 
Well that is one way to get a value into a user form. Hadn't thought of doing
that. Very Nifty! One thing though... Doesn't your procedure need to be
public?
 
Thank you all for your replies. Yes, I was not able to pass an arg directly
to Initialize. But I did get the idea to use the keyword public. Then I
implemented

Public Property Let Init(s1 as String)
....
End Property


This did work.

frm1.Init = "test"
frm1.Show

This compiled and displayed the text "test" after opening frm1.

Thanks all for the replies.

Rich
 
Of course it does. Thanks for the heads up.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
That is the same principle as my suggestion. A form is just a specific
instance of a class, so you can do anything with it that you do with a
class.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top