Results 1 to 6 of 6

Thread: InputBox Cancel

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    Greenville
    Posts
    73
    Hello I am using the following code for an input box and when I just click the cancel button that is given for the input box it still says " Incorrect Password" when I want it to just close out the inputbox. Sooo how do you code for if cancel then exit sub. Thanks.

    myvalue = InputBox("Please Enter Password:", "Edit Agents")


    If myvalue <> "manager" Then
    ElseIf myvalue <> "manager" Then
    MsgBox "Incorrect Password", vbOKOnly + vbInformation, "Denied"
    Exit Sub
    End If

    IE:::::::::: but does not work
    If Cancel = vbCancel Then
    Exit Sub
    End If

  2. #2
    Hyperactive Member JazzBass's Avatar
    Join Date
    Jun 1999
    Posts
    393
    Hi,
    I changed your code to a select case branch.
    If you want to keep your structure add another "If" statement in your first one to test to see if the returned value is "". That is what the input box returns if cancel was pressed.


    Code:
    myvalue = InputBox("Please Enter Password:", "Edit Agents")
    
    Select Case myvalue
    
        Case Is <> "manager"
            If myvalue = "" Then
                MsgBox "Canceled"
            Else
                MsgBox "Correct Password", 64, "Thanks"
            End If
            Exit Sub
    
        Case "manager"
            MsgBox "Incorrect Password", vbOKOnly + vbInformation, "Denied"
            Exit Sub
    
        End Select
    Let us know if that helped.

    JazzBass
    JazzBass
    In the .NET era
    Trying to remember VB6
    Progress:
    XP Professional @ Home
    and @ the Office

  3. #3
    Junior Member
    Join Date
    Mar 2000
    Posts
    16
    I believe that if the cancel button is invoked then it defaults the input variable to nothing so try this


    myvalue = InputBox("Please Enter Password:", "Edit Agents")

    Select Case myvalue

    Case Is <> "manager"
    If myvalue = "" Then
    'Enter any cancel message
    Exit sub
    Else
    MsgBox "Incorrect password"
    'Incorrect procedure
    End If

    Case "manager"
    MsgBox "Incorrect Password", vbOKOnly + vbInformation, "Denied"
    Exit Sub

    End Select

    Hope this helps

  4. #4
    Hyperactive Member JazzBass's Avatar
    Join Date
    Jun 1999
    Posts
    393

    UK Phil - That's right

    Hey,
    Yeah, your right. When a user cancels out of a Inputbox, it returns nothing. That is shown in my code as the two double quotes in the "If" statement.
    JazzBass

  5. #5
    Junior Member
    Join Date
    Mar 2000
    Posts
    16

    To JazzBass

    Yep, I wrote that whilst you were posting yours and didn't realise until afterwards. Nice to know that though. Another problem solved!!

    Cheers

  6. #6
    Hyperactive Member JazzBass's Avatar
    Join Date
    Jun 1999
    Posts
    393

    To UKPhil

    Cool!
    JazzBass
    In the .NET era
    Trying to remember VB6
    Progress:
    XP Professional @ Home
    and @ the Office

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