ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Variables- Multiple forms (https://www.excelbanter.com/excel-programming/332839-variables-multiple-forms.html)

andywalker[_4_]

Variables- Multiple forms
 

Hi,

I have two forms And i want to be able to pass variables from one for
to another. for example in form 1:

CurrentUser = TxtUser.value

then in form 2 i want to be able to use this variable eg

LblUser.Caption = CurrentUser

Where do i declare this variable in Vba and how?

I have tried a global variable in a standard module but this didn
work.

any help would be appreciated

thank

--
andywalke
-----------------------------------------------------------------------
andywalker's Profile: http://www.excelforum.com/member.php...fo&userid=2441
View this thread: http://www.excelforum.com/showthread.php?threadid=38222


anilsolipuram[_110_]

Variables- Multiple forms
 

If form1 variable as to be passed to form2 , in the form1 you have
define the function which will return the variable from form1 and from
form2 you have to call that defined function



in form1 the code is

Dim str As Variant
Private Sub UserForm_Initialize()
str = "testmne"
End Sub
Function f11()
f11 = str
End Function

in form2 the code is

Private Sub UserForm_Initialize()
MsgBox UserForm2.f11
End Sub


--
anilsolipuram
------------------------------------------------------------------------
anilsolipuram's Profile: http://www.excelforum.com/member.php...o&userid=16271
View this thread: http://www.excelforum.com/showthread...hreadid=382222


Henry[_5_]

Variables- Multiple forms
 
Andy,

Why not put the value in an unused cell on one of your sheets.

I usually have a hidden sheet called "system" where I store non-volatile
variables.

Sheets("system").Range("A1").Value = TxtUser.Value

LblUser.Caption = Sheets("system").Range("A1").Value

If you don't want to save this value when you close the workbook

Sheets("system").Range("A1").Value = ""
Application.Quit

You could also name the range *Sheets("system").Range("A1")* as CurrentUser
so
CurrentUser.Value = TxtUser.Value
Etc.

HTH
Henry



"andywalker" wrote
in message ...

Hi,

I have two forms And i want to be able to pass variables from one form
to another. for example in form 1:

CurrentUser = TxtUser.value

then in form 2 i want to be able to use this variable eg

LblUser.Caption = CurrentUser

Where do i declare this variable in Vba and how?

I have tried a global variable in a standard module but this didnt
work.

any help would be appreciated

thanks


--
andywalker
------------------------------------------------------------------------
andywalker's Profile:
http://www.excelforum.com/member.php...o&userid=24418
View this thread: http://www.excelforum.com/showthread...hreadid=382222




Tim Zych[_10_]

Variables- Multiple forms
 
The global in the module does work.

But here's a more explicit approach.

In the callee userform:

----------------------------------
Private mstrUserName As String

Property Let UserName(ByVal strUserName As String)
mstrUserName = strUserName
End Property

Private Sub CommandButton1_Click()
MsgBox mstrUserName
End Sub
---------------------------------

and in the caller userform

Load UserForm1
With UserForm1
.UserName = "Tim Zych"
.Show
End With


"andywalker" wrote
in message ...

Hi,

I have two forms And i want to be able to pass variables from one form
to another. for example in form 1:

CurrentUser = TxtUser.value

then in form 2 i want to be able to use this variable eg

LblUser.Caption = CurrentUser

Where do i declare this variable in Vba and how?

I have tried a global variable in a standard module but this didnt
work.

any help would be appreciated

thanks


--
andywalker
------------------------------------------------------------------------
andywalker's Profile:

http://www.excelforum.com/member.php...o&userid=24418
View this thread: http://www.excelforum.com/showthread...hreadid=382222





All times are GMT +1. The time now is 05:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com