+ Reply to Thread
Results 1 to 14 of 14

inputbox for simple verification purposes?

Hybrid View

  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
    Private Sub TextBox1_AfterUpdate()
    
      VerifyInput ActiveControl
      
    End Sub
    
    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    
      If ActiveControl.Tag = "failed" Then
        Cancel = True
        ActiveControl.Tag = ""
      End If
      
    End Sub
    Macro Code to Verify Input
    Sub VerifyInput(TB As MSForms.TextBox)
    
      Dim Text As String
      
        Text = InputBox("Please re-enter the text into the box below.")
        
          If Text <> "" Then
            If Text <> TB.Value Then
              MsgBox "The text doesn't match - try again."
              TB.Value = ""
              TB.Tag = "failed"
            End If
          End If
          
    End Sub
    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
    If checkAutomatic=True then txtType=1
    If checkDiesel=True then txtType=4
    and so on, which works fine, but some "Types" are combinations of two options, and the following statement wont work
    If checkAutomatic=True AND checkDiesel=True then txtType=5
    i'm not surprised it doesn't work, but what IS the right way to have more than one condition for an IF statement?

+ 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