Login Help!

K

kay

Thanks in advance for your time and help.
I have created Login form. But My code is not working. When I click on Login
button, the control goes to On Error GoTo Err_LoginButton_Click
I dont know whats wrong with the code:
here is the code:
Private Sub LoginButton_Click()

On Error GoTo Err_LoginButton_Click

Dim rs As DAO.Recordset
Dim strUser As String
Dim strPassword As String

txtEmpID.SetFocus
strUser = txtEmpID
txtEmpPass.SetFocus
strPassword = txtEmpPass

Set rs = CurrentDb.OpenRecordset("Select EmpID, EmpPassword from tblEmpID
where EmpID = " & strUser & " And EmpPassword = " & strPassword & " ",
dbOpenSnapshot)
If rs.EOF Then
DoCmd.OpenForm "frmTrackingV2"

Else
MsgBox "Password Invalid"
Me.txtEmpPass.SetFocus

End If

Exit_LoginButton_Click:
Exit Sub

Err_LoginButton_Click:
MsgBox "Code is not working"
MsgBox Err.Description
MsgBox Err.HelpFile
MsgBox Err.HelpContext
Resume Exit_LoginButton_Click

End Sub
 
J

J_Goddard via AccessMonster.com

Hi -

Your error is here:

Set rs = CurrentDb.OpenRecordset("Select EmpID, EmpPassword from tblEmpID
where EmpID = " & strUser & " And EmpPassword = " & strPassword & " ",
dbOpenSnapshot)

Because strUser and strPassword are both strings, they must be delimited by
single or double quotes in the recordset SQL. Using single quotes, this
becomes:

Set rs = CurrentDb.OpenRecordset("Select EmpID, EmpPassword from tblEmpID
where EmpID = '" & strUser & "' And EmpPassword = '" & strPassword & "' ",
dbOpenSnapshot)



Also, in this code:

If rs.EOF Then
DoCmd.OpenForm "frmTrackingV2"
Else
MsgBox "Password Invalid"
Me.txtEmpPass.SetFocus
End If

Are you sure your logic is sound here? You are opening the form if the
Username/Password is NOT found - you want it the other way around, surely?

HTH

John

p.s. What was the error message you were getting in debug.print err.
description?
 
D

Daniel Pineault

To troubleshoot the error simply comment out the

On Error GoTo Err_LoginButton_Click

line. Then rerun and it will highlight the line that is causing the error.

I suspect you have a fault in your SQL statement
"Select EmpID, EmpPassword from tblEmpID
where EmpID = " & strUser & " And EmpPassword = " & strPassword & " "

I think you need to add ' around the password, something more like:
"Select EmpID, EmpPassword from tblEmpID
where EmpID = " & strUser & " And EmpPassword = '" & strPassword & "'"

Try it out and post back if you need further help.
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.
 
K

kay

Thank you very much .its working after putting single quotes .
Now moving ahead, I have created 'AddNewUser' button on main form
("frmTrackingV2").
here what I want to do if EmpID has EmpRole = "AdminLevel" then AddNewUser
button should become visible on main form so manager can enter new user but
if EmpRole = UserLeval then user should not see this button.

any help on this please.
thanks
 

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

Top