Userform Textbox faint text

DipDip

Board Regular
Joined
Jan 23, 2015
Messages
76
Office Version
  1. 2016
Platform
  1. Windows
Hi Peeps,
I hope someone can help me with my query. I have tried searching on the net but to no avail. What I am trying to do is have "Please type your name here" displayed in the textbox, but when you start typing in something, that disappears.

I also need it do display in another box which says "Please be as descriptive as possible".

Here is my code so far...

Code:
Private Sub UserForm_Click()


End Sub


Private Sub UserForm_Initialize()


'Empty NameTextBox
NameTextBox.Value = ""


'Empty DateTextBox
DateTextBox.Value = Format(Now(), "DD/MM/YY")


'Empty TimeTextBox
TimeTextBox.Value = Format(Now(), "hh:mm")


'Empty WardAreaComboBox
WardAreaComboBox = "Select from list"


'Fill WardAreaComboBox
With WardAreaComboBox
    .AddItem "A Ward"
    .AddItem "B Ward"
    .AddItem "C Ward"
    .AddItem "D Ward"
    .AddItem "E Ward"
    .AddItem "F Ward"
    .AddItem "Car Park"
    .AddItem "Garden"
    .AddItem "*******"
    .AddItem "Reception"
    .AddItem "Other"
End With


'Empty DescTextBox
DescTextBox.Value = "Please be as descriptive as possible"


'Empty PriorityComboBox
PriorityComboBox = "Select from list"


'Fill PriorityComboBox
With PriorityComboBox
    .AddItem "High"
    .AddItem "Medium"
    .AddItem "Low"
End With


'Set Focus on NameTextBox
NameTextBox.SetFocus


End Sub


Private Sub ClearButton_Click()


Call UserForm_Initialize


End Sub


Private Sub CancelButton_Click()


Unload Me


End Sub
Private Sub OKButton_Click()


If NameTextBox.Value = "" Then
 
    MsgBox "You have forgotten to type in your name", vbCritical
    Exit Sub
 
End If
 
If WardAreaComboBox.Value = "Select from list" Then
 
    MsgBox "Please select where the issue is located", vbCritical
    Exit Sub
 
End If


If DescTextBox.Value = "Please be as descriptive as possible" Then
 
    MsgBox "Please type in a description of the issue", vbCritical
    Exit Sub
 
End If
 
If PriorityComboBox.Value = "Select from list" Then
 
    MsgBox "Please select how important the issue is", vbCritical
    Exit Sub
 
End If
 
EntryUserForm.Hide


Dim emptyRow As Long


'Make Sheet2 active
Sheet2.Activate


'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1


'Transfer information
Cells(emptyRow, 1).Value = NameTextBox.Value
Cells(emptyRow, 2).Value = DateTextBox.Value
Cells(emptyRow, 3).Value = TimeTextBox.Value
Cells(emptyRow, 4).Value = WardAreaComboBox.Value
Cells(emptyRow, 5).Value = DescTextBox.Value
Cells(emptyRow, 6).Value = PriorityComboBox.Value


Sheet1.Activate


End Sub
Thanks for looking through my query.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Re: Userform Textbox faint text help

Cheers for that, however, I've had a look at it and can't seem to get it to work.

It keeps highlighted the Class bits in red and I haven't used them before so not sure what I'm doing wrong.
 
Upvote 0
Re: Userform Textbox faint text help

Made it work by using this...
Code:
Private Sub NameTextBox_Enter()
    If NameTextBox.Text = "Type your name here" Then
        NameTextBox.Text = ""
    End If
End Sub
Private Sub NameTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If Trim(NameTextBox.Text) = "" Then
        NameTextBox.Text = "Type your name here"
    End If
End Sub
Private Sub DescTextBox_Enter()
    If DescTextBox.Text = "Please be as descriptive as possible" Then
        DescTextBox.Text = ""
    End If
End Sub
Private Sub DescTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If Trim(DescTextBox.Text) = "" Then
        DescTextBox.Text = "Please be as descriptive as possible"
    End If
End Sub
 
Upvote 0
Solution
Re: Userform Textbox faint text help

You could use code like this
Code:
Private Sub TextBox1_AfterUpdate()
    With TextBox1
        If .Text = vbNullString Then
            .Text = "Please type something"
            .ForeColor = RGB(128, 128, 128)
        End If
    End With
End Sub

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    With TextBox1
        If .Text = "Please type something" Then
            .Text = vbNullString
            .ForeColor = vbBlack
        End If
    End With
End Sub

Private Sub UserForm_Initialize()
    TextBox1_AfterUpdate
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top