View Full Version : Userform 'Greying Out' Textboxes
ajhez
07-16-2015, 06:56 AM
I have a number of textboxes in a Userform that will only require inputting in a minority of circumstances.
I have locked these textboxes to prevent input unless a checkbox has been ticked by the user to indicate they are required.
I wondered if there was a way to have these textboxes 'greyed out' when the checkbox is unchecked, and then return to the normal white/blank colour once the checkbox has been ticked / becomes live.
Thanks,
AJHEZ
gmayor
07-16-2015, 07:52 AM
Set the backcolor and enabled properties according to the value of the checkbox e.g.
Private Sub CheckBox1_Change()
With Me
If .CheckBox1.Value = True Then
.TextBox1.Enabled = True
.TextBox1.BackColor = &H80000005
Else
.TextBox1.Enabled = False
.TextBox1.BackColor = &HE0E0E0
End If
End With
End Sub
Set the initial value of the textbox to the false values.
ajhez
07-21-2015, 07:19 AM
Thanks, Graham.
I've noticed that if I type into an enabled textbox then uncheck my checkbox (making the textbox disabled and grey-out) that the text remains albeit it in a visible similar greyed out font colour.
Would there be a similar way that if this was to happen that the greyed out text matched the greyed out textbox and was completely invisible? I would then want it to be back to original black if the checkbox was re-checked and the textbox enabled.
My rationale for this is I want to avoid users querying if the greyed out text in a greyed out textbox will still be inputted by the form. But i also want it to become visible gain if the reason the box was unchecked was purely by accident, so the user will not need to re-input into the form.
gmayor
07-21-2015, 07:24 AM
Change the forecolor setting to the backcolor setting and then back to black e.g.
Private Sub CheckBox1_Change()
With Me
If .CheckBox1.Value = True Then
.TextBox1.Enabled = True
.TextBox1.BackColor = &H80000005
.TextBox1.Forecolor = &H80000012
Else
.TextBox1.Enabled = False
.TextBox1.BackColor = &HE0E0E0
.TextBox1.Forecolor = &HE0E0E0
End If
End With
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.