mistyinca1970
Member
- Local time
- Yesterday, 18:56
- Joined
- Mar 17, 2021
- Messages
- 117
OK, I have a login form that uses recordset to validate the associated password entered into the login form.
I have been using this information entered to capture TempVars that will be used throughout the many forms in this DB. Up until now, it set the useraccess of the person who logged in and uses their email address via TempVars in any send email functions.
I'm going to be expanding the use of this database to multiple divisions in my org. And I only want certain records in various queries to be available to users who login with that respective division. So division is a column in the main table (tblContracts), and I am using it as a criteria in the query that is the data for one of the main forms.
Currently, I'm accomplishing this by having a combo box on the login form so the user can select his/her division. But that is really not the way I want to go. I would prefer it to find the corresponding division associated with that user and set it as a TempVars...then that TempVars will be the criteria in my query for the data associated with the form.
Anyway, here's my login form's login button on click event:
And here is the recordset (qryLoginAccess) being called in this one:
(********** concatenated password removed here for security reasons)
So I want it to find the division associated with the email address of the user that logs in and set the TempVars off that. I don't know how to write this. I can't necessarily copy the password validation process as it is asking to see if the password entered matches the password associated with the username entered (email address). How do I tell it to find the division and set that TempVars?
Thank you,
EDIT:
Shoot! Why is it when I type it out and ask for help, I then see the answer? I think this is it here:
So I would use
Gonna go try it out.
I have been using this information entered to capture TempVars that will be used throughout the many forms in this DB. Up until now, it set the useraccess of the person who logged in and uses their email address via TempVars in any send email functions.
I'm going to be expanding the use of this database to multiple divisions in my org. And I only want certain records in various queries to be available to users who login with that respective division. So division is a column in the main table (tblContracts), and I am using it as a criteria in the query that is the data for one of the main forms.
Currently, I'm accomplishing this by having a combo box on the login form so the user can select his/her division. But that is really not the way I want to go. I would prefer it to find the corresponding division associated with that user and set it as a TempVars...then that TempVars will be the criteria in my query for the data associated with the form.
Anyway, here's my login form's login button on click event:
Code:
Private Sub btnLogin_Click()
Dim rs As DAO.Recordset
Dim db As Database
Set db = CurrentDb
Set rs = db.OpenRecordset("qryLoginAccess", dbOpenSnapshot, dbReadOnly)
rs.FindFirst "Username='" & Me.txtUserName & "'"
If rs.NoMatch = True Then
Me.lblIncorrectLogin.Visible = True
Me.txtUserName.SetFocus
Exit Sub
End If
Me.lblIncorrectLogin.Visible = False
If rs!Password <> Me.txtPassword Then
Me.lblIncorrectLogin.Visible = True
Me.txtPassword.SetFocus
Exit Sub
End If
Me.lblIncorrectLogin.Visible = False
TempVars("UserType") = rs!UserAccess_ID.Value
TempVars("EmailAddress") = Me.txtUserName.Value
TempVars("UserDivision") = Me.cboDivision.Value
If rs!UserAccess_ID = 1 Then
Dim prop As Property
On Error GoTo SetProperty
Set prop = CurrentDb.CreateProperty("AllowBypassKey", dbBoolean, False)
CurrentDb.Properties.Append prop
End If
SetProperty:
DoCmd.OpenForm "frmUpcomingContracts"
DoCmd.Close acForm, Me.Name
End Sub
And here is the recordset (qryLoginAccess) being called in this one:
Code:
SELECT tblStaffDivision.ID, tblStaffDivision.Email AS Username, ********* AS [Password], tblStaffDivision.UserAccess_ID, *********** AS Password2, tblStaffDivision.Division
FROM tblStaffDivision
ORDER BY tblStaffDivision.Staff;
So I want it to find the division associated with the email address of the user that logs in and set the TempVars off that. I don't know how to write this. I can't necessarily copy the password validation process as it is asking to see if the password entered matches the password associated with the username entered (email address). How do I tell it to find the division and set that TempVars?
Thank you,
EDIT:
Shoot! Why is it when I type it out and ask for help, I then see the answer? I think this is it here:
Code:
TempVars("UserType") = rs!UserAccess_ID.Value
So I would use
Code:
TempVars("UserDivision")=rs!StaffDivision.Division
Gonna go try it out.
Last edited: