Can someone please help me with my syntax below? I am trying to enable an object on a form for specific users only and in doing so I am trying to use the DLookUp function to try and keep it sweet and simple. I have created a table named “Employees” where I plan to add the people that will have access to the particular object (named CmdProjReport). The table is very basic just housing the below info:
Employees Table:
[HTML]
KeyID EmployeeID Name Phone
1 mibi Mike 7140
2 kluck Kath 3165
3 bobt Bob 5424
[/HTML]
Now I plane to execute the logic upon the loading of the form and I have come up with the below which as you can guess is not working. Can you help construct the below code to use the environments username and check to see if it exists in the Employees table and if so then enable the object? Any help would be greatly appreciated. (Not sure why I am having soooo much difficulty with the DLookUp syntax but I have tried everything I can think of and I can get it to work)
Thanks for the help
Birky
Employees Table:
[HTML]
KeyID EmployeeID Name Phone
1 mibi Mike 7140
2 kluck Kath 3165
3 bobt Bob 5424
[/HTML]
Now I plane to execute the logic upon the loading of the form and I have come up with the below which as you can guess is not working. Can you help construct the below code to use the environments username and check to see if it exists in the Employees table and if so then enable the object? Any help would be greatly appreciated. (Not sure why I am having soooo much difficulty with the DLookUp syntax but I have tried everything I can think of and I can get it to work)
Code:
Private Sub Form_Load() Dim PrimId As Variant PrimId = DLookup("[KeyId]","Employees","[EmployeeID]=Environ("username"") If PrimId = Null Then CmdProjReport.Visible = True End If End Sub
Thanks for the help
Birky
Comment