Results 1 to 21 of 21

Thread: Clearing a Textbox

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    The Dark Side of the Moon
    Posts
    448

    Clearing a Textbox

    Is there a way to clear a textbox other than.

    Text1.text = ""

  2. #2
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    You can also use API like this:
    VB Code:
    1. Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
    2. SetWindowText Text1.hwnd, ""
    Baaaaaaaaah

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    The Dark Side of the Moon
    Posts
    448
    That's a bit much. What I was trying to hit at was if there is a function that can clear a textbox, because this form I have in Access acts funny when I clear the two date formatted text boxes with = "".

  4. #4
    Hyperactive Member FATBOYPEE's Avatar
    Join Date
    May 2001
    Location
    Charleville (Ireland) Still. ANYONE GOT A JOB I CAN HAVE ? GIZA JOB. I CAN DO THAT....
    Posts
    463
    Are your textboxes bound or unbound ?

    If they're unbound, you should have no problems ?

    Pee

    Best Bar.....

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    What do you mean by "acts funny"?

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    The Dark Side of the Moon
    Posts
    448
    It sings and it dances.

    It causes errors what else?

  7. #7
    Hyperactive Member FATBOYPEE's Avatar
    Join Date
    May 2001
    Location
    Charleville (Ireland) Still. ANYONE GOT A JOB I CAN HAVE ? GIZA JOB. I CAN DO THAT....
    Posts
    463
    ooooh !

    Instead of assigning a format to the textbox (assuming you have?), put some formatting on the values in code in the lostfocus event or somesuch....

    You can then trap any errors that arise from the data not being validat against the Access Format.

    Pee

    Best Bar.....

  8. #8
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Wink

    Just a suggestion, .... but you'd be better off by putting all your code into a VB form, and leaving the Access database to just be a database.
    ~Peter


  9. #9
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    perhaps this project is only access.

    what about

    text1 = ""

    or

    text1 = vbnullstring



    might work

  10. #10
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Wink

    In Access you have to set the FOCUS to the textbox before you can clear it.

    I'm just saying, .... to avoid headaches down the road, make it in VB. Maybe he can't. It's just a suggestion.
    ~Peter


  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    The Dark Side of the Moon
    Posts
    448
    Goes to show how much you know about Access.

    You don't need to set the focus. Only when you use the text property do you need to use the setfocus().

    Just clear textboxes like

    Text1 = ""

    And this is in Access 97, I'm working for a company and they do not have VB compilers.

  12. #12
    Hyperactive Member FATBOYPEE's Avatar
    Join Date
    May 2001
    Location
    Charleville (Ireland) Still. ANYONE GOT A JOB I CAN HAVE ? GIZA JOB. I CAN DO THAT....
    Posts
    463
    Originally posted by JaredM
    Goes to show how much you know about Access.

    Hmm, how to win friends and influence people !!

    Well, nice to know any suggestions & help are appreciated....

    Best Bar.....

  13. #13
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Angry

    Yeah really huh? Go figure.

    I could be mean and say something about "VB compilers", but i'm not going to.

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    The Dark Side of the Moon
    Posts
    448
    I was kidding. Maybe I should've put a smiley next to it.

    I figured out the problem. I had to set the formatting property on the textbox in access in addition to the input mask.

  15. #15
    DaoK
    Guest
    That work :

    VB Code:
    1. Option Explicit
    2. Private Sub Form_Load()
    3. Dim Clear As String
    4. Text1 = Clear
    5. End Sub

  16. #16
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    But, doesn't Clear contain "" which is what he is trying to avoid?

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    The Dark Side of the Moon
    Posts
    448
    Don't worry peeps I've got it to run properly now. Course it's a little bit cheesy, but the end user won't be able to see it going on.

  18. #18
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    As long as it works.

    What did you do? I'm curious.

  19. #19
    DaoK
    Guest
    But, doesn't Clear contain "" which is what he is trying to avoid?
    I know that but he wanted to avoid the "" so a empty variable is equal to "" but you do not see it... Anyways, I do not see what is wrong with "" .

  20. #20
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    what's the point of 4 lines if you can do it in 1?

    text1 = ""

    that will work the same, if not better than your little (big) example

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    The Dark Side of the Moon
    Posts
    448
    There was a property called FORMAT in the textbox control for Access. I threw in the proper formatting and the problem went away.

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