Textbox Default Textbox Message

This code shows how to make it so a textbox can display a default instructional message.

The purpose of this is to save space. instead of having to use a label to provide basic instructions about what should be entered in a textbox the default text can do this instead.

  • When the user gives the textbox focus the default message disappears and the textbox becomes empty.
  • If the user does not enter anything in the textbox and the textbox loses focus the default message will reappear.
  • If the user DOES enter some text the textbox will display that text in the desired color [Color] specified in the Lost_Focus event

default textbox

INSTRUCTIONS FOR TEXTBOX DEFAULT MESSAGE

  1. Specify the textbox default text in the Textbox [TooltipText] property. For this example we will assume the textbox is named Text1. This is the text that will appear when the form loads and will be grey in color.
  2. Create a .bas module. For this example give it a name  DefaultTextbox.
  3. Enter the following code in the .bas module:

  4. Enter the following code in the textbox [Text1] GotFocus:

  5. Enter the following code in the textbox [Text1] LostFocus:

  6. In the [Form_Load] event enter

This is a neat little space saving and information providing textbox tweak I personally like and I hope you do too.