Quote from KjBox;703418Display More
OK here it is back (but not wrong now! )
You need to store the number of attempts in something other than a variable. The easiest way to do that is have another textbox on the form with visibility property set to False and a value of 2
Then refer to that textbox value rather than a variable (the value reduces by 1 after each failed attempt at logging in).
Private Sub CommandButton1_Click() Dim sUserid, sPassword, sSearchID As String Dim rIdPwd As Range sUserid = Useridtextbox sPassword = Passwordtextbox sSearchID = sUserid & " " & sPassword Label1.Visible = False Label2.Visible = False If sUserid = vbNullString Then Label1.Visible = True: Exit Sub ElseIf sPassword = vbNullString Then Label2.Visible = True: Exit Sub End If With Sheets("User Master File Records").Range("a:a") Set rIdPwd = .Find(What:=sSearchID, LookIn:=xlValues, lookat:=xlWhole) End With If Not rIdPwd Is Nothing Then MsgBox "access granted" 'Your code here to do whatever if access granted Unload Me Else MsgBox "Access denied, You have " & tbCnt & " attempt(s) left until the system closes" Useridtextbox = vbNullString Passwordtextbox = vbNullString tbCnt = tbCnt - 1 End If If tbCnt = -1 Then MsgBox "bye" 'Your code here to do whatever if access denied Unload Me End If End Sub
I am attaching a working sample.
Good Day Sir/Maam,specially to Sir KJBOX,
Can i ask if how i know the Username and Password of this code?
If there is no declared user and pass here,then how to put user and pass in this code?