Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / September 2007

Tip: Looking for answers? Try searching our database.

UserForms - how to return a value?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marcus Schöneborn - 24 Sep 2007 06:40 GMT
I've seen that one usually runs Me.Hide inside the OK_Click or
Cancel_Click method, but is it somehow possible to specify a return
value the Show method will return, like MsgBox does for example? Also,
is it possible to specify arguments to UserForm.Show so that the form
knows how to initialize itself, without having to make an extra code
module that's just there to show the dialog?

Or is it perhaps possible to have a public "static" function inside a
Dialog module that one can call at any time and that does the creation
of the dialog? I didn't succeed when I tried to define a function there
and call it from outside.
Bob Phillips - 24 Sep 2007 09:02 GMT
The standard way is to have a public property in the form and test that
afterwards

Dim myForm As UserForm1

   If myForm Is Nothing Then Set myForm = New UserForm1
   myForm.Show
   MsgBox myForm.myProp
   Set myForm = Nothing

In the form have a public variable

Public myProp as Boolean

and set it in the form code.

Signature

HTH

Bob

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

> I've seen that one usually runs Me.Hide inside the OK_Click or
> Cancel_Click method, but is it somehow possible to specify a return
[quoted text clipped - 7 lines]
> of the dialog? I didn't succeed when I tried to define a function there
> and call it from outside.
Marcus Schöneborn - 24 Sep 2007 09:12 GMT
> The standard way is to have a public property in the form and test that
> afterwards
[quoted text clipped - 11 lines]
>
> and set it in the form code.

That's what I am doing at the moment. I hoped there was another way to
do that... Well, then it's fine. Thanks.
Jon Peltier - 24 Sep 2007 12:46 GMT
You could set up properties, which I use to pass information into and out of
the form:

http://peltiertech.com/Excel/PropertyProcedures.html

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______

>> The standard way is to have a public property in the form and test that
>> afterwards
[quoted text clipped - 14 lines]
> That's what I am doing at the moment. I hoped there was another way to
> do that... Well, then it's fine. Thanks.
Bob Phillips - 24 Sep 2007 12:58 GMT
Uhh, isn't that what I said 2 hours 44 minutes earlier, and the OP said was
what he was doing?

Signature

HTH

Bob

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

> You could set up properties, which I use to pass information into and out
> of the form:
[quoted text clipped - 26 lines]
>> That's what I am doing at the moment. I hoped there was another way to
>> do that... Well, then it's fine. Thanks.
Jon Peltier - 24 Sep 2007 23:44 GMT
Bob -

You said public property, but I thought you demonstrated a public variable.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______

> Uhh, isn't that what I said 2 hours 44 minutes earlier, and the OP said
> was what he was doing?
[quoted text clipped - 29 lines]
>>> That's what I am doing at the moment. I hoped there was another way to
>>> do that... Well, then it's fine. Thanks.
Bob Phillips - 25 Sep 2007 00:51 GMT
In a class, a public variable is a read/write property.

Signature

HTH

Bob

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

> Bob -
>
[quoted text clipped - 42 lines]
>>>> That's what I am doing at the moment. I hoped there was another way to
>>>> do that... Well, then it's fine. Thanks.
Jon Peltier - 25 Sep 2007 02:49 GMT
Yes, in that sense it is a property. I was thinking more in the sense of the
property Let/Set/Get procedures, which I use a lot because they let you do
more than pass a value. You can use a procedure to set up the display on the
userform, maybe set values for multiple procedures, drive other events.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______

> In a class, a public variable is a read/write property.
>
[quoted text clipped - 44 lines]
>>>>> That's what I am doing at the moment. I hoped there was another way to
>>>>> do that... Well, then it's fine. Thanks.
Bob Phillips - 25 Sep 2007 08:59 GMT
I agree that Get/Let/Set gives you the capability to process the property a
great deal more. I too use them, almost exclusively, but for what the OP
wanted here, a simple read/.write property was sufficient, and let's be
honest, it is never much work to convert them over later if need be.

Signature

HTH

Bob

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

> Yes, in that sense it is a property. I was thinking more in the sense of
> the property Let/Set/Get procedures, which I use a lot because they let
[quoted text clipped - 58 lines]
>>>>>> to
>>>>>> do that... Well, then it's fine. Thanks.
Jon Peltier - 25 Sep 2007 21:25 GMT
Yeah, I guess we're both right. You can't beat the ease of converting, when
MZ Tools has a command to do just that.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______

>I agree that Get/Let/Set gives you the capability to process the property a
>great deal more. I too use them, almost exclusively, but for what the OP
[quoted text clipped - 63 lines]
>>>>>>> to
>>>>>>> do that... Well, then it's fine. Thanks.
Bob Phillips - 27 Sep 2007 10:19 GMT
Amen to that, indispensable.

Signature

HTH

Bob

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

> Yeah, I guess we're both right. You can't beat the ease of converting,
> when MZ Tools has a command to do just that.
[quoted text clipped - 73 lines]
>>>>>>>> to
>>>>>>>> do that... Well, then it's fine. Thanks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.