Trouble counting blank records with DCount function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • slenish
    Contributor
    • Feb 2010
    • 283

    Trouble counting blank records with DCount function

    Hello All,

    I am trying to use the DCount Function to count blank records on a table from a form. I want to make it so i can press a button and the function will run and show the total in a text box on a form. I can get it to work with non null or non blank fields but for some reason it just keeps showing me 0 when i try to get it to count blank fields. If the DCount function is not the best approach I appreciate any other alternatives. FYI I prefer to do this with VBA and not a query.

    Thanks in advance,

    Current code I have been working with
    Code:
    cntMax = DCount("[Name]","Table1","[Name]='""""' ")
    txtBox = cntMax
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    DCount(expr, domain, [criteria])
    The DCount Function doesn't count Records that contain Null Values in the Field referenced by expr unless expr is the asterisk (*) Wildcard Character. the following Syntax will work:
    Code:
    cntMax = DCount("*", "Table1", "IsNull([Name])")

    Comment

    • slenish
      Contributor
      • Feb 2010
      • 283

      #3
      Hi ADezii,

      appreciate the quick response on this. I was trying the wild card with the asterisk but i was doing it backward and using it at the end of the expression. Works great now really appreciate the help!

      Also I like the new picture for you avatar :D

      Take care

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32661

        #4
        For an actual count of records where [Name] is blank you would need to get the total (Using "*" as ADezii suggests) then subtract those with values (Using "[Name]").

        Comment

        Working...