Help controlling message box responses

MartinS

Active Member
Joined
Jun 17, 2003
Messages
420
Hi
I am attempting to stop access to a program when the user enters an incorrect password, and it works perfectly in debug, but when running, it skips the important lines and continues to load, even though the response from the messagebox is not used or stored.
Can anyone explain why it works in debug, but then doesn't when trying it live, or is there a better way to do this?
Any help/advice gratefully received
Regards
Martin
Code:
Dim strPWATTEMPT As String
Dim strMSGTEXT As String
Dim varRETRY As Variant
'\* Line label...
RetryAttempt:
'\* Request the user enter a password...
strPWATTEMPT = InputBox("Please enter the password.", "Enter Password")
'\* If the password that is entered is not correct...
    If Not StrComp(strPWATTEMPT, CODEPASSWORD) = 0 Then
'\* Display message to the user asking them to retry or cancel...
        varRETRY = MsgBox("The password you specified was incorrect!" & vbCrLf & vbCrLf _
                & "Would you like to try again?", _
                vbCritical + vbRetryCancel, _
                "Incorrect Password Entered")
'\* if user selects retry...
        If varRETRY = vbRetry Then
'\* allow user to try again...
            GoTo RetryAttempt
'\* If Retry not selected...
        Else
'\* define message text...
            strMSGTEXT = "The application will now close."
'\* display message to user...
                Call MsgBox(strMSGTEXT, vbCritical + vbOKOnly)
'\* set saved property...
                    ThisWorkbook.Saved = True 'Ignores when not in Debug
'\* close application...
                        Application.Quit 'Ignores when not in Debug
        End If
    End If
 

Some videos you may like

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

MartinS

Active Member
Joined
Jun 17, 2003
Messages
420
Glenn
It appears to have something to do with how you try to shut the windows down - if you click all three windows closed by their close [x] control, then it will continue on and run any code that follows on.
Not sure what other combinations will make it fail, but really don't want any combination that does not include entering the correct password to work.
Any ideas of how to get round it?
Regards, and thanks in advance
Martin
 

Watch MrExcel Video

Forum statistics

Threads
1,118,671
Messages
5,573,583
Members
412,537
Latest member
Mohamed_5966
Top