Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Display Message in TextBox until it is selected to type

Posted on 2011-02-22
6
Medium Priority
?
748 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
5 Comments
 
LVL 5

Accepted Solution

by:
roger_karam earned 1336 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 664 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 1336 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:Tracy
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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

783 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