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!
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!