Error message..

doran_doran

Registered User.
Local time
Today, 14:56
Joined
Aug 15, 2002
Messages
349
Hi, I am using following code to verify user. It's working. But when user put a wrong password they get two error. Please open errors.zip to see those errors. picture 1 comes first then picture 2. for the first time when u click on picture 2 , the picture 1 pops up again and then picture 2. (so, 1 and 2 apprears twice)

Any idea why ??


Private Sub cmdOk_Click()
On Error GoTo Err_cmdOk_Click
'-----------------------------------------------------------------------------------------------------------------------------
' This code is used to validate users found in the tbl_admin table. If the wrong user name or password is
' provided access is denied.
'-----------------------------------------------------------------------------------------------------------------------------
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim rstV As Recordset
Dim stDocName As String
Dim stLinkCriteria As String
Dim varX As Variant

Set db = currentdb()
Set rst = db.OpenRecordset("tbl_Admin", dbOpenDynaset)
varX = DLookup("([InitialPassword])", "tbl_admin", "[UserID] = '" & Me!txtUser & "'")

If Not IsNull(Me.txtUser) And Not IsNull(Me.txtPassword) Then
rst.FindFirst "Password = '" & Me.txtPassword & "'" & " And UserID = '" & Me.txtUser & "'"
If rst.NoMatch Then
MsgBox "You entered the wrong User Name or Password." & Chr(13) & _
"Please enter the correct User Name and Password or " & Chr(13) & _
"contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied"

ElseIf Me.txtPassword = varX Then
MsgBox "This is the first time using this report or your passowrd has been reset." & Chr(13) & _
"You must change your password before you can continue.", _
vbOKOnly + vbExclamation, "Change Password"
stDocName = "frmUserLogonNew"
stLinkCriteria = "[UserID]=" & "'" & Me![txtUser] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
stDocName = "frmStartup"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Else
MsgBox "You left the User Name and/or Password blank." & Chr(13) & _
"Please enter the correct User Name and Password or " & Chr(13) & _
"contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied"
End If

With User
.AccessID = rst.Fields("AccessID")
.ViewID = rst.Fields("ViewID")
.Active = rst.Fields("Active")
.Password = rst.Fields("Password")
.SecurityID = rst.Fields("SecurityID")
.UserID = rst.Fields("UserID")
End With

rst.close

Exit_cmdOk_Click:
Exit Sub

Err_cmdOk_Click:
MsgBox Err.Description
Resume Exit_cmdOk_Click

End Sub
 

Attachments

doran,

Code:
Private Sub cmdOk_Click()
On Error GoTo Err_cmdOk_Click
'-----------------------------------------------------------------------------------------------------------------------------
' This code is used to validate users found in the tbl_admin table. If the wrong user name or password is
' provided access is denied.
'-----------------------------------------------------------------------------------------------------------------------------
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim rstV As Recordset
Dim stDocName As String
Dim stLinkCriteria As String
Dim varX As Variant

Set db = currentdb()
Set rst = db.OpenRecordset("tbl_Admin", dbOpenDynaset)
varX = DLookup("([InitialPassword])", "tbl_admin", "[UserID] = '" & Me!txtUser & "'")

If Not IsNull(Me.txtUser) And Not IsNull(Me.txtPassword) Then
   rst.FindFirst "Password = '" & Me.txtPassword & "'" & " And UserID = '" & Me.txtUser & "'"
   If rst.NoMatch Then
      MsgBox "You entered the wrong User Name or Password." & Chr(13) & _
             "Please enter the correct User Name and Password or " & Chr(13) & _
             "contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied"
      Exit Sub <---- Add This !!!!!
                     Otherwise goes to "This code right here !!!! (See below)
   ElseIf Me.txtPassword = varX Then
      MsgBox "This is the first time using this report or your passowrd has been reset." & Chr(13) & _
             "You must change your password before you can continue.", _
             vbOKOnly + vbExclamation, "Change Password"
      stDocName = "frmUserLogonNew"
      stLinkCriteria = "[UserID]=" & "'" & Me![txtUser] & "'"
      DoCmd.OpenForm stDocName, , , stLinkCriteria
   Else
      stDocName = "frmStartup"
      DoCmd.OpenForm stDocName, , , stLinkCriteria
   End If
Else
   MsgBox "You left the User Name and/or Password blank." & Chr(13) & _
          "Please enter the correct User Name and Password or " & Chr(13) & _
          "contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied"
   Exit Sub <---- Add This !!!!!
                  Otherwise goes to "This code right here !!!! (See below)
End If

'
' This code right here !!!!!!!
'

With User
.AccessID = rst.Fields("AccessID")
.ViewID = rst.Fields("ViewID")
.Active = rst.Fields("Active")
.Password = rst.Fields("Password")
.SecurityID = rst.Fields("SecurityID")
.UserID = rst.Fields("UserID")
End With

rst.close

Exit_cmdOk_Click:
Exit Sub

Err_cmdOk_Click:
MsgBox Err.Description
Resume Exit_cmdOk_Click

End Sub

Wayne
 
More Tune up

Now I only get the the real error message but twice when i leave the password blank or incorrect.

MsgBox "You left the User Name and/or Password blank." & Chr(13) & _
"Please enter the correct User Name and Password or " & Chr(13) & _
"contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied"


Wayne Thanks a lot for helping me.
 

Users who are viewing this thread

Back
Top Bottom