FindFirst not finding first login/password attempt

G

Guest

I have a user login form with the following code. When a user logs in the
first time, the menu items are not activated as they should be, it's seems
like the code cannot find the user the first time. If the user exits back to
the main login form and reenters their password a second time, it works. This
appears to happen for each user. I am not sure why. This is code that I got
from an example on this site (a link) The module behind this just gets the
current user using FOSusername. That part works fine.
I think it's something in the findfirst that isn't finding the right user.
Just not sure.

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim rstV As Recordset
Dim stDocName As String
Dim stlinkCriteria As String

Set db = currentdb()
Set rst = db.OpenRecordset("tblSecurity", dbOpenDynaset)
'If Not IsNull(Me.txtUser) And Not IsNull(Me.txtPassword) Then
' rst.FindFirst "Password = '" & Me.txtPassword & "'" & " And UserID
= '" & Me.txtUser & "'"

If IsNull(Me.txtUser) = False And IsNull(Me.txtPassword) = False 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"
Me.txtPassword.Undo
Me.txtPassword.SetFocus

ElseIf Me.txtPassword = "password" Then
MsgBox "This is the first time using the database or your
password has been reset." & Chr(13) & _
"Please change your password to enter the database.", _
vbOKOnly + vbExclamation, "Change Password"
stDocName = "frmUserLogonNew"
stlinkCriteria = "[UserID]=" & "'" & Me![txtUser] & "'"
DoCmd.OpenForm stDocName, , , stlinkCriteria

Else

DoCmd.Close acForm, "frmUserLogon"
DoCmd.Close acForm, "frmUserLogonNew"

stDocName = "fmnuMainMenu"
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")
.EmployeeID = rst.Fields("EmployeeID")
.EmpFirst = rst.Fields("EmpFirst")
.EmpLast = rst.Fields("EmpLast")
.FullName = rst.Fields("FullName")


This is just a simple front end for an app that is split into FE/BE, FE is
an mde which the users will have locally.

Thanks for any help!
 
W

Wayne Morgan

I suspect that these are unbound controls. You are using the data typed in
them just for your code. The Undo statement further makes me suspicious.

After the user types in the user name and password, what do they do to
continue? When the textbox loses the focus, it will Update and the text that
has been typed in will go from being the Text property to being the Value
property of the textbox. If the control is unbound, you can Undo the control
prior to it updating, but not after it updates. So, if the Undo statement is
working then the password textbox hasn't updated. If the password textbox
hasn't updated then its value is probably Null.

I would recommend stepping through the code or adding some Debug.Print
statements in the code to find what the value is that is being retrieved
from the textboxes.

--
Wayne Morgan
MS Access MVP


Rita said:
I have a user login form with the following code. When a user logs in the
first time, the menu items are not activated as they should be, it's seems
like the code cannot find the user the first time. If the user exits back
to
the main login form and reenters their password a second time, it works.
This
appears to happen for each user. I am not sure why. This is code that I
got
from an example on this site (a link) The module behind this just gets the
current user using FOSusername. That part works fine.
I think it's something in the findfirst that isn't finding the right user.
Just not sure.

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim rstV As Recordset
Dim stDocName As String
Dim stlinkCriteria As String

Set db = currentdb()
Set rst = db.OpenRecordset("tblSecurity", dbOpenDynaset)
'If Not IsNull(Me.txtUser) And Not IsNull(Me.txtPassword) Then
' rst.FindFirst "Password = '" & Me.txtPassword & "'" & " And UserID
= '" & Me.txtUser & "'"

If IsNull(Me.txtUser) = False And IsNull(Me.txtPassword) = False 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"
Me.txtPassword.Undo
Me.txtPassword.SetFocus

ElseIf Me.txtPassword = "password" Then
MsgBox "This is the first time using the database or your
password has been reset." & Chr(13) & _
"Please change your password to enter the database.", _
vbOKOnly + vbExclamation, "Change Password"
stDocName = "frmUserLogonNew"
stlinkCriteria = "[UserID]=" & "'" & Me![txtUser] & "'"
DoCmd.OpenForm stDocName, , , stlinkCriteria

Else

DoCmd.Close acForm, "frmUserLogon"
DoCmd.Close acForm, "frmUserLogonNew"

stDocName = "fmnuMainMenu"
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")
.EmployeeID = rst.Fields("EmployeeID")
.EmpFirst = rst.Fields("EmpFirst")
.EmpLast = rst.Fields("EmpLast")
.FullName = rst.Fields("FullName")


This is just a simple front end for an app that is split into FE/BE, FE is
an mde which the users will have locally.

Thanks for any help!
 

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

Can someone check my code? 2
Parameter error box 3
username and password form 3
Login form user name and password 6
password form not working need help 2
Syntax error 6
Secure Login Form 4
Filtering...I think 3

Top