Solved

Display Message in TextBox until it is selected to type

Posted on 2011-02-22
6
742 Views
Last Modified: 2012-05-11
I want to display message in the TextBox until it is selected by the user to type in some value.

EX:
I want to display message "Enter your ID" in the Text Box until it is selected by the user to enter the ID.

How would i achieve this using Excel VBA.
0
Comment
Question by:srikanthv2322
  • 2
  • 2
6 Comments
 
LVL 5

Accepted Solution

by:
roger_karam earned 334 total points
ID: 34957441
You want to use the inputbox function:


    strID= InputBox(Prompt:="Enter your ID.", Title:="ID input", Default:="ID Please")

-RK
0
 
LVL 50

Assisted Solution

by:Dave Brett
Dave Brett earned 166 total points
ID: 34957483
To force the user to enter an ID you would validate the entry as below

This test looks for a simple entry, then reflgas the message with an error title if nothing was entered

You could take it further, say to validate a 5 digit code etc

Cheers

Dave
Sub GetId()
    Dim strMsg As String
    Dim strTitle As String
redo:
    strId = InputBox("Enter your ID", strTitle)
    If Len(strId) = 0 Then
        strTitle = "Error: You must enter an ID to proceed!"
        GoTo redo
    End If
End Sub

Open in new window

0
 
LVL 5

Assisted Solution

by:roger_karam
roger_karam earned 334 total points
ID: 34957529
Hey srikanthv2322,

I think I might have misunderstood the question. Do you want a textbox that has Enter your ID written on it, but when you select the textbox it goes blank?

If you have a form with a Text Box, what you want to do is set the Textbox Text control to "Enter your ID" then have the following in the vba code for the text box. It will make it go blank when the text box is selected if it has Enter your ID written on it.

Private Sub TextBox1_Enter()

If TextBox1.Value = "Enter your ID" Then
TextBox1.Value = ""
End If

End Sub

-RK
0
 
LVL 50

Expert Comment

by:Dave Brett
ID: 35194530
As roger_karam re-interpreted his orginal comment, and it isn't completely clear what the Asker wanted, then I think a point split for
 - roger_karam's comment #34957529  (250 points)
- brettdj's comment #34957483  (250 points)

would be more appropriate

Cheers

Dave
0
 
LVL 24

Expert Comment

by:broomee9
ID: 35225349
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question