Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Using Public to Pass Variable

I have a UserForm that captures the users name, I am trying to pass that
information to another UserForm. I'm assuming that is possible using the
Public declarations, but I am obviously having problems. Here is my example
code

Public Name As String
________________________________
Private Sub OKButton_Click()
Name = NameBox1

UserForm4.Hide
End Sub
________________________________

'Name gets passed to this UserForm

________________________________
Private Sub SignOffButton_Click()
MsgBox Name

Unload UserForm5
End Sub
________________________________

Do I need to declare the variables Public in UserForm5 also? Are they
declared in the right place? Should the subs be name Public instead of
Private? etc. My MsgBox is returning empty. Any help is greatly
appreciated.

DP

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Using Public to Pass Variable

First of all, I would avoid using "Name" as the variable name, as
this is a property name of many objects; using "Name" will cause
confusion. Don't declare the Public variable in the userform's
module. Declare it in a regular code module instead.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"D.Parker" wrote in message
...
I have a UserForm that captures the users name, I am trying to
pass that
information to another UserForm. I'm assuming that is possible
using the
Public declarations, but I am obviously having problems. Here
is my example
code

Public Name As String
________________________________
Private Sub OKButton_Click()
Name = NameBox1

UserForm4.Hide
End Sub
________________________________

'Name gets passed to this UserForm

________________________________
Private Sub SignOffButton_Click()
MsgBox Name

Unload UserForm5
End Sub
________________________________

Do I need to declare the variables Public in UserForm5 also?
Are they
declared in the right place? Should the subs be name Public
instead of
Private? etc. My MsgBox is returning empty. Any help is
greatly
appreciated.

DP



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Using Public to Pass Variable

Give this a try...

msgbox userform4.Name

Depending where all you have declared a variable called Name you may need to
be more explicit in your reference to Name.

One thing I do if I am going to be requiring Global Variables is to declare
a module strictly for the purpose of storing them. I can then just refer to
them by referencing that module. Keeps things a little straighter if they are
all in one place...

HTH

"D.Parker" wrote:

I have a UserForm that captures the users name, I am trying to pass that
information to another UserForm. I'm assuming that is possible using the
Public declarations, but I am obviously having problems. Here is my example
code

Public Name As String
________________________________
Private Sub OKButton_Click()
Name = NameBox1

UserForm4.Hide
End Sub
________________________________

'Name gets passed to this UserForm

________________________________
Private Sub SignOffButton_Click()
MsgBox Name

Unload UserForm5
End Sub
________________________________

Do I need to declare the variables Public in UserForm5 also? Are they
declared in the right place? Should the subs be name Public instead of
Private? etc. My MsgBox is returning empty. Any help is greatly
appreciated.

DP

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Using Public to Pass Variable

I have renamed my variable from Name to XName, for the sake of example.

My Module call my UserForms, so would I place the Public declarations at the
first line of the module? I not clear on the placement of the Public XName
as String declaration?
Thank you.

DP

"Jim Thomlinson" wrote:

Give this a try...

msgbox userform4.Name

Depending where all you have declared a variable called Name you may need to
be more explicit in your reference to Name.

One thing I do if I am going to be requiring Global Variables is to declare
a module strictly for the purpose of storing them. I can then just refer to
them by referencing that module. Keeps things a little straighter if they are
all in one place...

HTH

"D.Parker" wrote:

I have a UserForm that captures the users name, I am trying to pass that
information to another UserForm. I'm assuming that is possible using the
Public declarations, but I am obviously having problems. Here is my example
code

Public Name As String
________________________________
Private Sub OKButton_Click()
Name = NameBox1

UserForm4.Hide
End Sub
________________________________

'Name gets passed to this UserForm

________________________________
Private Sub SignOffButton_Click()
MsgBox Name

Unload UserForm5
End Sub
________________________________

Do I need to declare the variables Public in UserForm5 also? Are they
declared in the right place? Should the subs be name Public instead of
Private? etc. My MsgBox is returning empty. Any help is greatly
appreciated.

DP

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Using Public to Pass Variable

To keep my naming straight I do the following:

In the visual basic editor right click on any of the modules, sheets or
forms in the projects window. Select insert module. If the properties window
is not visible select view -properties window. The first item in the
properties window for your new module will be name. It will say something
like module1. Change that to modGlobal. Now within that module add the line

public g_mStrName as string

This is the naming convention I use. g stands for global. m stands for
module. Str stands for string. Now when I am using the variable I know
exactly where it came from and what kind of variable it is.

In your form you can get a list of all of your global variables by typing
"modGlobal." and you will get a listing of all the public variables in the
module. so your line of code will look like...

msgbox modGlobal.g_mStrName

or if you want you can just enter it as

msgbox g_mStrName

HTH

"D.Parker" wrote:

I have renamed my variable from Name to XName, for the sake of example.

My Module call my UserForms, so would I place the Public declarations at the
first line of the module? I not clear on the placement of the Public XName
as String declaration?
Thank you.

DP

"Jim Thomlinson" wrote:

Give this a try...

msgbox userform4.Name

Depending where all you have declared a variable called Name you may need to
be more explicit in your reference to Name.

One thing I do if I am going to be requiring Global Variables is to declare
a module strictly for the purpose of storing them. I can then just refer to
them by referencing that module. Keeps things a little straighter if they are
all in one place...

HTH

"D.Parker" wrote:

I have a UserForm that captures the users name, I am trying to pass that
information to another UserForm. I'm assuming that is possible using the
Public declarations, but I am obviously having problems. Here is my example
code

Public Name As String
________________________________
Private Sub OKButton_Click()
Name = NameBox1

UserForm4.Hide
End Sub
________________________________

'Name gets passed to this UserForm

________________________________
Private Sub SignOffButton_Click()
MsgBox Name

Unload UserForm5
End Sub
________________________________

Do I need to declare the variables Public in UserForm5 also? Are they
declared in the right place? Should the subs be name Public instead of
Private? etc. My MsgBox is returning empty. Any help is greatly
appreciated.

DP



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Using Public to Pass Variable

I have declared the declarations in a regular code module (i.e. Module2) and
have taken them out of the UserForm, and unfortunately my message Boxes are
still empty. Am I declaring the variable wrong?

Public Sub VariableDeclarations()

Public XName As String

End Sub

If someone could provide the exact code it would be appreciated. I am very
new to the VBA Excel world. Thanks again.

D.Parker
_________________________________
"Chip Pearson" wrote:

First of all, I would avoid using "Name" as the variable name, as
this is a property name of many objects; using "Name" will cause
confusion. Don't declare the Public variable in the userform's
module. Declare it in a regular code module instead.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"D.Parker" wrote in message
...
I have a UserForm that captures the users name, I am trying to
pass that
information to another UserForm. I'm assuming that is possible
using the
Public declarations, but I am obviously having problems. Here
is my example
code

Public Name As String
________________________________
Private Sub OKButton_Click()
Name = NameBox1

UserForm4.Hide
End Sub
________________________________

'Name gets passed to this UserForm

________________________________
Private Sub SignOffButton_Click()
MsgBox Name

Unload UserForm5
End Sub
________________________________

Do I need to declare the variables Public in UserForm5 also?
Are they
declared in the right place? Should the subs be name Public
instead of
Private? etc. My MsgBox is returning empty. Any help is
greatly
appreciated.

DP




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Using Public to Pass Variable

In a general/standard code module

Public xName As String

Userform4.Module
________________________________
Private Sub OKButton_Click()
xName = NameBox1

UserForm4.Hide
End Sub
________________________________

Userform5 module
________________________________
Private Sub SignOffButton_Click()
MsgBox xName

Unload UserForm5
End Sub
________________________________



--

HTH

RP
(remove nothere from the email address if mailing direct)


"D.Parker" wrote in message
...
I have renamed my variable from Name to XName, for the sake of example.

My Module call my UserForms, so would I place the Public declarations at

the
first line of the module? I not clear on the placement of the Public

XName
as String declaration?
Thank you.

DP

"Jim Thomlinson" wrote:

Give this a try...

msgbox userform4.Name

Depending where all you have declared a variable called Name you may

need to
be more explicit in your reference to Name.

One thing I do if I am going to be requiring Global Variables is to

declare
a module strictly for the purpose of storing them. I can then just refer

to
them by referencing that module. Keeps things a little straighter if

they are
all in one place...

HTH

"D.Parker" wrote:

I have a UserForm that captures the users name, I am trying to pass

that
information to another UserForm. I'm assuming that is possible using

the
Public declarations, but I am obviously having problems. Here is my

example
code

Public Name As String
________________________________
Private Sub OKButton_Click()
Name = NameBox1

UserForm4.Hide
End Sub
________________________________

'Name gets passed to this UserForm

________________________________
Private Sub SignOffButton_Click()
MsgBox Name

Unload UserForm5
End Sub
________________________________

Do I need to declare the variables Public in UserForm5 also? Are they
declared in the right place? Should the subs be name Public instead

of
Private? etc. My MsgBox is returning empty. Any help is greatly
appreciated.

DP



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Using Public to Pass Variable

Take the declaration our of the sub. It should stand alone at teh top of the
module...

HTH

"D.Parker" wrote:

I have declared the declarations in a regular code module (i.e. Module2) and
have taken them out of the UserForm, and unfortunately my message Boxes are
still empty. Am I declaring the variable wrong?

Public Sub VariableDeclarations()

Public XName As String

End Sub

If someone could provide the exact code it would be appreciated. I am very
new to the VBA Excel world. Thanks again.

D.Parker
_________________________________
"Chip Pearson" wrote:

First of all, I would avoid using "Name" as the variable name, as
this is a property name of many objects; using "Name" will cause
confusion. Don't declare the Public variable in the userform's
module. Declare it in a regular code module instead.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"D.Parker" wrote in message
...
I have a UserForm that captures the users name, I am trying to
pass that
information to another UserForm. I'm assuming that is possible
using the
Public declarations, but I am obviously having problems. Here
is my example
code

Public Name As String
________________________________
Private Sub OKButton_Click()
Name = NameBox1

UserForm4.Hide
End Sub
________________________________

'Name gets passed to this UserForm

________________________________
Private Sub SignOffButton_Click()
MsgBox Name

Unload UserForm5
End Sub
________________________________

Do I need to declare the variables Public in UserForm5 also?
Are they
declared in the right place? Should the subs be name Public
instead of
Private? etc. My MsgBox is returning empty. Any help is
greatly
appreciated.

DP




  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Using Public to Pass Variable

Chip/Jim:

Thank you for the direction. After a few iterations and trial and error, it
works now! Thanks again.

D. Parker

"Chip Pearson" wrote:

First of all, I would avoid using "Name" as the variable name, as
this is a property name of many objects; using "Name" will cause
confusion. Don't declare the Public variable in the userform's
module. Declare it in a regular code module instead.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"D.Parker" wrote in message
...
I have a UserForm that captures the users name, I am trying to
pass that
information to another UserForm. I'm assuming that is possible
using the
Public declarations, but I am obviously having problems. Here
is my example
code

Public Name As String
________________________________
Private Sub OKButton_Click()
Name = NameBox1

UserForm4.Hide
End Sub
________________________________

'Name gets passed to this UserForm

________________________________
Private Sub SignOffButton_Click()
MsgBox Name

Unload UserForm5
End Sub
________________________________

Do I need to declare the variables Public in UserForm5 also?
Are they
declared in the right place? Should the subs be name Public
instead of
Private? etc. My MsgBox is returning empty. Any help is
greatly
appreciated.

DP




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
Public variable Jack New Users to Excel 4 March 18th 06 09:35 PM
Public variable usage! pikus Excel Programming 0 April 13th 04 09:28 PM
Public Variable Jason Excel Programming 4 April 12th 04 07:06 PM
Public/Procedure Variable Otto Moehrbach[_6_] Excel Programming 2 February 6th 04 04:58 PM
public variable marwan hefnawy Excel Programming 1 September 5th 03 08:54 AM


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

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

About Us

"It's about Microsoft Excel"