Login form user name and password

G

Guest

I have login form with user name and password. Currently my code works if i
enter correct password and user name it will open form and if password or
name name or both is not valid then it will open msgbox. What i am looking
for is
saperate msgbox for password and user, if user name correct but password not
then i need show msgbox "invalid password" and same thing for user name.
Also if both incorrect then msgbox
"Invalid password a and user name". Please help me out. Thanks.

===============
Private Sub cmdLogin_Click()
On Error GoTo Err_cmdLogin_click

Dim rs As DAO.Recordset
Dim strDesk As String
Dim strPassword As String
Dim stDocName As String
Dim stLinkCriteria As String
Dim strSQL As String

txtDesk.SetFocus
strDesk = txtDesk
txtPassword.SetFocus
strPassword = txtPassword
If Not IsNull(Me.txtDesk) And Not IsNull(Me.txtPassword) Then
Set rs = CurrentDb.OpenRecordset("Select * From tblUsers Where Desk =
'" & strDesk & "' and Password = '" & strPassword & "'", dbOpenSnapshot)
End If

If Not rs.EOF Then
stDocName = "frmMain"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

If rs.EOF Then
MsgBox "Invalid Desk Number and Password. Please try again.",
vbCritical, "Invalid Desk Number and Password"
txtDesk = Null
txtPassword = Null
txtDesk.SetFocus
End If
rs.Close
Set rs = Nothing

Exit_cmdLogin_click:
Exit Sub
Err_cmdLogin_click:
MsgBox Err.Description
Resume Exit_cmdLogin_click
End Sub
 
G

Guest

Try something like

'Open record set on the user name only

Set rs = CurrentDb.OpenRecordset("Select * From tblUsers Where Desk =
'" & strDesk & "'", dbOpenSnapshot)
If Not rs.EOF Then
If rs!Password = strPassword Then
stDocName = "frmMain"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
MsgBox "Invalid Password"
End If
Else
MsgBox "Invalid User Name"
End If
 
G

Guest

If password correct but user not then i see two msgboxes 'invalid user name'
and 'invalid user name and password' and same thing if both not correct. What
should i change to view only one msgbox?
===========================

Private Sub cmdLogin_Click()
On Error GoTo Err_cmdLogin_click

Dim rs As DAO.Recordset
Dim strDesk As String
Dim strPassword As String
Dim stDocName As String
Dim stLinkCriteria As String
Dim strSQL As String

txtDesk.SetFocus
strDesk = txtDesk
txtPassword.SetFocus
strPassword = txtPassword

Set rs = CurrentDb.OpenRecordset("Select * From tblUsers Where Desk ='" &
strDesk & "'", dbOpenSnapshot)
If Not rs.EOF Then
If rs!Password = strPassword Then
stDocName = "frmMain"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
MsgBox "Invalid Password"
End If
Else
MsgBox "Invalid User Name"
End If

If rs.EOF Then
MsgBox "Invalid Desk Number and Password. Please try again.",
vbCritical, "Invalid Desk Number and Password"
txtDesk = Null
txtPassword = Null
txtDesk.SetFocus
End If

rs.Close
Set rs = Nothing
Exit_cmdLogin_click:
Exit Sub
Err_cmdLogin_click:
MsgBox Err.Description
Resume Exit_cmdLogin_click
End Sub
==============================
 
G

Guest

If password correct but user not then i see two msgboxes 'invalid user name'
and 'invalid user name and password' and same thing if both not correct. What
should i change to view only one msgbox?
===========================

Private Sub cmdLogin_Click()
On Error GoTo Err_cmdLogin_click

Dim rs As DAO.Recordset
Dim strDesk As String
Dim strPassword As String
Dim stDocName As String
Dim stLinkCriteria As String
Dim strSQL As String

txtDesk.SetFocus
strDesk = txtDesk
txtPassword.SetFocus
strPassword = txtPassword

Set rs = CurrentDb.OpenRecordset("Select * From tblUsers Where Desk ='" &
strDesk & "'", dbOpenSnapshot)
If Not rs.EOF Then
If rs!Password = strPassword Then
stDocName = "frmMain"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
MsgBox "Invalid Password"
End If
Else
MsgBox "Invalid User Name"
End If

If rs.EOF Then
MsgBox "Invalid Desk Number and Password. Please try again.",
vbCritical, "Invalid Desk Number and Password"
txtDesk = Null
txtPassword = Null
txtDesk.SetFocus
End If

rs.Close
Set rs = Nothing
Exit_cmdLogin_click:
Exit Sub
Err_cmdLogin_click:
MsgBox Err.Description
Resume Exit_cmdLogin_click
End Sub
==============================
 
A

AccessVandal via AccessMonster.com

How about this way?

Set rs = CurrentDb.OpenRecordset("Select * From tblUsers Where Desk =
'" & strDesk & "' and Password = '" & strPassword & "'", dbOpenSnapshot)

If rs.EOF Then
MsgBox "Invalid Desk Number and Password. Please try again.",
vbCritical, "Invalid Desk Number and Password"
txtDesk = Null
txtPassword = Null
txtDesk.SetFocus
elseIf Not rs.EOF Then
stDocName = "frmMain"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
 
G

Guest

What about if only password or name incorrect. I whould like to see different
msgbox. Some thing like this:
If txtUser = "admin" And txtPassword = "manager" Then
stDocName = "frmMain"
DoCmd.OpenForm stDocName, , , stLinkCriteria
end if
If (Not txtUser = "admin" And Not txtPassword = "manager") Then
MsgBox "Invalid User Number and Password. Please try again.",
vbCritical, "Invalid Desk Number and Password"
txtUser = Null
txtPassword = Null
txtUser.SetFocus
End If

If Not (txtUser = "admin") And (txtPassword = "manager") Then
MsgBox "Invalid User Number. Please try again.", vbCritical, "Invalid
Desk Number"
txtUser = Null
txtDesk.SetFocus

End If
If Not (txtPassword = "manager") And (txtUser = "admin") Then
MsgBox "Invalid Password. Please try again.", vbCritical, "Invalid
Password"
txtPassword = Null
txtPassword.SetFocus
End If
----------
This code workes fine but i can make work exactly same way if i am pulling
data from table


AccessVandal via AccessMonster.com said:
How about this way?

Set rs = CurrentDb.OpenRecordset("Select * From tblUsers Where Desk =
'" & strDesk & "' and Password = '" & strPassword & "'", dbOpenSnapshot)

If rs.EOF Then
MsgBox "Invalid Desk Number and Password. Please try again.",
vbCritical, "Invalid Desk Number and Password"
txtDesk = Null
txtPassword = Null
txtDesk.SetFocus
elseIf Not rs.EOF Then
stDocName = "frmMain"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
---
 

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

MsgBox 3
Password login code 12
Match User Name and Password from Access table 2
Match UserNm and Password from table 2
Login form 2
Filtering...I think 3
How to hide password? 1
Input box question 2

Top