Results 1 to 9 of 9
  1. #1
    larrytxeast is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    5

    Need Help With DLookup in Query: Handling Null (#Error) With Numeric Fields

    This is my 1st post ever here, thank you.

    I'm using Access 2010. I have the following "base" DLookup statement that works except for null situations:

    BadgeNumber1: DLookUp("[BadgeNumber]","tblChefs","[autoid] =" & [FirstChoiceChef])

    If there is nothing to look up, it returns #Error. I got the bright idea of making a modified statement to handle null situations, it looks like this:

    IIf(IsNull(DLookUp("[BadgeNumber]","tblChefs","[autoid] =" & [FirstChoiceChef])),"NothingToSee",DLookUp("[BadgeNumber]","tblChefs","[autoid] =" & [FirstChoiceChef]))

    (it uses this as its foundation: IIf(IsNull(x), "Oops", x) where x is the previous "base" DLookup statement)

    There are no syntax errors, however it still returns #Error, and I'm guessing it's because "BadgeNumber" is a numeric field. Blank values that produce this error, they don't have a default value of 0, they are just blank.

    Tips?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    If DLookup does not find a match, it should just return null.

    What is the 'null situation' - is it possible FirstChoiceChef could be null?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    larrytxeast is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    5
    Quote Originally Posted by June7 View Post
    If DLookup does not find a match, it should just return null.

    What is the 'null situation' - is it possible FirstChoiceChef could be null?
    Yes, FirstChoiceChef could be null, and when I looked back at the database in such #Error cases it was in fact on occasions when this value was null (or blank etc).

    Maybe I'm instead supposed to have the IIf(IsNull) portion instead check to see if FirstChoiceChef is null instead of that entire equation?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Yes, that would be the case. Handle the possible null. Give the expression something else to process.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    larrytxeast is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    5
    Quote Originally Posted by June7 View Post
    Yes, that would be the case. Handle the possible null. Give the expression something else to process.
    Yes, thanks. I did and it fixed it, the expression looks like so (excluding the custom variable name):

    IIf(IsNull([FirstChoiceChef]),"NothingChosen", DLookUp("[BadgeNumber]","tblChefs","[autoid] =" & [FirstChoiceChef]))

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    There may be better options than using DLookup because domain aggregate functions can be slow performers in query.

    So why do you even need the badge number in the query?

    Why not just include tblChefs in the query?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    larrytxeast is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    5
    Quote Originally Posted by June7 View Post
    There may be better options than using DLookup because domain aggregate functions can be slow performers in query.

    So why do you even need the badge number in the query?

    Why not just include tblChefs in the query?
    Care to elaborate on the better options?

    I have done setups where I included tblChefs in the query, where it was looking up the chef's name with the ChefID field in the "base" table (so could see their actual name), in this case however it got confusing because there are 3 fields--FirstChoice, SecondChoice and ThirdChoice all which have the autoid value from the tblChef plugged instead of the name (as should be the case). I kept running into errors and gave up doing it that way.

    In this one other forum, (access-programmers.co.uk), there was an "introduce yourself" forum or whatever, and I was able to elaborate a bit there on my background. I'm not a hard-core programmer, although I do a fair amount of code. Most of all, I hadn't done databases in several years (2010 was the previous occasion) so I had become quite a bit "stale" in remembering basic things. A previous co-worker called me up needing help with an Access database so basically I've "rebooted" but with many cobwebs still in my head from being "stale" (although after a week of this much of this has cleared up, not all however). So I am not as "fresh" as others, and perhaps not as fluent regardless. I'm a clear step above a clerical/administrative person, however. (Besides that I do know some code, also notice the Redick and Leszynski naming conventions.) Maybe I'm an "advanced power user" or something of that caliber.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Three 'choice' fields is not strictly normalized structure. Suppose you want to find all records with chef Jim, regardless of which choice field he is in - this means applying the same filter criteria to all 3 fields with OR operator.

    To display the associated chef info for each 'choice' field, the query would have to pull in tblChefs 3 times, 1 each joined to each of the 'choice' fields.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    larrytxeast is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    5
    Quote Originally Posted by June7 View Post
    Three 'choice' fields is not strictly normalized structure. Suppose you want to find all records with chef Jim, regardless of which choice field he is in - this means applying the same filter criteria to all 3 fields with OR operator.

    To display the associated chef info for each 'choice' field, the query would have to pull in tblChefs 3 times, 1 each joined to each of the 'choice' fields.
    Oh dear, I think you're right. Fortunately, I don't think anyone is running that filter, no one needs to know that, but structurally speaking you're right. At this point I'm so deep in it would be a major undertaking (somewhat) to reconfigure it this way, but if I do somehow get the time I may well normalize this aspect. (And thanks for helping me remember what that term is called.)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 09-05-2012, 10:23 AM
  2. Handling Null DLookup result
    By j6sander in forum Access
    Replies: 1
    Last Post: 07-19-2012, 11:07 AM
  3. Importing numeric fields with null values from XML
    By hcorvallis in forum Import/Export Data
    Replies: 1
    Last Post: 10-20-2011, 08:09 AM
  4. DLookUp function giving invalid use of null error
    By shubhamgandhi in forum Programming
    Replies: 4
    Last Post: 07-21-2011, 06:04 PM
  5. Numeric value out of range (null)
    By PPCMIS2009 in forum Queries
    Replies: 0
    Last Post: 02-03-2009, 11:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums