473,416 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

DLookUp Function Issues

52
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
Aug 24 '07 #1
3 1888
dima69
181 Expert 100+
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
Aug 24 '07 #2
Jim Doherty
897 Expert 512MB
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
Aug 24 '07 #3
Birky
52
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
Aug 24 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: KLAU | last post by:
I have a field that retrieves information from an expression in a query. I have used a DLookup function to get the calculated field from the query. However, the relationship is 1-to-many so one...
1
by: MUHAMAMD SALIM SHAHZAD | last post by:
dear sir, i would like to get your assitance about the above issues, can't find any better slutions or codes - table name: MOTOR2000 - field name1: POLICYNO - field name2: ExPolicyNo i...
3
by: Tripp Knightly | last post by:
I have a lookup table from which I want to categorize various bands of customer net income. Some of the income is positive, some is negative. The bands vary in size (ie, <500, -200 to 0, 100 to...
6
by: Don Sealer | last post by:
I've written this expression for a DLookup function. It works almost alright. What I'm trying to do is type in a description and the ID field (number) populates automatically. It works almost as...
2
by: Don | last post by:
Can someone help me fix my DLookup problem. I'm far from proficiency with Access. I've been creating databases for several years for work with the help of many of you and trial and error. I have...
1
by: Parasyke | last post by:
I have a form (I won't bore you with the details of the necessity of this, but), I need to have a textbox that uses DLookup to get a value from a table with both being keyed to a common field...
2
by: RoadrunnerII | last post by:
Hi All I am new to this forum and still learning MS Access. Hoping this is the right place to ask If not please let me know! Looking for some help with the SQL statements in Access 2003 with the...
2
by: Denise | last post by:
Front end is Access 2002, back end is linked Oracle tables. My users need to describe things in feet and inches and want to use the standard ' and " abbrevations. On a testing form I go to a...
7
Breezwell
by: Breezwell | last post by:
This is probably a simple question for someone out there. I understand that the DLookup function takes has the following syntax: DLookup(expression,domain,) From what I have read, domain can...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.