By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,656 Members | 1,752 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,656 IT Pros & Developers. It's quick & easy.

Trouble counting blank records with DCount function

100+
P: 283
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
Expand|Select|Wrap|Line Numbers
  1. cntMax = DCount("[Name]","Table1","[Name]='""""' ")
  2. txtBox = cntMax
  3.  
Nov 19 '11 #1

✓ answered by ADezii

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:
Expand|Select|Wrap|Line Numbers
  1. cntMax = DCount("*", "Table1", "IsNull([Name])")

Share this Question
Share on Google+
3 Replies


ADezii
Expert 5K+
P: 8,685
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:
Expand|Select|Wrap|Line Numbers
  1. cntMax = DCount("*", "Table1", "IsNull([Name])")
Nov 19 '11 #2

100+
P: 283
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
Nov 19 '11 #3

NeoPa
Expert Mod 15k+
P: 31,712
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]").
Nov 20 '11 #4

Post your reply

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