Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Apr 2015
    Posts
    153
    Thanks
    70
    Thanked 0 Times in 0 Posts

    Transfer value of combobox in userform1 to textbox in userform2

    Hi Experts,

    I continue to study VBA.

    I am learning how to code Forms.

    I have Form1 and Form2. I am working on populating a Textbox1 on userform2 with what appears in a combo box on userform1.

    I'm using following code. It works part way. When I click the command button to open form2 nothing show up in textbox1. However, when I click the red x to close the form it populates textbox1 with the data I want. Amazing.

    I am missing something and I hope you can help.

    Thank you in advance.


    Private Sub commandbutton6_Click()
    UserForm2.Show
    With UserForm2
    .Textbox1.Value = UserForm1.CBView.Value
    .Show
    End With
    End Sub

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    E.N.,

    Try this:

    UserForm1
    Code:
    Private Sub commandbutton6_Click()
    
       UserForm2.Show
    
    End Sub
    UserForm2
    Code:
    Private Sub Form_Activate()
    
      Me.Textbox1.Value = UserForm1.CBView.Value
    
    End Sub
    HTH
    Last edited by RetiredGeek; 2015-10-31 at 12:29.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. The Following User Says Thank You to RetiredGeek For This Useful Post:

    Excelnewbie (2015-11-02)

  4. #3
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,639
    Thanks
    115
    Thanked 650 Times in 592 Posts
    ...Or just comment out the one line in your code

    Code:
    Private Sub commandbutton6_Click()
     'UserForm2.Show
     With UserForm2
     .Textbox1.Value = UserForm1.CBView.Value
     .Show
     End With
     End Sub

  5. The Following User Says Thank You to Maudibe For This Useful Post:

    Excelnewbie (2015-11-02)

  6. #4
    2 Star Lounger
    Join Date
    Apr 2015
    Posts
    153
    Thanks
    70
    Thanked 0 Times in 0 Posts
    RG and Maud-

    Both approaches did the job. Thank you for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •