Can anyone help me find the issue in my code? It seems to work ok other than I keep getting a Run-Time Error 424. When I click 'Debug' it drops me on to this line
The code is a username and password setup where it checks the username in another spreadsheet against the password in an adjacent column. The checking of the user name and password is working fine and lets me in to my next userform as planned but then when I come to exit I get the error.
Thanks in advance.
Loop While Not rngUser Is Nothing And firstUser <> rngUser.Address
The code is a username and password setup where it checks the username in another spreadsheet against the password in an adjacent column. The checking of the user name and password is working fine and lets me in to my next userform as planned but then when I come to exit I get the error.
Thanks in advance.
VBA Code:
Private Sub CMD_Login_Click()
If TxtPIN.value = "" Then
MsgBox ("Enter your PIN number"), vbOKOnly
TxtPIN.SetFocus
Exit Sub
End If
If TxtPassword.value = "" Then
MsgBox ("Enter your password"), vbOKOnly
TxtPassword.SetFocus
Exit Sub
End If
Dim wbk As Workbook
Dim ws As Worksheet
Dim UserName As String, PW As String
Dim rngUser As Range
Dim firstUser As String
Dim UserFound As Boolean
Set wbk = Workbooks.Open("XXXX\Returns v.2.0.xlsx", ReadOnly:=True)
Sheets("Admin Users").Select
'Set ws = wbk.Sheets("Admin Users")
UserName = TxtPIN.value
PW = TxtPassword.value
With Range("A:B")
Set rngUser = .Find(UserName, lookat:=xlWhole)
If Not rngUser Is Nothing Then
firstUser = rngUser.Address
Do
If (PW = rngUser.Offset(0, 1).value) And rngUser.Offset(0, 6).value = "Yes" Then
UserFound = True
TxtUsers.Text = wbk.Sheets("Data").Range("AI2")
TxtTotalTests.Text = wbk.Sheets("Data").Range("AJ2")
wbk.Close
UsrFrmAdminDashboard.Show
Else
Set rngUser = .FindNext(rngUser)
End If
Loop While Not rngUser Is Nothing And firstUser <> rngUser.Address
Else
MsgBox "You are not authorised to use this system!", vbExclamation, "Returns - Admin Dashboard"
TxtPIN.value = ""
TxtPassword.value = ""
Exit Sub
End If
End With
If Not UserFound Then
MsgBox "Either your account access has not been approved or you have entered an incorrect password!", vbOKOnly, "Returns - Admin Dashboard"
TxtPIN.value = ""
TxtPassword.value = ""
TxtPIN.SetFocus
End If
End Sub
Last edited by a moderator: