Private Sub cmbValidate_Click()
Dim FindR As Range
Dim FindR2 As Range
On Error Resume Next
Set FindR = Sheet9.Range("D").Find(What:=UserForm2.tbxUser.Value, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext)
Set FindR2 = Sheet9.Range("E").Find(What:=UserForm2.tbxPW.Value, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext)
On Error GoTo 0
Dim sMsg As String, sTitle As String, sStyle As String
Dim iCounta As Integer
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
Sheet9.Range("B1").Value = UserForm2.tbxUser.Value
Unload Me
UserForm1.Show
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
I am using the above code to password-protect UserForm1 by using UserForm2. Although I know these password protect systems are easily surpassed I need some level of protection in the UserForm as it contains confidential information and it's been requested from a higher level.
I have highlighted in red where I am encountering the dreaded [91] error "Object variable or With block variable no set".
Simply put, I have a small range of Usernames and Passwords in range D:E (D being Usernames, E being passwords). I want the password checker to search through the Usernames and passwords and if the relevant Username and Password entered by the user isn't found then I want them to be notified and they have 2 further attempts. After the third attempt the program will simply exit. If they enter a correct Username and Password combination, then they are directed to UserForm1.
The code above worked like a dream for the counter (which advises the user which try they are on) and for putting a "Logged in as: XXX" message on UserForm1 once successfully entered however only for a singular set Username/Password. Short of giving every one of the expected 300 or so users of this program a copy of their own and changing every bit of code for each user, is there anyway I can edit the above code to make it work?
Many thanks in advance for any help.
For your ease of helping, please find a copy of the workbook via the link below - please ignore all the random details in each of the sheets, only the UserForm is important 
http://www.nippyzip.com/uploads/080519105604-01993.zip
~Liam
Bookmarks