Results 1 to 4 of 4

Thread: How do I clear a textbox by just clicking on it? Also, a database(?) related question

  1. #1

    Thread Starter
    Registered User
    Join Date
    Jan 2013
    Posts
    1

    How do I clear a textbox by just clicking on it? Also, a database(?) related question

    Hello!

    It's my first time to post on this forum, and I'm looking forward to post more as time passes.

    But for now, I would like to ask a couple of questions...

    First, how do I clear the contents of a Textbox by just clicking on it?

    Second, a more complicated one... I would like to create a VB program where I would just input a number (say, an student ID number) and the details of the student would be displayed. I know it has something to with databases, but I'm not really sure. I have only basic knowledge of VB, and I am using an older version.

    Thank you in advance.

    Cheers.

  2. #2
    gibra
    Guest

    Re: How do I clear a textbox by just clicking on it? Also, a database(?) related ques

    First question:
    Text1.Text = vbNullString

    Second question:
    open a new thread with specific info.

  3. #3
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: How do I clear a textbox by just clicking on it? Also, a database(?) related ques

    First question:
    I will be sticking with
    Text1.Text = ""
    I have been rubbing garlic on my neck for decades, and never had a vampire bite.
    I have been using "" for decades, and never had a problem.
    I don't know if a switch to vbNullString will cause any problems, but why should I take the risk ? (I don't give a hang about tiny savings in time or space)

    Regarding the second Question, be sure to mention what version of VB you are using, for two reasons -
    1) It can effect what DB accessing method you can use (DAO vs ADO)
    2) We can harass you, until you upgrade to VB6

    Rob,
    PS In case you are very new to VB, you may need to know the event to use. EG -
    Private Sub Text1_Click()
    Text1.Text = ""
    End Sub
    And depending on the context you are using this, there are other events, that can be used, instead.
    You may care to widen your explanation of what will be happening ?
    Last edited by Bobbles; Jan 26th, 2013 at 07:57 AM.

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: How do I clear a textbox by just clicking on it? Also, a database(?) related ques

    Rather than clearing the data when you click on it you might want to consider highlighting the data when the text box gets focus. This will allow the user to clear the data with the first key stroke or retain the data or part of the data as they wish.

    The method depends on the version of VB you are using.
    VB6 or earlier would be
    Code:
    Text1.SelStart=1
    Text1.SelLength=Len(Texr1.Text)
    VB7 amd newer would be
    Code:
    Text1.SelectAll

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width