INPUTBOX not evaluating properly

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ineedahelp
    New Member
    • Sep 2006
    • 98

    INPUTBOX not evaluating properly

    I have declared mUser as a public variable as I need to be able to alter ALL procedures depending on the input.

    Option Compare Database
    Public mUser As String

    I am trying to check if the user types the correct entry. If I enter 'laa' or 'LAA' or 'jg' or 'JG' into my inputbox, although it debugs properly, my IF statement always forces the msgBox display. Why isn't mUser working in my IF statement? thank you for any help!!!

    Private Sub Form_Open(Cance l As Integer)

    mUser = InputBox("Pleas e sign in: ", "User Sign In", , 5000, 5000)
    Debug.Print mUser
    Debug.Print Len(mUser)
    If mUser <> "JG" Or mUser <> "laa" Or mUser <> "jg" or mUser <> "JG" Then
    MsgBox "Incorrect Entry!", vbCritical
    'DoCmd.Close
    End If
    End Sub
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32662

    #2
    You're using OR instead of AND.

    Another tip to make things easier is :-

    Use UCase() around the response from InputBox then you only have to check against the names once.
    This also avoids problems when someone types in 'James'.

    Comment

    • ineedahelp
      New Member
      • Sep 2006
      • 98

      #3
      Sometimes its the simple things that get us down!!!! thanks!!!

      Comment

      • comteck
        New Member
        • Jun 2006
        • 179

        #4
        Use "UCase" as NeoPa suggested, but also add an ELSEIF statement. It should look like this:
        Code:
        Private Sub Form_Open(Cancel As Integer)
        
        mUser = InputBox("Please sign in: ", "User Sign In", , 5000, 5000)
        UCase(mUser)
        Debug.Print mUser
        Debug.Print Len(mUser)
        If mUser <> "JG" Then
        MsgBox "Incorrect Entry!", vbCritical
        'DoCmd.Close
        Else If mUser <> "LAA"
        MsgBox "Incorrect Entry!", vbCritical
        'DoCmd.Close
        End If
        End Sub

        Comment

        Working...