Run-Time Error 424

K1600

Board Regular
Joined
Oct 20, 2017
Messages
181
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
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:
You can try
VBA Code:
Application.DisplayAlerts = False
Set wbk = Workbooks.Open("XXXX\Returns v.2.0.xlsx", ReadOnly:=True)
Application.DisplayAlerts = True
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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