DSUM in a TextBox of a Report

C

chris1

I have textbox on a report (Detail Section) that uses the DSum domain
function. I am trying to add an amount from a table with a criteria value
from a Form. The following is what I have:

=Dsum("[Amount]","tbl_name","[Manager]=" & Forms!frm_name![Manager])

I get the #Error display. If I take the criteria argument out it works fine
so I know the error is in the criteria section.

By the way, in VBA I assign a variable to the function and it works:
dbltemp = DSum("[Amount]","tbl_name","[Manager] = [Forms]![frm_name]![Manager]
")


Why do I get an error in th Textbox and the result I want in VBA? What is the
fix in the TextBox control? Please help! Thank you!
 
D

Douglas J. Steele

Is Manager a text field? If so, you need quotes around the value:

=Dsum("[Amount]","tbl_name","[Manager]=" & Chr$(34) &
Forms!frm_name![Manager] & Chr$(34))

or

=Dsum("[Amount]","tbl_name","[Manager]=""" & Forms!frm_name![Manager] &
"""")
 
C

chris1 via AccessMonster.com

Thank you Douglas.. It has worked .. again thank you for your help and time!
 
C

chris1 via AccessMonster.com

Actually Douglas the chr$(34) worked but using the """ did not. I get the
expression you have entered has an invalid string. What did I do?

Is Manager a text field? If so, you need quotes around the value:

=Dsum("[Amount]","tbl_name","[Manager]=" & Chr$(34) &
Forms!frm_name![Manager] & Chr$(34))

or

=Dsum("[Amount]","tbl_name","[Manager]=""" & Forms!frm_name![Manager] &
"""")
I have textbox on a report (Detail Section) that uses the DSum domain
function. I am trying to add an amount from a table with a criteria value
[quoted text clipped - 14 lines]
the
fix in the TextBox control? Please help! Thank you!
 
D

Douglas J. Steele

Did you count correctly? That's 3 double quotes after [Manager]=, and 4
double quotes at the end.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


chris1 via AccessMonster.com said:
Actually Douglas the chr$(34) worked but using the """ did not. I get the
expression you have entered has an invalid string. What did I do?

Is Manager a text field? If so, you need quotes around the value:

=Dsum("[Amount]","tbl_name","[Manager]=" & Chr$(34) &
Forms!frm_name![Manager] & Chr$(34))

or

=Dsum("[Amount]","tbl_name","[Manager]=""" & Forms!frm_name![Manager] &
"""")
I have textbox on a report (Detail Section) that uses the DSum domain
function. I am trying to add an amount from a table with a criteria
value
[quoted text clipped - 14 lines]
the
fix in the TextBox control? Please help! Thank you!
 

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