Try this
Private Sub cmbValidate_Click()
Dim FindR As Range
Dim FindR2 As Range
Dim sMsg As String, sTitle As String, sStyle As String
Dim iCounta As Integer
On Error Resume Next
Set FindR = Sheet9.Range("D1:D10").Find(What:=Me.tbxUser.Value, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext)
If FindR Is Nothing Then MsgBox Me.tbxUser & " is not listed", vbCritical, "Incorrect user name"
Exit Sub
Set FindR2 = Sheet9.Range("E1:E10").Find(What:=Me.tbxPW.Value, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext)
If FindR2 Is Nothing Then MsgBox Me.tbxPW & " is not listed", vbCritical, "Incorrect password"
Exit Sub
On Error GoTo 0
iCounta = Me.tbxGoes.Value
sTitle = "Hub Access Manager - Invalid"
sMsg = "You have entered an incorrect Username and/or Password" & vbNewLine & "Please try again using your exact details." & vbNewLine & "You have " & (3 - iCounta) & " attempts remaining."
sStyle = vbOKOnly + vbExclamation
If iCounta < 3 Then
If Me.tbxUser.Value <> FindR Or Me.tbxPW.Value <> FindR2 Then
MsgBox sMsg, sStyle, sTitle
With Me
tbxUser.Value = vbNullString
tbxPW = vbNullString
tbxUser.SetFocus
tbxGoes.Value = iCounta + 1
End With
Else
UserForm1.Label226 = Me.tbxUser.Value
' Sheet9.Range("B1").Value = Me.tbxUser.Value
UserForm1.Show
Unload Me
' UserForm1.Label226 = Sheet9.Range("B1").Value
End If
ElseIf iCounta > 2 Then
MsgBox "You have tried three time incorrectly. Hub Access Manager will now close the Hub.", vbOKOnly + vbExclamation, "Hub Access Manager: Closing"
ActiveWorkbook.Close SaveChanges:=False
End If
End Sub
Bookmarks