+ Reply to Thread
Results 1 to 14 of 14

inputbox for simple verification purposes?

  1. #1
    Registered User
    Join Date
    05-03-2008
    Posts
    57

    inputbox for simple verification purposes?

    Hi,
    I have a VBA userform with various textbox fields like 'Name' and 'Address' and 'Amount'
    I would like an input box to pop up that asks the user to 're-enter for verification'
    So that they have to type the same thing twice, to protect against typos

    How do I code it so the program compares the inputbox to the textbox and passes only if they are identical?

    (or even, using two inputboxes instead if that would be easier)

    Grateful for any assistance
    Andrew

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello durandal5,

    Here is the code for the Textbox control and the macro to verify the input.

    Textbox Event Code
    Please Login or Register  to view this content.
    Macro Code to Verify Input
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    05-03-2008
    Posts
    57
    Thanks, that seems to be right, but there's a problem...

    the input box will not pop up after i've entered the text, it only appears if i close the userform, and while it appears to verify like i wanted, when you OK or Cancel the box, there is no form to go back to, the program just ends

    the code i devised myself earlier also had this problem with AfterUpdate

    perhaps it's a Mac Excel bug. I will try on a windows computer.

  4. #4
    Registered User
    Join Date
    05-03-2008
    Posts
    57
    aha, the problem seems to be with the enter key
    tabbing to the next box or clicking another control brings the inputbox up
    i turned the textbox's EnterKeyBehaviour property to True and now it works when you press enter too

    (although i'm a bit confused as i thought enter key behaviour was for making new lines in the text box...)

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello durandl05,

    Nice work on catching that property setting. I didn't occur to me to ask if you were using a Mac. I will start doing that. The world isn't exclusively PC!

    Sincerely,
    Leith Ross

  6. #6
    Registered User
    Join Date
    05-03-2008
    Posts
    57
    Thanks again. Yes the Mac VBA suite has a few quirks. Last time i spent ages wondering why the Tabbing order wasn't working, no matter how what i set teh 'TabOrder' and 'Autotab' properties too... turned out the code ran fine on Windows.

    I have a real basic question now...
    i have a bunch of checkboxes for another field, clicking one of them puts a number into a 'Type' box elsewhere

    for instance
    Please Login or Register  to view this content.
    and so on, which works fine, but some "Types" are combinations of two options, and the following statement wont work
    Please Login or Register  to view this content.
    i'm not surprised it doesn't work, but what IS the right way to have more than one condition for an IF statement?

  7. #7
    Registered User
    Join Date
    05-03-2008
    Posts
    57
    Good grief, it was just a typo i'd made when writing the procedure. The code works. Never mind!

  8. #8
    Registered User
    Join Date
    05-03-2008
    Posts
    57
    Hello again,
    When I tried to put this code in a new Userform (same idea, just this one is the real thing, the first one was just a quick demo), I get a 'Error 13, Type Mismatch' bug. Can't work out why this would be as I'm doing exactly the same thing. Any ideas?

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello durandal05,

    If would help to see the code and on which line the error occurs.

    Sincerely,
    Leith Ross

  10. #10
    Registered User
    Join Date
    05-03-2008
    Posts
    57
    when it runs i get a Error 13 Type Mismatch message and the 'verifyinput activecontrol' line is highlighted. the error occurs when i hit enter after typing something in the textbox (txtName)


    Please Login or Register  to view this content.
    i'm quite baffled!

  11. #11
    Registered User
    Join Date
    05-03-2008
    Posts
    57
    i'm having some luck with the following code: in the textbox afterupdate even i store the text in a variable strTemp and call a subroutine called 'verify'. only problem is i can't get the focus/cursor to stay in the textbox if the user fails the verification. probably an easy solution to this, would you happen to know what it is? (or alternatively, what the problem is with the code you gave me originally, which has been bugging me for hours!) Cheers

    Please Login or Register  to view this content.

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello ,

    You need to use the the TextBox_Exit() event to return the user back to the text box if the verification fails.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  13. #13
    Registered User
    Join Date
    05-03-2008
    Posts
    57
    Ok got it working. Thanks for all your help

    Please Login or Register  to view this content.
    (to anyone who wants to use this - the above will leave the original input in the box, which is better for my purposes. a line like txtname="" will clear it)

  14. #14
    Registered User
    Join Date
    05-03-2008
    Posts
    57
    after working on this for hours...

    'Path/File error'

    document lost

    *shoots laptop*

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1