Solved

Problem with DLookup/null records in Access Project

Posted on 2003-12-02
3
385 Views
Last Modified: 2012-08-13
I'm working on an Access Project using SQL Server 7 database.
I'm having a problem with the DLookup function.

Here is an example of my problem:

sExpr = "CASE WHEN [FirstName]=NULL THEN 'No First Name' ELSE [FirstName] END"
sResult = DLookup(sExpr, "Network", "NetworkID=18436")

If FirstName record is null, it returns:
  Error:
  Run-time error '94':
  Invalid use of Null

If FirstName record is not null:
  sResult = 'Rob'
-----------------
If I change the expression syntax to:
sExpr = "CASE WHEN [FirstName]<>NULL THEN [FirstName] ELSE 'No First Name' END"
sResult = DLookup(sExpr, "Network", "NetworkID=18436")

If FirstName record is null:
sResult = 'No First Name'

If FirstName record is not null:
sResult = NULL
** I need this to return the value of [FirstName] if it is not null! **

Can somebody tell me how to write this expression so that DLookup can use it and be able to handle null records?
Thanks!

~Rob
0
Comment
Question by:rfiddler
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 8

Accepted Solution

by:
Benjamin_Luk earned 50 total points
ID: 9863623
change :
sResult = DLookup(sExpr, "Network", "NetworkID=18436")
To:
sResult = NZ(DLookup(sExpr, "Network", "NetworkID=18436"),"")

Regards

Ben
0
 
LVL 5

Assisted Solution

by:morpheus30
morpheus30 earned 30 total points
ID: 9863767
BTW, the line:
sExpr = "CASE WHEN [FirstName]=NULL THEN 'No First Name' ELSE [FirstName] END"

should be:

sExpr = "CASE WHEN [FirstName] IS NULL THEN 'No First Name' ELSE [FirstName] END"

Then you can use DLookup as suggested by Benjamin_Luk.

My two cents...
0
 

Author Comment

by:rfiddler
ID: 9870756
Thanks Ben and Morpheus!
It's working now.

I'm increasing the points and rewarding Morpheus for the two cents as well.

Thanks again.

~Rob
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question