View Full Version : Solved: Msg box - if password is wrong
Hi 
 
How would i add the function to the current macro is the user enters the wrong password. when thy click the Administrator tab worksheet. 
MsgBox "Invalid Password - Please Try Again To Log-in."
RonMcK
07-23-2008, 05:26 AM
Pete,
You could do something like the red colored code that I added:
EnterPassword:
                  If Not Authorized Then
                     PasswordEntered = InputBox("Please Enter Administrator Password To " & vbCrLf & _
"Access Administrator Worksheet" & vbCrLf & "(or Enter 'End' to terminate.)")
                     If PasswordEntered = Password Then
                        Authorized = True
                    ElseIf PasswordEntered = "End" Then
                        GoTo Bail_Out
                    Else
                        response = MsgBox("Invalid Password - Please Try Again To Log-in.", _
 vbOKOnly, "Warning.")
                        Authorized = False
                        GoTo EnterPassword
                     End If
                  End If
(down at bottom of sub:)
Bail_Out:
   Application.EnableEvents = True
   Application.ScreenUpdating = ScreenUpdating
   
End Sub
Look up MsgBox in Excel Help for more details and background.
Added with edit: Thanks, Bob, a very Good Point.  Pete, look at your code and tell me if you want End to exit out of the sub (macro) completely.
Cheers!
thansk for the feedback....works prefectly
Bob Phillips
07-23-2008, 05:28 AM
You should add an exit condition in case they don't know the password and they don't want to answer that question for the rset of their lives.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.