Consulting

Results 1 to 4 of 4

Thread: Userform 'Greying Out' Textboxes

  1. #1
    VBAX Regular
    Joined
    May 2015
    Posts
    44
    Location

    Userform 'Greying Out' Textboxes

    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

  2. #2
    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.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular
    Joined
    May 2015
    Posts
    44
    Location
    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.

  4. #4
    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
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Tags for this Thread

Posting Permissions

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