Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 298
Default pass value to excel userform - is there a constructor? how to pass

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default pass value to excel userform - is there a constructor? how to pass

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)

"Rich" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default pass value to excel userform - is there a constructor? how to

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?

--
HTH...

Jim Thomlinson


"Bob Phillips" wrote:

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)

"Rich" wrote in message
...
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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default pass value to excel userform - is there a constructor? how to

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)

"Jim Thomlinson" wrote in message
...
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?

--
HTH...

Jim Thomlinson


"Bob Phillips" wrote:

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)

"Rich" wrote in message
...
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






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default pass value to excel userform - is there a constructor? how to pass

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.
--
HTH...

Jim Thomlinson


"Rich" wrote:

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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 298
Default pass value to excel userform - is there a constructor? how to pass

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

"Rich" wrote:

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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default pass value to excel userform - is there a constructor? how to pass

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)

"Rich" wrote in message
...
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

"Rich" wrote:

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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass data from UserForm to spreadsheet susan Excel Programming 1 September 2nd 06 09:36 PM
Pass variable from module to userform and back [email protected] Excel Programming 0 July 20th 06 04:46 PM
Pass public variable from one userform to a second... Mike Dunworth Excel Programming 2 September 4th 05 12:30 AM
can a userform pass an argument? smokiibear Excel Programming 12 December 8th 04 02:14 AM
How to pass arguments from ThisWorkbook to a UserForm strataguru[_4_] Excel Programming 1 October 7th 03 11:29 PM


All times are GMT +1. The time now is 04:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"