G
Guest
Thank you for taking the time to read my post regardless of whether you can
help or not.
I am trying to set up a user control form which will allow users to access
the application but only with the right registered password per user. Each
user has there own password, i am aware of how to set up controls and so on
for this and have created the code to make this work.
However there is a few enhancements i'd love to add.
1. Allows users only 3 attemps to try and login before the application closes.
2. As the user makes and error (enters the wrong password) a warning mesage
box appears telling them how many attempts they have left (each error means a
message box which counts down the number of attempts left)
I have tried to do "Loops" and "Do" btu am still a novice to vba.
Please find my code below as follows.
Private Sub btnLoginOk_Click()
If IsNull(txtUserName) Or txtUserName.Value = "" Then
MsgBox "Please enter your user name.", vbQuestion + vbOKOnly, "Campaign
Manager"
Exit Sub
End If
If IsNull(txtPassword) Or txtPassword.Value = "" Then
MsgBox "Please enter your password.", vbQuestion + vbOKOnly, "Campaign
Manager"
Exit Sub
End If
If DCount("[username]", "[tblUsers]", "[username]=txtUsername.Value") = 1 Then
currentuser = txtUserName.Value
If txtPassword = DLookup("[password]", "[tblUsers]",
"[username]=txtUsername.Value") Then
If DLookup("[inactive]", "[tblUsers]",
"[username]=txtUsername.Value") = True Then
MsgBox "Your account has been locked. Please contact the
administrator.", vbCritical + vbOKOnly, "Campaign Manager"
Else
DoCmd.OpenForm "frmMain"
With Application.Forms.frmMain.lblusernamewelcome
.Caption = "Welcome! " & UCase(Left(currentuser, 1)) &
Mid(currentuser, 2, 30)
End With
DoCmd.Close acForm, "frmLogin"
End If
Else
MsgBox "Password Incorrect! Please Try Again...", vbCritical + vbOKOnly,
"Campaign Manager"
End If
Else
MsgBox "The specified user name does not exist!", vbExclamation + vbOKOnly,
"Campaign Manager"
End If
End Sub
help or not.
I am trying to set up a user control form which will allow users to access
the application but only with the right registered password per user. Each
user has there own password, i am aware of how to set up controls and so on
for this and have created the code to make this work.
However there is a few enhancements i'd love to add.
1. Allows users only 3 attemps to try and login before the application closes.
2. As the user makes and error (enters the wrong password) a warning mesage
box appears telling them how many attempts they have left (each error means a
message box which counts down the number of attempts left)
I have tried to do "Loops" and "Do" btu am still a novice to vba.
Please find my code below as follows.
Private Sub btnLoginOk_Click()
If IsNull(txtUserName) Or txtUserName.Value = "" Then
MsgBox "Please enter your user name.", vbQuestion + vbOKOnly, "Campaign
Manager"
Exit Sub
End If
If IsNull(txtPassword) Or txtPassword.Value = "" Then
MsgBox "Please enter your password.", vbQuestion + vbOKOnly, "Campaign
Manager"
Exit Sub
End If
If DCount("[username]", "[tblUsers]", "[username]=txtUsername.Value") = 1 Then
currentuser = txtUserName.Value
If txtPassword = DLookup("[password]", "[tblUsers]",
"[username]=txtUsername.Value") Then
If DLookup("[inactive]", "[tblUsers]",
"[username]=txtUsername.Value") = True Then
MsgBox "Your account has been locked. Please contact the
administrator.", vbCritical + vbOKOnly, "Campaign Manager"
Else
DoCmd.OpenForm "frmMain"
With Application.Forms.frmMain.lblusernamewelcome
.Caption = "Welcome! " & UCase(Left(currentuser, 1)) &
Mid(currentuser, 2, 30)
End With
DoCmd.Close acForm, "frmLogin"
End If
Else
MsgBox "Password Incorrect! Please Try Again...", vbCritical + vbOKOnly,
"Campaign Manager"
End If
Else
MsgBox "The specified user name does not exist!", vbExclamation + vbOKOnly,
"Campaign Manager"
End If
End Sub