Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing variable betwwen UserForm 1

Status
Not open for further replies.

andols

Programmer
Aug 30, 2005
12
SE
Hi,
 
Hi,

I press the wrong button as first, sorry for the blank post.

Now to my problem, I am trying to send a varible betwen two UserForum. I tried to do this by using a Class, se code
Code:
'Class
Option Explicit

Private mvarvalue As String
Public Property Let Edit(ByVal vData As String)
    mvarvalue = vData
End Property

Public Property Get Edit() As String
    Edit = mvarvalue
End Property
'*********************************

'Userform1
Private Sub cmdRedAnl_Click()
Dim pEdit As Edit
Set pEdit = New Edit
pEdit.Edit = "Red"
UserForm2.Show
End Sub
'****************************************

'UserForm2
Private Sub UserForm_Initialize()
Dim pEdit As Edit
Set pEdit = New Edit
MsgBox pEdit.Edit, vbDefaultButton1, "hej"
End Sub
'****************************************

But it seems like 'mvarvalue' does not keep its value.

If someone knows something about this or anyother way to passing variable to other UserForum, I would be thankfull.

Anders Olsson
 
Anders,

Assuming your class name is Edit as well as the property name (I would argue against doing this to avoid confusion), you appear to be instantiating this class twice; i.e. within each Userform. Each pEdit is invisible to the other Userform code. If you want to use this approach, pEdit should be declared as Public from a standard module and instantiated from there as well. The individual Userforms would then read and write this property as needed. Of course, you could just use a globally declared variable that each Userform would access.


Regards,
Mike
 
Mike,

I use your tips with the globally declared variable, thanx for that.

I guess I did something wrong the Class, I did not get it to work inside an UserForm either, I tried to declare the pEdit as Public in a Mudule but got a Error when trying to instatiet it there .

//Anders
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top