Please check Code
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 = "MES123") Or (user = "user" And password = "user") Then
Unload Me
Application.Visible = True
Else
If LoginInstance < 3 Then
MsgBox "Invalid login credentials. Please try again.", vbOKOnly + vbCritical, "Invalid Login Details"
LoginInstance = LoginInstance + 1
Else
MsgBox "You have exceeded the maximum number of login attempts.", vbOKOnly + vbCritical, "Invalid Credentials"
Unload Me
ThisWorkbook.Close Savechanges:=False
Application.Visible = True
LoginInstance = 0
End If
End If
End Sub
Private Sub cmdLogin_Enter()
End Sub
Private Sub Frame1_Click()
End Sub
Private Sub Image1_BeforeDragOver(ByVal Cancel As MSForms.ReturnBoolean, ByVal Data As MSForms.DataObject, ByVal X As Single, ByVal Y As Single, ByVal DragState As MSForms.fmDragState, ByVal Effect As MSForms.ReturnEffect, ByVal Shift As Integer)
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