Password at Login Form

G

Guest

Hi, Guys!

Good morning! I have difficulty making my login form work.
Problem: When an employee clocks in or out, he will input his employee
number in the employeenumber textbox. When he presses the Enter key, the
cursor will move to the passcode textbox where he will input his unique
passcode number. When he clicks the Clock In/Clock Out button, Access should
verify the if the employee number and passcode match. If it matched, a form
showing the employee's picture, name and position will display. He press the
Enter key twice and the form will close and go back to Login Form (his time
in/time out will be set by a macro called "time in". If he enters a wrong
passcode, a message box will appear telling him his passcode is wrong and
after 3 tries and still enters a wrong passcode, the application will
shutdown.

But something's wrong. Access just opens the form showing the employee's
name, picture and position no matter what passcode you input (although the
form contains the correct employee based on the employee number that was
entered in the login form). Meaning it doesn't verify if the passcode and the
employee number are match.
Below is my code and I hope someone could help me make it work:

Private Sub cmdLogIn_click()
On Error GoTo Err_cmdLogin_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "DTR AM"

stLinkCriteria = "[EmployeeNumber]=" & Me![EmployeeNumber]

If IsNull(Me.EmployeeNumber) Or Me.EmployeeNumber = "" Then
MsgBox "Please enter your Employee I.D.", vbOKOnly, "Require Data"
Me.EmployeeNumber.SetFocus
Exit Sub
End If

If IsNull(Me.Password) Or Me.Password = "" Then
MsgBox "Please enter your password.", vbOKOnly, "Required Data"
Me.Password.SetFocus
Exit Sub
End If

If Me.Password.Value = DLookup("Password", "Employees for Payroll",
"[EmployeeNumber]=" & Me.EmployeeNumber.Value) Then
EmployeeNumber = Me.Password.Value

DoCmd.Close acForm, "log in", acSaveNo
DoCmd.OpenForm stDocName, , , stLinkCriteria


Else
MsgBox "Sorry, but your password is invalid! Please try again",
vbOKOnly, "Invalid Password!"
Me.Password.SetFocus
End If

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "I am sorry, but the system cannot verify your identification.
Please contact your System Administrator.", vbCritical, "Unidentified user
was blocked!"
Application.Quit

End If
Exit_cmdLogin_Click:
Exit Sub

Err_cmdLogin_Click:
MsgBox Err.Description
Resume Exit_cmdLogin_Click


End Sub

Private Sub cmdLogOut_Click()
On Error GoTo Err_cmdLogOut_Click

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "DTR PM"
stLinkCriteria = "[EmployeeNumber]=" & Me![EmployeeNumber]

If IsNull(Me.EmployeeNumber) Or Me.EmployeeNumber = "" Then
MsgBox "Please enter your Employee I.D.", vbOKOnly, "Require Data"
Me.EmployeeNumber.SetFocus
Exit Sub
End If

If IsNull(Me.Password) Or Me.Password = "" Then
MsgBox "Please enter your password.", vbOKOnly, "Required Data"
Me.Password.SetFocus
Exit Sub
End If


If Me.Password.Value = DLookup("Password", "Employees for Payroll",
"[EmployeeNumber]=" & Me.EmployeeNumber.Value) Then
EmployeeNumber = Me.Password.Value

DoCmd.Close acForm, "log in", acSaveNo
DoCmd.OpenForm stDocName, , , stLinkCriteria


Else
MsgBox "Sorry, but your password is invalid! Please try again",
vbOKOnly, "Invalid Password!"
Me.Password.SetFocus
End If

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "I am sorry, but the system cannot verify your identification.
Please contact your System Administrator.", vbCritical, "Unidentified user
was blocked!"
Application.Quit

End If
Exit_cmdLogOut_Click:
Exit Sub

Err_cmdLogOut_Click:
MsgBox Err.Description
Resume Exit_cmdLogOut_Click


End Sub

Thank you very much in advance and God bless!
--
My sincerest thanks. . . and may the good Lord bless you always and give
you more knowledge and intelligence to share with us novice. Thank you very
much!

Resty A. Morales
 
C

chris.nebinger

Obviously, the problem would be in this section:

If Me.Password.Value = DLookup("Password", "Employees for Payroll",

"[EmployeeNumber]=" & Me.EmployeeNumber.Value) Then
EmployeeNumber = Me.Password.Value
DoCmd.Close acForm, "log in", acSaveNo
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
MsgBox "Sorry, but your password is invalid! Please try again",
vbOKOnly, "Invalid Password!"
Me.Password.SetFocus
End If


The easiest way is to put a break point (F9) and walk through it. The
only thing I see is to transpose these two lines:

DoCmd.Close acForm, "log in", acSaveNo
DoCmd.OpenForm stDocName, , , stLinkCriteria

to

DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, "log in", acSaveNo

Once you close the log in form, any code would stop as well. Let the
stDocName for be opened first.

Also, I don't understand the intention of this line:
EmployeeNumber = Me.Password.Value

Why would you be setting the employee number box to the password?


Chris Nebinger
 
G

Guest

Hi, Chris. Gooe evening!

First, I would like to thank you for your prompt reply. Thank you very much.
Anyway, as for your question " Why would you be setting the employee number
box to the password?", I want to check if the employee number entered into
the employee number field in login form matches with the passcode that I
assigned to that particular employee. Am I doing the right thing here?
Please advise me. Thank you very much!
--
My sincerest thanks. . . and may the good Lord bless you always and give
you more knowledge and intelligence to share with us novice. Thank you very
much!

Resty A. Morales
 
C

chris.nebinger

I would use the following code:

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "DTR PM"
stLinkCriteria = "[EmployeeNumber]=" & Me![EmployeeNumber]


If IsNull(Me.EmployeeNumber) Or Me.EmployeeNumber = "" Then
MsgBox "Please enter your Employee I.D.", vbOKOnly, "Require
Data"
Me.EmployeeNumber.SetFocus
Exit Sub
End If
If IsNull(Me.Password) Or Me.Password = "" Then
MsgBox "Please enter your password.", vbOKOnly, "Required Data"

Me.Password.SetFocus
Exit Sub
End If

If DCOUNT("Password","[Employees for Payroll]","Password =
"EmployeeNumber]=" & Me.EmployeeNumber.Value) & " AND Password = '" &
Me.Password.Value & "'") > 0 then
'Found a valid username & password combination....
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, "log in", acSaveNo

Else
MsgBox "Sorry, but your password is invalid! Please try again",
vbOKOnly, "Invalid Password!"
Me.Password.SetFocus
End If


Chris Nebinger
 
M

mcescheriowa

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then

if Bob botches his login twice, and then is successful, Dave will only have
one chance to login.

Chris M
mcescheriowa
 
C

chris.nebinger

Not necessarily. If the form is reinitialized, either on a different
computer or the form is closed & reopened (I assume it is a scoped in
the form), then intLogonAttempts will go back to 0. I would think this
would be discovered during user testing, or really quickly once it gets
distributed to the users.



Chris Nebinger
 
G

Guest

Hi guys! Thank you very much for the knowledge you just shared. Although my
previous code is working now (I am now testing it). All employees are using
my bundy clock now and so far I have no glitches....yet. To Chris, I have
corrected my error, you asked me "Also, I don't understand the intention of
this line:
EmployeeNumber = Me.Password.Value". It should have been
EmployeeNumber=Me.EmployeeNumber.Value.

All in all, I thank you all very much guys. I find Chris's code, your latest
answer to my post, more professional than the one i did. But I told myself
"Be original". So if something came up in the future I think I have to
replace my existing code with Chris's. Again, thank you very much guys and
God bless you always!

Resty

--
My sincerest thanks. . . and may the good Lord bless you always and give
you more knowledge and intelligence to share with us novice. Thank you very
much!

Resty A. Morales
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

SplitFormDatasheet property 6
Macro to VBA 20
Choose Form that Loads Based on Login 6
Passing Two Argument in OpenFrom 4
Filtering...I think 3
Password programming 4
Opening form using 2 criteria 9
Secure Login Form 4

Top