Input box with username/passwords not working.

klarowe

Active Member
Joined
Mar 28, 2011
Messages
389
Can someone tell me why this is not working? The username input box pops up correctly and only accepts the 3 valid entries, but when the password box pops up, no matter what I put in there it keeps coming back with the incorrect password messagebox... even if the password is correct.

Or if there is a simpler way to do this, please fell free to correct it.
Thanks

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Range("C27")) Is Nothing Then
User:   UserName = Application.InputBox("Please enter username.", "Username", vbOKCancel)
        If UserName = 0 Then Exit Sub
        Select Case UserName
            Case "Jeff Sheely"
PWordJS:        Password = Application.InputBox("Please enter Password.", "Password", vbOKCancel)
                If Password = 0 Then Exit Sub
                If Passord = "JSheely" Then
                    ActiveSheet.Pictures.Insert( _
                    "S:\SERVICE\Shop Teardown Reports\Teardown Templates\New Teardown Pictures\Signature1.jpg" _
                    ).Select
                    Selection.ShapeRange.LockAspectRatio = msoFalse
                    Selection.ShapeRange.Width = 168#
                    Selection.ShapeRange.Height = 15#
                    Selection.ShapeRange.IncrementTop 2.25
                    Selection.ShapeRange.IncrementLeft 0.75
                Else:
                    MsgBox "You have entered an incorrect password.", vbOKOnly, "Incorrect Password"
                GoTo PWordJS
                End If
                
            Case "Dan Madison"
PWordDM:        Password = Application.InputBox("Please enter Password.", "Password", vbOKCancel)
                If Password = 0 Then Exit Sub
                If Passord = "DMadison" Then
                    ActiveSheet.Pictures.Insert( _
                    "S:\SERVICE\Shop Teardown Reports\Teardown Templates\New Teardown Pictures\Signature1.jpg" _
                    ).Select
                    Selection.ShapeRange.LockAspectRatio = msoFalse
                    Selection.ShapeRange.Width = 168#
                    Selection.ShapeRange.Height = 15#
                    Selection.ShapeRange.IncrementTop 2.25
                    Selection.ShapeRange.IncrementLeft 0.75
                Else:
                    MsgBox "You have entered an incorrect password.", vbOKOnly, "Incorrect Password"
                    GoTo PWordDM
                End If
                
            Case "Mike Andrews"
PWordMA:        Password = Application.InputBox("Please enter Password.", "Password", vbOKCancel)
                If Password = 0 Then Exit Sub
                If Passord = "MAndrews" Then
                    ActiveSheet.Pictures.Insert( _
                    "S:\SERVICE\Shop Teardown Reports\Teardown Templates\New Teardown Pictures\Signature1.jpg" _
                    ).Select
                    Selection.ShapeRange.LockAspectRatio = msoFalse
                    Selection.ShapeRange.Width = 168#
                    Selection.ShapeRange.Height = 15#
                    Selection.ShapeRange.IncrementTop 2.25
                    Selection.ShapeRange.IncrementLeft 0.75
                Else:
                    MsgBox "You have entered an incorrect password.", vbOKOnly, "Incorrect Password"
                    GoTo PWordMA
                End If
            Case Else:
                    MsgBox "You have not entered a valid Username.", vbOKOnly, "Invalid Username"
                    Sheets("Home").Range("C37").Value = ""
                    GoTo User
        End Select
    End If
End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Found a different way to do it that works pretty well.
Code:
 Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Range("C27")) Is Nothing Then
User:   UserName = InputBox("Please enter username.", "Username", vbOKCancel)
        If UserName = "Jeff Sheely" Then
PWordJS:        Password = InputBox("Please enter password.", "Password", vbOKOnly)
                If Password = "JSheely" Then
                    ActiveSheet.Pictures.Insert( _
                    "S:\SERVICE\Shop Teardown Reports\Teardown Templates\New Teardown Pictures\Signature1.jpg" _
                    ).Select
                    Selection.ShapeRange.LockAspectRatio = msoFalse
                    Selection.ShapeRange.Width = 168#
                    Selection.ShapeRange.Height = 15#
                    Selection.ShapeRange.IncrementTop 2.25
                    Selection.ShapeRange.IncrementLeft 0.75
                Else:
                    MsgBox "You have entered an incorrect password.", vbOKOnly, "Incorrect Password"
                    GoTo PWordJS
                End If
        
        ElseIf UserName = "Dan Madison" Then
PWordDM:        Password = InputBox("Please enter password.", "Password", vbOKOnly)
                If Password = "DMadison" Then
                    ActiveSheet.Pictures.Insert( _
                    "S:\SERVICE\Shop Teardown Reports\Teardown Templates\New Teardown Pictures\Signature (DMadison).jpg" _
                    ).Select
                    Selection.ShapeRange.LockAspectRatio = msoFalse
                    Selection.ShapeRange.Width = 168#
                    Selection.ShapeRange.Height = 15#
                    Selection.ShapeRange.IncrementTop 2.25
                    Selection.ShapeRange.IncrementLeft 0.75
                Else:
                    MsgBox "You have entered an incorrect password.", vbOKOnly, "Incorrect Password"
                    GoTo PWordDM
                End If
        
        ElseIf UserName = "Mike Andrews" Then
PWordMA:        Password = InputBox("Please enter password.", "Password", vbOKOnly)
                If Password = "MAndrews" Then
                    ActiveSheet.Pictures.Insert( _
                    "S:\SERVICE\Shop Teardown Reports\Teardown Templates\New Teardown Pictures\Signature (MAndrews).jpg" _
                    ).Select
                    Selection.ShapeRange.LockAspectRatio = msoFalse
                    Selection.ShapeRange.Width = 168#
                    Selection.ShapeRange.Height = 15#
                    Selection.ShapeRange.IncrementTop 2.25
                    Selection.ShapeRange.IncrementLeft 0.75
                Else:
                    MsgBox "You have entered an incorrect password.", vbOKOnly, "Incorrect Password"
                    GoTo PWordDM
                End If
        Else:
            MsgBox "You have entered an incorrect user name.", vbOKOnly, "Incorrect User Name"
            GoTo User
        End If
    End If
End Sub
 
Upvote 0
Change the tests as follows:-
Code:
If ucase(UserName) = ucase("Jeff Sheely") Then

Or, if you don't mind the passwords being case-insensitive too, place this as line 1 of your module:-
Code:
Option Compare Text
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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