Consulting

Results 1 to 4 of 4

Thread: Populate TextBox based combobox value

  1. #1
    VBAX Newbie
    Joined
    May 2014
    Posts
    2
    Location

    Populate TextBox based combobox value

    I would like to populate TextBox ex. "Rectangle1" based on what is selected in "Combobox1"


    I have separate Userform where the Combobox and TextBox is.


    Private Sub Combobox1_DropButtonClick()
    Dim sh As Shape
    Set sh = ActivePresentation.Slides(1).Shapes("Rectangle1")
    sh.Name = "Rectangle1"
    If Combobox.Listcount = 0 Then
    With Combobox1 
    .AddItem " ", 0
    .Additem "Test", 1
    .Additem "Test2", 2
    End With
    End If
    End Sub
    
    
    Private Sub TextBox1_Change()
    Dim sh As Shape
    Set sh = ActivePresentation.Slides(1).Shapes("Rectangle2")
    sh.Name = "Rectangle2"
    End Sub
    
    
    Private Sub CommandButton1_Click()
    Dim Value As Shape
    Value = TextBox1.Text
    Activepresentation.Slides(1).Shapes ("Rectangle2")
    sh.name = "Rectangle2"
    End Sub

    Thank You

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Usually you would populate the combo box as the form initialises.

    Private Sub UserForm_Initialize()
    With ComboBox1
    .Clear
    .AddItem " ", 0
    .AddItem "Test", 1
    .AddItem "Test2", 2
    End With
    End Sub

    You could EITHER update the shape text when the combo box changes OR when the form closes.

    Private Sub ComboBox1_Change()
    ActivePresentation.Slides(1).Shapes("Rectangle 1").TextFrame.TextRange = _
    Me.ComboBox1.Value
    End Sub


    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    ActivePresentation.Slides(1).Shapes("Rectangle 1").TextFrame.TextRange = _
    Me.ComboBox1.Value
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Newbie
    Joined
    May 2014
    Posts
    2
    Location
    Thank you for your reply,

    I got it work with following:

    Private Sub ComboBox1_DropButtonClick()
    With Activepresentation.Slides(1).Shapes("Retangle1")
    .TextFrame.TextRange.Text = ComboBox1.Text
    End With
    If combobox.ListCount = 0 Then
    With ComboBox1
    .AddItem " ", 0
    .AddItem "Test", 1
    .AddItem "Test2", 2
    End With
    End If
    End Sub
    Only issue now is that if I want to add freetext it wont submit it with enter key...

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    And that's why you should use the events I mentioned!
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

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