Hello AKRAMI,
I have modified your "Database" page to include a new column labeled "Locked". There is a cell for each user. If it is TRUE then the user can not login until the "Locked" cell has been changed back to TRUE. The user will be locked out after 3 failed attempts.
The Table on "Database" has three dynamic named ranges: Users, Passwords, and Locked. You can add or remove users from these lists and not have to modify the UserForm code. The attached workbook has all the changes made to it.
UserForm Code
Private Sub CommandButton1_Click()
Dim n As Integer
Dim pwd As String
Dim Tries As Integer
Tries = CInt(Label1.Caption)
n = ComboBox1.ListIndex
If n = -1 Then
Exit Sub
End If
If Range("Locked").Cells(n + 1, 1) = True Then
Label1.Caption = "3"
TextBox1.Value = ""
ComboBox1.Value = ""
ComboBox1.SetFocus
MsgBox "Your account has been locked. Please see the Administrator to have it unlocked.", vbOKOnly + vbCritical
Exit Sub
End If
pwd = Range("Passwords").Cells(n + 1, 1)
If TextBox1 = pwd Then
MsgBox "You are Logged In!"
Unload Me
Exit Sub
End If
Tries = Tries - 1
If Tries > 0 Then
Label1.Caption = Tries
TextBox1.Value = ""
TextBox1.SetFocus
Else
Range("Locked").Cells(n + 1, 1).Value = True
Label1.Caption = "3"
TextBox1.Value = ""
ComboBox1.Value = ""
ComboBox1.SetFocus
End If
End Sub
Private Sub UserForm_Initialize()
Label1.Caption = "3"
ComboBox1.RowSource = Range("Users").Address
End Sub
Bookmarks