I am trying to create a TempVars that holds the “Permission” Variable for use in code when opening forms etc. After watching numerous YouTube videos I managed to create a log in screen and save the rs variable as TempVars “CurrentUserID” that all works fine so thought it would be fairly simple task to copy the code that works parrot fashion, change a few names to create a TempVars “UserPermission” but I just cant get it to work. I confess I have very little understanding of code and have tried several things with no success.
Any help appreciated.
Code:
Private Sub btnLogIn_Click()
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("tbl_Emp_Details", dbOpenSnapshot, dbReadOnly)
rs.FindFirst "User_Name='" & Me.txtUserName & "'"
Dim ap As Recordset
Set ap = CurrentDb.OpenRecordset("tbl_Emp_Details", dbOpenSnapshot, dbReadOnly)
ap.FindFirst "Emp_ID='" & Me.txtUserID & "'"
If rs.NoMatch = True Then
Me.labWrongUser.Visible = True
Me.txtUserName.SetFocus
Exit Sub
End If
Me.labWrongUser.Visible = False
If rs!User_Password <> Nz(Me.txtPassword, "") Then
Me.LabWrongPW.Visible = True
Me.txtPassword.SetFocus
Exit Sub
End If
TempVars.Add "CurrentUserID", Me.txtUserID.Value
'MsgBox TempVars![currentUserID]
TempVars.Add "UserPermission", Me.txtPermission.Value
'MsgBox TempVars![UserPermission]
Me.LabWrongPW.Visible = False
DoCmd.OpenForm "frm_Index_Main"
DoCmd.Close acForm, "frm_Login"
End Sub
.