Consulting

Results 1 to 5 of 5

Thread: Solved: MsgBox Loop Help

  1. #1
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location

    Solved: MsgBox Loop Help

    I have something like this

    [vba]res = InputBox("Please Enter Password")
    If res = "candy" Then[/vba]
    It will run a couple of formulas.

    I would like so if res doesn't = "candy" then to prompt res2 = MsgBox(""Sorry wrong Answer! Please Try Again!", vbYesNo)
    And if clicked Yes loop back to the original res InputBox.
    If clicked No To Exit Sub.

    Any help would be great. Thanks

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Try this:
    [VBA]
    Sub res()
    Dim res As String
    Strt:
    res = InputBox("Please Enter Password")
    If res = "candy" Then
    MsgBox "Success"
    ElseIf res <> "candy" Then
    res2 = MsgBox("Sorry wrong Answer! Please Try Again!", vbYesNo)
    If res2 = vbYes Then
    GoTo Strt
    Else
    Exit Sub
    End If
    End If
    End Sub
    [/VBA]
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    Perfect!

    One more thing do you know how i can have the text entered in the InputBox appear as asterisks? "*****"

  4. #4
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Nope! you need to use a userform and textbox if you are planning on using it for a password!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  5. #5
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    Ok thanks i will use it like that. Thanks Simon

Posting Permissions

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