Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Display Message in TextBox until it is selected to type

Posted on 2011-02-22
6
Medium Priority
?
746 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

670 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