Using values from one useform in another userform

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gw.boswell@gmail.com

    #1

    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

  • sweet_dreams

    #2
    Re: Using values from one useform in another userform


    gw.boswell@gmai l.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(ByVa l sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load
    MessageBox.Show (MyText)
    End Sub

    form1 code:
    Private WithEvents f2 As New Form2

    Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
    System.EventArg s) 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:
    PGBET menghadirkan portal informasi APK, fitur, panduan akses, dan simulasi interaktif di browser dengan penjelasan jujur, jelas, aman, serta selalu mudah dipahami.

    PGBET menghadirkan portal informasi APK, fitur, panduan akses, dan simulasi interaktif di browser dengan penjelasan jujur, jelas, aman, serta selalu mudah dipahami.

    PGBET menghadirkan portal informasi APK, fitur, panduan akses, dan simulasi interaktif di browser dengan penjelasan jujur, jelas, aman, serta selalu mudah dipahami.


    Hope this hepls.

    Regards,
    sweet_dreams

    Comment

    • zacks@construction-imaging.com

      #3
      Re: Using values from one useform in another userform


      gw.boswell@gmai l.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.

      Comment

      • gw.boswell@gmail.com

        #4
        Re: Using values from one useform in another userform

        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
        zacks@construct ion-imaging.com wrote:
        gw.boswell@gmai l.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.

        Comment

        Working...