|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Using values from one useform in another userformI 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 gw.bosw***@gmail.com napisal(a):
> I have created a userform with textboxes for data entry. I also have a Hi Garry,> 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 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 gw.bosw***@gmail.com wrote:
> I have created a userform with textboxes for data entry. I also have a As long as the instance of the first form was declared as public, the> 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? 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. 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: Show quoteHide quote > gw.bosw***@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. |
|||||||||||||||||||||||