MsgBox

G

Guest

If password correct but user not then i see 2 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 for each incorrect data?
===========================

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
==============================
 
C

Crystal

Delete this statement

MsgBox "Invalid Desk Number and Password. Please try
again.", vbCritical, "Invalid Desk Number and Password"


Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 
G

Guest

If i delete this statement then i will not able to show msgbox "Invalid Desk
Number and Password. Please try again." if both incorrect? ......
 
C

Crystal

It will never happen that way -- your recordset is already
filtered for Desk and if it is at the EOF, then Desk was not
found and you will have already given the user a message to
that effect.

Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 

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


Top