hello,
im using the following code for a form for user login credentials. i would like to:
1) extend the form for multi users - so i can add a user 'abc' (password: 123), 'def' (password: 456) etc
and
2) allow a user 3 attempts to input correct password failing which the file should close.
many thanks,
skf
im using the following code for a form for user login credentials. i would like to:
1) extend the form for multi users - so i can add a user 'abc' (password: 123), 'def' (password: 456) etc
and
2) allow a user 3 attempts to input correct password failing which the file should close.
many thanks,
skf
VBA Code:
Option Explicit
Private Sub cmdClear_Click()
Me.txtUserID.Value = ""
Me.txtPassword.Value = ""
Me.txtUserID.SetFocus
'Code to exit- Please remove the comments if you want to use it exit
' Unload Me
' ThisWorkbook.Close Savechanges:=False
' Application.Visible = True
End Sub
Private Sub cmdLogin_Click()
Dim user As String
Dim password As String
user = Me.txtUserID.Value
password = Me.txtPassword.Value
If (user = "admin" And password = "admin") Then
Unload Me
Application.Visible = True
Else
MsgBox "Invalid Credentials"
Unload Me
ThisWorkbook.Close Savechanges:=False
Application.Visible = True
End If
End Sub
Private Sub Image1_Click()
End Sub
Private Sub UserForm_Initialize()
Me.txtUserID.Value = ""
Me.txtPassword.Value = ""
Me.txtUserID.SetFocus
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then Cancel = True
End Sub