dsum with 2 criteria

  • Thread starter Thread starter Simon
  • Start date Start date
S

Simon

Whats wrong with this code

YearCabinsTurnover = DSum("[SumOfSubTotal]", "Query8", "[Year]=" &
NowYear And "[OrderType]= '2'")


Thanks

SImon
 
Whats wrong with this code

YearCabinsTurnover = DSum("[SumOfSubTotal]", "Query8", "[Year]=" &
NowYear And "[OrderType]= '2'")

Thanks

SImon
What is NowYear? A Control name on a form? I'll assume it will have a
Number value, i.e. 2009 or 1998.
What datatype is [OrderType]? I'll guess it's a Number datatype.

YearCabinsTurnover = DSum("[SumOfSubTotal]", "Query8", "[Year]=" &
NowYear & " And [OrderType]= 2")

Please look up, in VBA help
Restrict + "Restrict data to a subset of records" + "Multiple Fields
in Criteria Expressions" to learn how to use multiple fields in a
where clause.

Note: Year is a reserved keyword and should not be used as a field
name. I would suggest you change it to something else, perhaps
SalesYear

For additional reserved words, see the Microsoft KnowledgeBase article
for your version of Access:

109312 'Reserved Words in Microsoft Access' for Access 97
209187 'ACC2000: Reserved Words in Microsoft Access'
286335 'ACC2002: Reserved Words in Microsoft Access'
321266 'ACC2002: Microsoft Jet 4.0 Reserved Words'

For an even more complete list of reserved words, see:
http://www.allenbrowne.com/AppIssueBadWord.html
 
Back
Top