arnelgp
..forever waiting... waiting for jellybean!
- Local time
- Today, 10:12
- Joined
- May 7, 2009
- Messages
- 20,723
Actually I have read this long time on one of my Access books.and try using "*" rather than "1" in the dcount function
I am too lazy to look through all my numerous books, so I
asked AI.
Here is what AI has to say:
Question:
Can i use "1" instead of "*" in Dcount domain function in ms access?
Answer:
Yes, you can use "1" instead of "*" in DCount, and it's actually more efficient!
Both work the same way:
vba
' These are equivalent:
DCount("*", "Customers")
DCount("1", "Customers")
' With criteria:
DCount("*", "Orders", "Status='Active'")
DCount("1", "Orders", "Status='Active'")
Why "1" is better:
Faster - Access doesn't need to resolve field names
No field name conflicts - Won't break if you rename/delete fields
Clearer intent - You're just counting records, not referencing actual data
Performance comparison:
vba
' Slower - Access must validate field exists
DCount("*", "LargeTable", "Status='Active'")
' Faster - Just counts records
DCount("1", "LargeTable", "Status='Active'")
' Also works with specific field (counts non-null values)
DCount("CustomerID", "Orders") ' Only counts non-NULL CustomerIDs
Best practices:
Use "1" when counting all records
Use "FieldName" when you want to count only non-NULL values in that field
Use "*" if you prefer traditional SQL syntax
Example:
vba
' Count all customers
Debug.Print DCount("1", "Customers") '
' Count customers with email
Debug.Print DCount("Email", "Customers") ' Counts non-NULL emails
' Count active orders
Debug.Print DCount("1", "Orders", "Status='Active'") '
So yes, use "1" - it's a better choice!
Last edited: