Help controlling message box responses

MartinS

Active Member
Joined
Jun 17, 2003
Messages
487
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
It works for me. What exactly happens when you run it?
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,461
Members
449,085
Latest member
ExcelError

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top