• Using one userform to fill in multiple textboxes in another userform

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Using one userform to fill in multiple textboxes in another userform

    Author
    Topic
    #508423

    :confused:

    Hello,

    I have a userfom with multiple textboxes that get filled in using another userfom that contains multiple dependent comboboxes. I’ve attached a sample that shows what i’m trying to achieve. the form called MainUserform has many textboxes, if you double click a textboxes, userfom called ToUseUserfom will show up, so user can make a selection and send back to the Main userfom.

    1. Is there a way to make the ToUseUserform send the selected value in combobox to the textbox that invoked it? in this case Textboxes 1 to 4.

    Thank you in advance.

    46961-Test1

    Viewing 0 reply threads
    Author
    Replies
    • #1593721

      This is simpler if you just have the one form and have a hidden frame containing the second form’s content. Then you unhide the frame instead of showing a second form.

      However, without changing to a single form you can pass values between the forms like this.
      In the MainForm amend the code to pass the name of the textbox to the ToUseForm

      Code:
      Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
        ToUseForm.Tag = "TextBox1"
        ToUseForm.Show
      End Sub

      Then in the ToUseForm, use the form tag to return a value

      Code:
      Private Sub ComboBox1_Change()
        Debug.Print Me.Tag
        Me.txttosend.Value = Me.ComboBox1.Value
        MainForm.Controls(Me.Tag).Value = Me.ComboBox1.Value
      End Sub
      • #1593722

        This is simpler if you just have the one form and have a hidden frame containing the second form’s content. Then you unhide the frame instead of showing a second form.

        However, without changing to a single form you can pass values between the forms like this.
        In the MainForm amend the code to pass the name of the textbox to the ToUseForm

        Code:
        Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
          ToUseForm.Tag = "TextBox1"
          ToUseForm.Show
        End Sub

        Then in the ToUseForm, use the form tag to return a value

        Code:
        Private Sub ComboBox1_Change()
          Debug.Print Me.Tag
          Me.txttosend.Value = Me.ComboBox1.Value
          MainForm.Controls(Me.Tag).Value = Me.ComboBox1.Value
        End Sub

        thank you sir. I really appreciate your help. I will try it and report back.

      • #1593742

        It works great. thanks again. i did change the ]Private Sub TextBox1_DblClick() to Private Sub TextBox1_Enter(). i noticed that using the double click made the mouse cursor loading (Shows a circle like doing operations still) after making a section in the comobox.

        The Enter() didn’t have this effect plus it’s faster to show up the ToUseUserform.

        Again, thank you so much for your time and help.

        Code:
        Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
          ToUseForm.Tag = “TextBox1”
          ToUseForm.Show
        End Sub
    Viewing 0 reply threads
    Reply To: Using one userform to fill in multiple textboxes in another userform

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: