DSUM Syntax Error

N

NeoFax

I am getting the following suntax error: "Syntax error in string in
query expression '[MonthNum]=6'""(second quote is not in the error
screen). Here is my DSum expression: Test:
DSum("Units","tblMonthlyUnits","[MonthNum]=" &
CStr(DatePart("m",dhpreviousworkdaya(Date()))) & """"). The
tblMonthlyUnits is set up as follows:

MonthNum(Dbl) Sample: 1, 2, 3, 4, 5, ...
MonthName(Txt) Sample: Jan, Feb, Mar, Apr, ...
Units(Dbl) Sample: 2.51, 2.03, 2.67, 1.89, 2.54, ...

Why am I getting the error? If I change the criteria part of the DSum
to "[MonthNum]=6", it works fine. I have tried without changing the
DatePart function to a string, also changing to Double with CDbl and
without change at all and I receive the same error. Could it be the 4
quotation marks at the end?
 
N

NeoFax

I am getting the following suntax error: "Syntax error in string in
query expression '[MonthNum]=6'""(second quote is not in the error
screen).  Here is my DSum expression:  Test:
DSum("Units","tblMonthlyUnits","[MonthNum]=" &
CStr(DatePart("m",dhpreviousworkdaya(Date()))) & """").  The
tblMonthlyUnits is set up as follows:

MonthNum(Dbl) Sample: 1, 2, 3, 4, 5, ...
MonthName(Txt) Sample: Jan, Feb, Mar, Apr, ...
Units(Dbl)  Sample: 2.51, 2.03, 2.67, 1.89, 2.54, ...

Why am I getting the error?  If I change the criteria part of the DSum
to "[MonthNum]=6", it works fine.  I have tried without changing the
DatePart function to a string, also changing to Double with CDbl and
without change at all and I receive the same error.  Could it be the 4
quotation marks at the end?

Fixed it myself. Here is the final DSUM:
DSum("Units","tblMonthlyUnits","[MonthNum]=" &
CDbl(DatePart("m",dhpreviousworkdaya(Date())))). Didn't need to
concatenate the quotations as the DatePart returns a number value and
not a string. Now my new dilemma is figuring out how to sum the
values of a column.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top