Is there an easy way to put some descriptive text inside a textbox, have it grayed out, and when you enter text in the box, it overwrites this text? For instance, I have an Issues database. In the text field, I want to put the text as follows: Enter your issue here. Then when they type in that field, it overwrites that text with whatever they enter. Hope that makes sense.
Depends on your definition of "easy," I guess! It takes a bit of code to in a number of events to cover everything, but it's not really complicated.
Set the Default Value of the textbox to "Enter Your Issue Here".
Assuming your textbox is named TextboxName and you want the text for instructions to be a pale blue (16744448)
Code:
Private Sub Form_Current()
If Me.TextboxName = "Enter Your Issue Here" Then
TextboxName.ForeColor = 16744448
Else
TextboxName.ForeColor = 0
End If
End Sub
Private Sub TextboxName_Click()
If Me.TextboxName = "Enter Your Issue Here" Then
Me.TextboxName.SelStart = 0
Me.TextboxName.SelLength = Len(Me.TextboxName)
Else
Me.TextboxName.SelStart = Nz(Len(Me.TextboxName), 0)
End If
End Sub
Private Sub TextboxName_GotFocus()
If Me.TextboxName = "Enter Your Issue Here" Then
Me.TextboxName.SelStart = 0
Me.TextboxName.SelLength = Len(Me.TextboxName)
Else
Me.TextboxName.SelStart = Nz(Len(Me.TextboxName), 0)
End If
End Sub
Private Sub TextboxName_KeyDown(KeyCode As Integer, Shift As Integer)
TextboxName.ForeColor = 0
End Sub
You can replace TextboxName with the actual name of your textbox, 16744448 with the appropriate number for the font color you want for the instructions and "Enter Your Issue Here" with whatever instructions you want to appear.
"Enter Your Issue Here" in light blue text, selected (highlighted) will be in the textbox until you enter the textbox, either by tabbing or use of the mouse. The instructions will disappear with the first keystroke entered. When entering the textbox after data has been entered, the cursor will move to the end of the text.
You must remember, when doing reports and so forth, to take into account the fact that if the user doesn't enter anything into the textbox, it's Default Value is Enter Your Issue Here. You could possibly check before saving the record, in the Form_BeforeUpdate evnt, and if the Default is still there, change it to something else or prompt your user to enter an issue before saving the record, depending on your needs.