Connecting Tech Pros Worldwide Forums | Help | Site Map

DLookUp Function Issues

Member
 
Join Date: Dec 2006
Posts: 52
#1: Aug 24 '07
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)

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     Dim PrimId As Variant
  3.  
  4.     PrimId = DLookup("[KeyId]","Employees","[EmployeeID]=Environ("username"")
  5.  
  6.     If PrimId = Null Then
  7.         CmdProjReport.Visible = True
  8.     End If
  9. End Sub
  10.  

Thanks for the help
Birky

dima69's Avatar
Expert
 
Join Date: Sep 2006
Location: Israel
Posts: 181
#2: Aug 24 '07

re: DLookUp Function Issues


Quote:

Originally Posted by Birky

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)

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     Dim PrimId As Variant
  3.  
  4.     PrimId = DLookup("[KeyId]","Employees","[EmployeeID]=Environ("username"")
  5.  
  6.     If PrimId = Null Then
  7.         CmdProjReport.Visible = True
  8.     End If
  9. End Sub
  10.  

Thanks for the help
Birky


If PrimId = Null expression will never act as TRUE, because (Null = Null) = Null.
To execute the command when PrimeId is Null, use this syntax:
Expand|Select|Wrap|Line Numbers
  1. If IsNull(PrimId) Then
  2.     CmdProjReport.Visible = True
  3. End If
Jim Doherty's Avatar
Moderator
 
Join Date: Aug 2007
Location: Derbyshire,England
Posts: 639
#3: Aug 24 '07

re: DLookUp Function Issues


Quote:

Originally Posted by Birky

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)

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     Dim PrimId As Variant
  3.  
  4.     PrimId = DLookup("[KeyId]","Employees","[EmployeeID]=Environ("username"")
  5.  
  6.     If PrimId = Null Then
  7.         CmdProjReport.Visible = True
  8.     End If
  9. End Sub
  10.  

Thanks for the help
Birky


Altered to suit it will work now

Jim

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     Dim PrimId As Variant
  3.     Dim strusername As String
  4.     strusername = Environ("USERNAME")
  5.  
  6.     PrimId = DLookup("[KeyId]", "Employees", "[EmployeeID]='" & strusername & "'")
  7.  
  8.     If IsNull(PrimId) Then
  9.         cmdProjReport.Visible = True
  10.     End If
  11.  
  12. End Sub
Member
 
Join Date: Dec 2006
Posts: 52
#4: Aug 24 '07

re: DLookUp Function Issues


You all are life savers, and thanks for helping me out with this one. As you can see I have a lot to learn and I’m thankful you all are willing to teach.

Have a great weekend..
Birky
Reply