The password supplied is not correct... It is!

albertc30

Well-known Member
Joined
May 7, 2012
Messages
1,091
Office Version
  1. 2019
Platform
  1. Windows
Hi all.

I have a userform that allows me to type in a username and a password.

This then is checked to a hidden sheet and if found it opens if not it returns an error as per bellow code;

Code:
Private Sub cmBtnLogin_Click()


Dim iFoundPass As Integer
On Error Resume Next
With Sheets("UsersHide").Range("UserNames")


   iFoundPass = .Find(What:=txtBoxUserName, After:=.Cells(1, 1), LookIn:=xlValues, LookAt _
        :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False).Row
End With
On Error GoTo 0


If iFoundPass = 0 Then
   SomethingWrong
      Exit Sub
End If


If Sheets("UsersHide").Cells(iFoundPass, 2) <> txtBoxPassword Then
   SomethingWrong
      Exit Sub
End If


Sheets("Invoice").Unprotect Password:="******"
    
Sheets("Invoice").Range("CurrentUser") = txtBoxUserName


Sheets("Invoice").Protect Password:="*******"


Unload Me


Application.Visible = True


End Sub

This has always worked with no issues and today, it now behaves differently even though that code was never touched.

In fact, when I try to open the spreadsheet again after the error, it now tells me the page is already opened!

In fact, if I enter the wrong password I get the wrong message error!

The error I am now getting is the following;

Run-Time error '1004':
The password you supplied is not correct. Verify that the CAPS LOCK key is off and be sure to use the correct capitalization.

Also, with a top spec PC i5 with 16GB RAM why is VBA telling me no memory or low memory?

It's all happening at once.

Any help is really appreciated.

Thanks.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
It is better to Set the find equal to a range rather than an integer. Even it it did work with an integer, rows should always be dimmed as Long to be on the safe side.

e.g.
Code:
Private Sub cmBtnLogin_Click()
  Dim rFoundPass As Range
  
  With Sheets("UsersHide").Range("UserNames")
    Set rFoundPass = .Find(What:=txtBoxUserName, After:=.Cells(1, 1), LookIn:=xlValues, LookAt _
      :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
      False)
  End With
  
  If rFoundPass Is Nothing Then
     SomethingWrong
      Exit Sub
  End If
  
  If Sheets("UsersHide").Cells(rFoundPass.Row, 2) <> txtBoxPassword Then
     SomethingWrong
      Exit Sub
  End If
  
  Sheets("Invoice").Unprotect Password:="******"
  Sheets("Invoice").Range("CurrentUser") = txtBoxUserName
  Sheets("Invoice").Protect Password:="*******"
  
  Unload Me
  Application.Visible = True
End Sub
 
Upvote 0
Hi Kenneth.

I have just tried your code and it still returns the same error.

Much appreciated for your help and apologies for the late reply.

I'm going to have to break my head with this one.

Not once did I even touched the code for this and it's going **** up now!

Cheers.
 
Upvote 0
Put a breakpoint on this line...


Code:
If Sheets("UsersHide").Cells(iFoundPass, 2) <> txtBoxPassword Then


when you get to this breakpoint in your code, drop down to your immediate window and test those variables and see what they are.

type these lines into the immediate window and hit enter...

?Sheets("UsersHide").Cells(iFoundPass, 2)
?txtBoxPassword
?txtBoxPassword = Sheets("UsersHide").Cells(iFoundPass, 2)

Please share the results
 
Last edited:
Upvote 0
Oh dear...

This is a bit above my pay grade, lol...

I'll give it a try.

Cheers.
 
Upvote 0
If it is a case issue, put lcase() around the found password and the texbox's password. That way, your equality check will always work. Otherwise, your worksheet found password case must match the textbox's case.

Since these are passwords, it may not be advisable to show results in this forum unless you obfuscate them.

For the case check, the VBE Immediate Window view of the debug.print values can be done this way after running the code.
Code:
Private Sub cmBtnLogin_Click()
  Dim rFoundPass As Range
  
  With Sheets("UsersHide").Range("UserNames")
    Set rFoundPass = .Find(What:=txtBoxUserName, After:=.Cells(1, 1), LookIn:=xlValues, LookAt _
      :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
      False)
  End With
  
  If rFoundPass Is Nothing Then
     SomethingWrong
      Exit Sub
  End If
  
  Debug.Print rFoundPass, rFoundPass.row
  Debug.Print Sheets("UsersHide").Cells(rFoundPass.Row, 2), txtBoxUserName
  Debug.Print lcase(Sheets("UsersHide").Cells(rFoundPass.Row, 2)), lcase(txtBoxUserName)

  If Sheets("UsersHide").Cells(rFoundPass.Row, 2) <> txtBoxPassword Then
     SomethingWrong
      Exit Sub
  End If
  
  Sheets("Invoice").Unprotect Password:="******"
  Sheets("Invoice").Range("CurrentUser") = txtBoxUserName
  Sheets("Invoice").Protect Password:="*******"
  
  Unload Me
  Application.Visible = True
End Sub
 
Last edited:
Upvote 0
Hi all.

The issue was in the invoice sheet protected with the correct password but unlike the password stated in the code, it was actually saved in CAPS LOCK!!! Ops...

It's working now and with your new code as per advice.

Much appreciated guys.

I'll have to look into the breakpoint thing.

Never used it but I think I got it. Please see pic.

I think that cant use code in protected sheet guided me in the right direction?!

https://www.dropbox.com/s/e9kpwsv8u65sd3n/Screenshot_42.png?dl=0

Screenshot_42.png
 
Last edited:
Upvote 0
Hi all.

The issue was in the invoice sheet protected with the correct password but unlike the password stated in the code, it was actually saved in CAPS LOCK!!! Ops...

It's working now and with your new code as per advice.

Much appreciated guys.

I'll have to look into the breakpoint thing.

Never used it but I think I got it. Please see pic.

I think that cant use code in protected sheet guided me in the right direction?!

https://www.dropbox.com/s/e9kpwsv8u65sd3n/Screenshot_42.png?dl=0

Screenshot_42.png


That is your "Locals" window. Go into your 'View' options at the top and enable the "Immediate" window. It is an INVALUABLE tool while coding and debugging.

Or try hitting Ctrl + G
 
Last edited:
Upvote 0
I would recommend deleting that link or changing your production version password.

The local window is good for debugging too. I normally just use a MsgBox() or Debug.Print for simple debugging aids. The Immediate Window can be used interactively as explained. You can execute several lines in Immediate window by separating the lines with colons. e.g.
Code:
a="Ken": Msgbox "Hi " & a & "!"
 
Upvote 0
I would recommend deleting that link or changing your production version password.

The local window is good for debugging too. I normally just use a MsgBox() or Debug.Print for simple debugging aids. The Immediate Window can be used interactively as explained. You can execute several lines in Immediate window by separating the lines with colons. e.g.
Code:
a="Ken": Msgbox "Hi " & a & "!"


Thanks to all the help everyone.

The password as it stands its just generic and it will be changed.

Much appreciated to all of you and for the valuable time you give to the excel community.

Cheers.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

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