Log in

View Full Version : refresh a textbox



romelsms1
10-06-2011, 01:51 AM
hi,

I’m trying to create a connection (in word 2003) between a “combobox” and a “textbox”. In the combobox I have 3 entries. When I select an entry “renault” in the text box I want to appear “car”

My problem: When I select an entry in the textbox does not appear automatically the specific part. I must write something over it

For example:
Renault -> car
Sony -> laptop
LA -> city
and also a line for new entry



Private Sub ComboBox1_click()

'Renault -> car
'Sony -> laptop
'LA -> city
‘and also a line for new entry


Me.ComboBox1.List = Split(" renault sony LA")

End Sub


Private Sub TextBox1_Change()

If Me.ComboBox1.Text = "renault" Then
' Me.TextBox1.Text = Refresh ?????
Me.TextBox1.Text = "car"
Else
If Me.ComboBox1.Text = "sony" Then
TextBox1.Text = "laptop"
Else
If Me.ComboBox1.Text = "la" Then
TextBox1.Text = "city"
Else
TextBox1.Text = "" 'for a new wntry
End If
End If
End If
End Sub

gmaxey
10-06-2011, 05:09 AM
Option Explicit
Private Sub ComboBox1_Change()
Select Case ComboBox1.Value
Case "LA"
TextBox1.Text = "City"
Case "Renault"
TextBox1.Text = "Car"
Case "Sony"
TextBox1.Text = "Laptop"
Case Else
TextBox1.Text = ComboBox1.Value
End Select
End Sub
Private Sub UserForm_Initialize()
Me.ComboBox1.List = Split("LA|Renault|Sony", "|")
End Sub

romelsms1
10-06-2011, 10:33 PM
hi again,

I have another problem:
when I save and exit the document and I re-open it, the combobox don't keep the entrys, why? (for that I must reload the code)

Tinbendr
10-16-2011, 08:25 AM
the combobox don't keep the entrys, why? That's the way it's designed.

If you want to keep the entries, you'll have to store them and use the data dynamically.

Attach a sample doc so we can see what you're trying to accomplish.