PDA

View Full Version : Show/Hide Textboxes from a combobox



macca34
03-04-2014, 03:52 AM
I have code below that hides text when a checkbox is selected. Does anyone know how I can change this to a combobox that shows/hide a textbox rather than just plain text?


Private Sub CheckBox1_Click()
If Bookmarks("TextToHide").Range.Font.Hidden = True Then

Bookmarks("TextToHide").Range.Font.Hidden = False

Else

Bookmarks("TextToHide").Range.Font.Hidden = True

End If
End Sub

macca34
03-04-2014, 06:20 AM
I have tried the following. However both textboxes are disabled!


Option Explicit
Const T1 = "Addition"
Const T2 = "Amendment"
Private Sub ComboBox1_Change()
ComboBox1.List = Array(T1, T2)
If ComboBox1.Value = "T1" Then
TextBox1.Enabled = True
Else
TextBox2.Enabled = False
If ComboBox1.Value = "T2" Then
TextBox2.Enabled = True
Else
TextBox1.Enabled = False
End If
End If
End Sub

fumei
03-04-2014, 04:01 PM
However both textboxes are disabled! if this is the _Change procedure, what is in the combobox in the first place? You can not change anything if there is nothing there...so what is there?

In any case, Enable is not a visible property.

Where are these controls? On a userform? if they are legacy ActiveX controls in the document, then they do not have a Visible property.

macca34
03-05-2014, 02:29 AM
I have tried changing to the following.


Option Explicit
Const T1 = "Addition"
Const T2 = "Amendment"
Private Sub Document_Open()
ComboBox1.List = Array(T1, T2)
If ComboBox1.Value = "" Then
TextBox1.Enabled = False
TextBox2.Enabled = False
End If
If ComboBox1.Value = "T1" Then
TextBox1.Enabled = True
Else
TextBox1.Enabled = False
If ComboBox1.Value = "T2" Then
TextBox2.Enabled = True
Else
TextBox2.Enabled = False
End If
End If
End Sub

Both textboxes are still disabled. If Enable property is not visable whT can Iuse to enable/disable a textbox?