By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,606 Members | 2,019 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,606 IT Pros & Developers. It's quick & easy.

Using values from one useform in another userform

P: n/a
I have created a userform with textboxes for data entry. I also have a
command button that calls a second useform. A user enters certain
information in the first useform but if he/she wants to do additional
calculations, they use the command button to bring up the second
userform and add additional information via textboxes in the second
form. However, the calculations need the data from both userforms.
Given that the variables are declared private and if they are changed
to public an error occurs, how can I make the variables entered in the
first userform available to the second userform?

TIA

Garry

Aug 15 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a

gw********@gmail.com napisal(a):
I have created a userform with textboxes for data entry. I also have a
command button that calls a second useform. A user enters certain
information in the first useform but if he/she wants to do additional
calculations, they use the command button to bring up the second
userform and add additional information via textboxes in the second
form. However, the calculations need the data from both userforms.
Given that the variables are declared private and if they are changed
to public an error occurs, how can I make the variables entered in the
first userform available to the second userform?

TIA

Garry
Hi Garry,

You have to add property on your second form like for example:

form2 code:
Dim _MyText As String

Public Property MyText() As String
Get
Return _MyText
End Get
Set(ByVal value As String)
_MyText = value
End Set
End Property

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
MessageBox.Show(MyText)
End Sub

form1 code:
Private WithEvents f2 As New Form2

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
f2.MyText = "hello"
f2.Show()
End Sub

when you create new instance of form2, you have to pass value to this
property.

Here you can find great articles about working with multiple forms:
http://www.devcity.net/Articles/94/multipleforms.aspx
http://www.devcity.net/Articles/100/multipleforms2.aspx
http://www.devcity.net/Articles/102/multipleforms3.aspx

Hope this hepls.

Regards,
sweet_dreams

Aug 15 '06 #2

P: n/a

gw********@gmail.com wrote:
I have created a userform with textboxes for data entry. I also have a
command button that calls a second useform. A user enters certain
information in the first useform but if he/she wants to do additional
calculations, they use the command button to bring up the second
userform and add additional information via textboxes in the second
form. However, the calculations need the data from both userforms.
Given that the variables are declared private and if they are changed
to public an error occurs, how can I make the variables entered in the
first userform available to the second userform?
As long as the instance of the first form was declared as public, the
second form should have access to all of the first form's textbox
controls and their text property.

Even if you take the advise of the other poster and store the values
entered in public properties in the first form, the still will be
available unless the instance of the first form's class is public.

Aug 15 '06 #3

P: n/a
Thanks everyone for the help. The suggestion about passing variables
would probably work. I had tried declaring the variables public but
that didn't seem to work. I did find the problem however. It seems
that I use a click event with the text boxes in the first userform.
When I changed the event to a change event and had the variables
declared public in the module Declaration area, things worked fine.
Since I previously had only one form and use a click event to initiate
the calculations, it worked fine. But when calling the second form
there wasn't a final click event to load the variables from the
textboxes. Just a beginners mistake. :-)
Thanks again,
Garry
za***@construction-imaging.com wrote:
gw********@gmail.com wrote:
I have created a userform with textboxes for data entry. I also have a
command button that calls a second useform. A user enters certain
information in the first useform but if he/she wants to do additional
calculations, they use the command button to bring up the second
userform and add additional information via textboxes in the second
form. However, the calculations need the data from both userforms.
Given that the variables are declared private and if they are changed
to public an error occurs, how can I make the variables entered in the
first userform available to the second userform?

As long as the instance of the first form was declared as public, the
second form should have access to all of the first form's textbox
controls and their text property.

Even if you take the advise of the other poster and store the values
entered in public properties in the first form, the still will be
available unless the instance of the first form's class is public.
Aug 16 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.