Dsum() return a negative

  • Thread starter Thread starter TeeSee
  • Start date Start date
T

TeeSee

Could someone please explain why the following Dsum() returns a
negative number. Thanks

Dim intRecCount As Integer
intRecCount = DSum("ynDelete", "tblCDMRvalues", ([ynDelete] = Yes))
 
Try:
intRecCount = DSum("ynDelete", "tblCDMRvalues", "[ynDelete] = Yes"

AFAIK, all of the Domain functions take strings as arguments.

Could someone please explain why the following Dsum() returns a
negative number. Thanks

Dim intRecCount As Integer
intRecCount = DSum("ynDelete", "tblCDMRvalues", ([ynDelete] = Yes))
 
You are summing values in the ynDelete field. If that is a Yes/No field, a
Yes value is represented by -1. You are adding all of these values (sort
of).
The reason I say "sort of" is because your syntax is incorrect. As ruralguy
pointed out, the criteria part of the expression needs to be a string, but
he left out a closing parentheses. Try this:
intRecCount = DSum("ynDelete", "tblCDMRvalues", "[ynDelete] = Yes")

If there are three records in which ynDelete is True, the expression will
return -3. If you wrap it in the Abs function you will get 3 as the result:
intRecCount = Abs(DSum("ynDelete", "tblCDMRvalues", "[ynDelete] = Yes"))

However, since it seems you want to count the records, DCount would be a
more efficient way to go about it:
intRecCount = DCount("*", "tblCDMRvalues", "[ynDelete] = Yes")
 
Back
Top