PDA

View Full Version : Populate TextBox based combobox value



Leisson
05-08-2014, 02:02 AM
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

John Wilson
05-08-2014, 07:10 AM
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

Leisson
05-08-2014, 08:42 AM
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...

John Wilson
05-08-2014, 08:58 AM
And that's why you should use the events I mentioned!