Hello,
This may get a little long but I want to explain what my goal is and what I have tried so far.
GOAL.
I am trying to set it up so users can only see records that belong to their department (Tax can only see TAX records) when they are performing a search. I thought an easy way to do this was by creating a login and a password type setup in my search form. Where the department selection would be the User Name and the UserID would be the password. This works as long as I only have a person tied to one department. The problem comes in when I set a up a person that should have access to more than one departments records (TAX and Accounting).
CODE.
I am using
Code:
UserID = VBA.Environ("username")
to obtain the users name in the text box "txtUserId"
This is the code I am using to make sure the UserId and UserDepartment match.
Code:
Dim MyEmpID As Variant
'Check value of UserName in tblEmployees to see if this matches value chosen in combo box
If Me.txtUserId.Value = DLookup("UserName", "tblEmployees", "[EmpID]=" & Me.cmbUdpart.Value) Then
MyEmpID = Me.cmbUdpart.Value
'Close logon form and open splash screen
DoCmd.OpenForm "MainFrm"
Else
MsgBox "Wrong Department", vbCritical + vbOKOnly, "Invalid Entry!"
Me.txtUserId.SetFocus
TABLE.
Here is tblEmployees

My thinking is that each UserDeparment would have its own EmpID so Accounting = 1, RIM = 2, and TAX = 3 and so on. On my form the UserId text box is auto filled with the Department selection being a drop down box of the UserDepartment and EmpID rows in this table.
THE ERROR MSG.
If I say the User ID is fvwinch and select Accounting for the department, I have no problems and when I debug I see MyEmpID = 1 and Me.cmbUdpart.Value = 1. Now if I select RIM with fvwinch get the msg "wrong department' and in debuging I see MyEmpID = Empty and Me.cmbUdpart.Value = 1.
This driving me crazy so any help here is very much appreciated.