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