Reputation: 504
I am attempting to use the DCount() Function to return a count from my table. My issue is that it always returns a NULL value.
How should I Re-write this VBA statement so that it returns the accurate count?
ReturnedCount = DCount("CountOfItems", "[__TestTable]", "NameOfItem = " & ItemName)
Debug.Print ReturnedCount
Upvotes: 0
Views: 1099
Reputation: 55831
You should use:
On Error Goto 0
ReturnedCount = DCount("*", "[__TestTable]", "NameOfItem = '" & ItemName & "'")
It will at least return 0 (zero) ... if the table and field names are correct.
Upvotes: 0
Reputation:
NameOfItem
implies a string. You need to wrap strings in single quotes when passing them as a parameter to a D-Function; just like passing them as a parameter in a Query.
ReturnedCount = DCount("CountOfItems", "[__TestTable]", "NameOfItem = '" & ItemName & "'")
Using the immediate window to test your D-Functions will simplify debugging.
Upvotes: 1