473,385 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Using values from one useform in another userform

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
3 4934

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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andy | last post by:
Hi! Is possible to do xml validation of one xml block based on values from another xml block? For example, I have an input xml file containing account types. <Root> <AccountTypes>...
1
by: Jimmy | last post by:
I have a table that is shown below in ORIGINAL TABLE. It is common for the VEHICLE # field to have repeating vehicles (ID 3,4,5 & 8,9). Usually the Vehicle will have SHIPDATE, DATE_RECEIVED, and...
1
by: ILCSP | last post by:
Hello, I'm trying to accomplish 3 things with one stored procedure. I'm trying to search for a record in table X, use the outcome of that search to insert another record in table Y and then exec...
6
by: psbasha | last post by:
Hi, I am assigning the list/dict values to another list/dict variable as shown below. List : List1 = List2 = List1
0
by: menyki | last post by:
Below is a little code i wrote to display values on another form called recordForm. The code is writen on a form called regForm.pls can somebody help tell me what to do cos is not running. ...
1
by: zoeb | last post by:
Currently I have a table, and would like the calculate a field in the table by referencing values from another 3 tables. i.e. tblData Index1, Index2, Index3, Value 1 2 3 2...
5
by: mruedy | last post by:
I would like to know if it is possible to write an XML Schema restriction that binds to values of another element. For example I have XML <people> <family name="Smith"> ...
7
by: Andy Sears | last post by:
I am trying to SUM values in a column where values in another column are the same. Here is what I need, but I know the 5th line won't work: UPDATE manufacturing_detail SET item_lead_time_1 = ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.