Solved

Display Message in TextBox until it is selected to type

Posted on 2011-02-22
6
744 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

622 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