Results 1 to 7 of 7
  1. #1
    Xiaoding is offline Novice
    Windows 2K Access 2003
    Join Date
    Nov 2009
    Posts
    29

    Can't get NZ Function to Work

    Hi All,

    I have a query with one field:
    Count: DCount("TAG_NUMBER","H Pm's Closed, 1st TEMP").

    It counts the number of records returned by the query "H Pm's Closed, 1st TEMP".

    Occasionally, the "H Pm's Closed, 1st TEMP" query returns no records. So, I get no Dcount result. So the query shows no records returned. I need a zero there in that case.

    I would like there to be a zero instead of no records, but I can't figure out how to do it. The NZ function is mentioned a lot, but I can't get it to work. Where do I use the NZ, or do I use something else, to get a zero instead of no records? I'm using Access 2003.




  2. #2
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Try the Following:
    1) Count: Nz(DCount("TAG_NUMBER","H Pm's Closed, 1st TEMP"),0)

    2) Count: iif(isNull(DCount("TAG_NUMBER","H Pm's Closed, 1st TEMP")),0,DCount("TAG_NUMBER","H Pm's Closed, 1st TEMP"))


    I have made adjustment to the second expression just check out whether it gives the error.
    Last edited by maximus; 04-01-2010 at 09:02 AM.

  3. #3
    Xiaoding is offline Novice
    Windows 2K Access 2003
    Join Date
    Nov 2009
    Posts
    29

    re:

    Thnx for your reply,


    The first one does not work, the second one returns the error, "The expression you entered has a function containing the wrong number of arguments".

    Thank you

    Xiaoding

  4. #4
    ConneXionLost's Avatar
    ConneXionLost is offline Simulacrum
    Windows XP Access 2003
    Join Date
    Jan 2010
    Location
    Victoria, Canada
    Posts
    291
    Not saying this will fix the problem, but "Count" is a reserved word and should be avoided as a field name.

    Cheers,

  5. #5
    Xiaoding is offline Novice
    Windows 2K Access 2003
    Join Date
    Nov 2009
    Posts
    29
    Quote Originally Posted by ConneXionLost View Post
    Not saying this will fix the problem, but "Count" is a reserved word and should be avoided as a field name.

    Cheers,
    Thnx, I didn't know that! But, as you thought, that's not the problem.

  6. #6
    ConneXionLost's Avatar
    ConneXionLost is offline Simulacrum
    Windows XP Access 2003
    Join Date
    Jan 2010
    Location
    Victoria, Canada
    Posts
    291
    Quote Originally Posted by Xiaoding View Post

    Occasionally, the "H Pm's Closed, 1st TEMP" query returns no records. So, I get no Dcount result. So the query shows no records returned. I need a zero there in that case.
    If your query "H Pm's Closed, 1st TEMP" is not returning a recordset (due to nulls) then, for that instance, there is NO field named "TAG_NUMBER". As a result, Access can't see any nulls for Nz to act on in the first place.

    You may need to alter your "H Pm's Closed, 1st TEMP" query.

    Nulls

    Cheers,

  7. #7
    Xiaoding is offline Novice
    Windows 2K Access 2003
    Join Date
    Nov 2009
    Posts
    29

    re:

    Well, that sounds logical. Unfortunetly, it adds up to the same question, since the NZ function is used, in queries, to deal with null results. So the question still is, how do I get NZ to work in this query? Or something else?

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

Similar Threads

  1. Query to work as a Vlookup function
    By dharmik in forum Queries
    Replies: 21
    Last Post: 01-04-2012, 08:12 AM
  2. Want function to get current function name
    By Davis DeBard in forum Programming
    Replies: 2
    Last Post: 08-13-2009, 05:02 AM
  3. VBA Code To Work With MySQL
    By botts121 in forum Programming
    Replies: 0
    Last Post: 07-08-2009, 08:51 AM
  4. Forms don't work the same
    By hawzmolly in forum Access
    Replies: 0
    Last Post: 12-18-2008, 05:46 PM
  5. Can't get TransferSpreadsheet to work
    By Valeda in forum Import/Export Data
    Replies: 0
    Last Post: 07-19-2007, 08:04 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