Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
PJ PJ is offline
external usenet poster
 
Posts: 112
Default Display variable in userform

I would like to use custom userforms for various dialog boxes, error
trapping, etc. and wanted to know if it is possible to reference a string
variable on a userform. For example, say I have a variable called myVar in
my code and certain conditions are met where I want to display a userform. I
want to add a label with text on the userform and have it display the value
of myVar. Is there a way to do this?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default Display variable in userform

Make myVar public - ie don't declare it in a sub, but before the first sub
put the line

Public myVar as variant

Then in your userform code you can refer to it.

Sam


"PJ" wrote:

I would like to use custom userforms for various dialog boxes, error
trapping, etc. and wanted to know if it is possible to reference a string
variable on a userform. For example, say I have a variable called myVar in
my code and certain conditions are met where I want to display a userform. I
want to add a label with text on the userform and have it display the value
of myVar. Is there a way to do this?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Display variable in userform

To follow up on Sam's posting.... go into the VB editor and copy/paste
this...

"Understanding Scope and Visibility"

into the Search Box and then click on the item with the same name in the
list that appears... this will give you more details about what Sam has
suggested to you.

--
Rick (MVP - Excel)


"Sam Wilson" wrote in message
...
Make myVar public - ie don't declare it in a sub, but before the first sub
put the line

Public myVar as variant

Then in your userform code you can refer to it.

Sam


"PJ" wrote:

I would like to use custom userforms for various dialog boxes, error
trapping, etc. and wanted to know if it is possible to reference a string
variable on a userform. For example, say I have a variable called myVar
in
my code and certain conditions are met where I want to display a
userform. I
want to add a label with text on the userform and have it display the
value
of myVar. Is there a way to do this?


  #4   Report Post  
Posted to microsoft.public.excel.programming
PJ PJ is offline
external usenet poster
 
Posts: 112
Default Display variable in userform

Thanks for the help, but I'm still confused.

Say my conditions are met and I have created a "message string" in my code.
So when I have the code display the userform, how do I get the string to show
on the userform? If I add a label, can I set the value to the msgVar1? If
so, how? I was trying to set the caption of the label on the userform to the
variable, but didn't have any success. I'm not sure I'm going about this the
right way.

Thanks

"Rick Rothstein" wrote:

To follow up on Sam's posting.... go into the VB editor and copy/paste
this...

"Understanding Scope and Visibility"

into the Search Box and then click on the item with the same name in the
list that appears... this will give you more details about what Sam has
suggested to you.

--
Rick (MVP - Excel)


"Sam Wilson" wrote in message
...
Make myVar public - ie don't declare it in a sub, but before the first sub
put the line

Public myVar as variant

Then in your userform code you can refer to it.

Sam


"PJ" wrote:

I would like to use custom userforms for various dialog boxes, error
trapping, etc. and wanted to know if it is possible to reference a string
variable on a userform. For example, say I have a variable called myVar
in
my code and certain conditions are met where I want to display a
userform. I
want to add a label with text on the userform and have it display the
value
of myVar. Is there a way to do this?


.

  #5   Report Post  
Posted to microsoft.public.excel.programming
PJ PJ is offline
external usenet poster
 
Posts: 112
Default Display variable in userform

OK I think I figured it out.

I declared "msgString1" as a public variable and set it to this in my code:
msgString1 = "Some text here..." & vbNewLine _
& vbNewLine & "And some more text here " & myVar1 & " more stuff."

Then I added a label named "msgVar1" on the userform and set it like so.
Form1.msgVar1 = msgString1
Form1.Show

It seems to work but I was hoping someone could confirm this is an
acceptable way of doing it.

Thanks - PJ


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Display variable in userform

OK I think I figured it out.

I declared "msgString1" as a public variable and set it to this in my
code:
msgString1 = "Some text here..." & vbNewLine _
& vbNewLine & "And some more text here " & myVar1 & " more stuff."

Then I added a label named "msgVar1" on the userform and set it like so.
Form1.msgVar1 = msgString1
Form1.Show

It seems to work but I was hoping someone could confirm this is an
acceptable way of doing it.


It is fine to do it that way. Another way would be to put the assignment
statement in the UserForm's Initialize event procedure. Doing it that way,
would automatically make the assignment when the UserForm is initially shown
(that is, after the first time it is shown in a session or the next time it
is show after having been Unload'ed) and you would not have to remember to
set it each time your code Show's the UserForm.

--
Rick (MVP - Excel)

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
userform display tkraju via OfficeKB.com Excel Programming 0 May 7th 09 07:23 PM
How to feed a userform a variable to display in a textbox? Chet Excel Programming 2 February 1st 08 02:46 PM
Can't Display Userform WLMPilot Excel Programming 2 January 30th 08 10:32 PM
display userform Anthony Excel Discussion (Misc queries) 3 February 27th 07 04:02 PM
How to cause userform to display Jim[_31_] Excel Programming 4 November 28th 03 11:00 PM


All times are GMT +1. The time now is 01:32 AM.

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"