Help with DSum Function

  • Thread starter Thread starter Joe Cilinceon
  • Start date Start date
J

Joe Cilinceon

I trying to get a total for a charge in a date span. Here is as close as
I've gotten:
DSum("[qryCharges]![ChgAmt]","[qryCharges]","[qryCharges]![ChgID]= 1" &
"[qryCharges]![PaymentDate] = Between " & #11/1/2005# & " And #" & Date() &
"#")

ChgAmt is currency
ChgID is the item number
PaymentDate is from 1st to current date

Please I need some help with the syntax.
 
DSum("[qryCharges]![ChgAmt]","[qryCharges]", _
"[qryCharges]![ChgID]= 1" & _
"[qryCharges]![PaymentDate] = Between #11/1/2005# And " & _
Format(Date(), "\#mm\/dd\/yyyy\#"))
 
Douglas J. Steele said:
DSum("[qryCharges]![ChgAmt]","[qryCharges]", _
"[qryCharges]![ChgID]= 1" & _
"[qryCharges]![PaymentDate] = Between #11/1/2005# And " & _
Format(Date(), "\#mm\/dd\/yyyy\#"))

You don't need an And in there?

DSum("[qryCharges]![ChgAmt]","[qryCharges]", _
"[qryCharges]![ChgID]= 1 And " & _
"[qryCharges]![PaymentDate] = Between #11/1/2005# And " & _
Format(Date(), "\#mm\/dd\/yyyy\#"))

Tom Lake
 
Tom Lake said:
Douglas J. Steele said:
DSum("[qryCharges]![ChgAmt]","[qryCharges]", _
"[qryCharges]![ChgID]= 1" & _
"[qryCharges]![PaymentDate] = Between #11/1/2005# And " & _
Format(Date(), "\#mm\/dd\/yyyy\#"))

You don't need an And in there?

DSum("[qryCharges]![ChgAmt]","[qryCharges]", _
"[qryCharges]![ChgID]= 1 And " & _
"[qryCharges]![PaymentDate] = Between #11/1/2005# And " & _
Format(Date(), "\#mm\/dd\/yyyy\#"))

Quite right. I was concentrating on the dates, and missed that.

Thanks for the assist, Tom.
 
Thanks Tom and Douglas it is much appreacaited.

Tom Lake said:
Douglas J. Steele said:
DSum("[qryCharges]![ChgAmt]","[qryCharges]", _
"[qryCharges]![ChgID]= 1" & _
"[qryCharges]![PaymentDate] = Between #11/1/2005# And " & _
Format(Date(), "\#mm\/dd\/yyyy\#"))

You don't need an And in there?

DSum("[qryCharges]![ChgAmt]","[qryCharges]", _
"[qryCharges]![ChgID]= 1 And " & _
"[qryCharges]![PaymentDate] = Between #11/1/2005# And " & _
Format(Date(), "\#mm\/dd\/yyyy\#"))

Quite right. I was concentrating on the dates, and missed that.

Thanks for the assist, Tom.
 
Hi Douglas

You are missing an "And" after the first criteria, and there is no need for
the equal mark before the between

DSum("[qryCharges]![ChgAmt]","[qryCharges]", _
"[qryCharges]![ChgID]= 1 AND " & _
"[qryCharges]![PaymentDate] Between #11/1/2005# And " & _
Format(Date(), "\#mm\/dd\/yyyy\#"))


DSum("[qryCharges]![ChgAmt]","[qryCharges]", _
"[qryCharges]![ChgID]= 1" & _
"[qryCharges]![PaymentDate] = Between #11/1/2005# And " & _
Format(Date(), "\#mm\/dd\/yyyy\#"))


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Joe Cilinceon said:
I trying to get a total for a charge in a date span. Here is as close as
I've gotten:
DSum("[qryCharges]![ChgAmt]","[qryCharges]","[qryCharges]![ChgID]= 1" &
"[qryCharges]![PaymentDate] = Between " & #11/1/2005# & " And #" & Date()
& "#")

ChgAmt is currency
ChgID is the item number
PaymentDate is from 1st to current date

Please I need some help with the syntax.
 
Good Lord: it's taken 3 of us to answer the one question!

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Ofer said:
Hi Douglas

You are missing an "And" after the first criteria, and there is no need
for
the equal mark before the between

DSum("[qryCharges]![ChgAmt]","[qryCharges]", _
"[qryCharges]![ChgID]= 1 AND " & _
"[qryCharges]![PaymentDate] Between #11/1/2005# And " & _
Format(Date(), "\#mm\/dd\/yyyy\#"))


DSum("[qryCharges]![ChgAmt]","[qryCharges]", _
"[qryCharges]![ChgID]= 1" & _
"[qryCharges]![PaymentDate] = Between #11/1/2005# And " & _
Format(Date(), "\#mm\/dd\/yyyy\#"))


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Joe Cilinceon said:
I trying to get a total for a charge in a date span. Here is as close as
I've gotten:
DSum("[qryCharges]![ChgAmt]","[qryCharges]","[qryCharges]![ChgID]= 1" &
"[qryCharges]![PaymentDate] = Between " & #11/1/2005# & " And #" &
Date()
& "#")

ChgAmt is currency
ChgID is the item number
PaymentDate is from 1st to current date

Please I need some help with the syntax.
 
lol no wonder I don't get many answers to my questions. Thanks again I think
I have it now.

Good Lord: it's taken 3 of us to answer the one question!


Ofer said:
Hi Douglas

You are missing an "And" after the first criteria, and there is no
need for
the equal mark before the between

DSum("[qryCharges]![ChgAmt]","[qryCharges]", _
"[qryCharges]![ChgID]= 1 AND " & _
"[qryCharges]![PaymentDate] Between #11/1/2005# And " & _
Format(Date(), "\#mm\/dd\/yyyy\#"))


DSum("[qryCharges]![ChgAmt]","[qryCharges]", _
"[qryCharges]![ChgID]= 1" & _
"[qryCharges]![PaymentDate] = Between #11/1/2005# And " & _
Format(Date(), "\#mm\/dd\/yyyy\#"))


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I trying to get a total for a charge in a date span. Here is as
close as I've gotten:
DSum("[qryCharges]![ChgAmt]","[qryCharges]","[qryCharges]![ChgID]=
1" & "[qryCharges]![PaymentDate] = Between " & #11/1/2005# & " And
#" & Date()
& "#")

ChgAmt is currency
ChgID is the item number
PaymentDate is from 1st to current date

Please I need some help with the syntax.
 
Try this, there are some changes
1. Add the word AND after the first criteria
2. Put the first date in the string
3. Remove the equal sign before the between

DSum("[qryCharges]![ChgAmt]","[qryCharges]","[qryCharges]![ChgID]= 1 AND
[qryCharges]![PaymentDate] Between #11/1/2005# And #" & Date() & "#")
 
Ofer said:
Try this, there are some changes
1. Add the word AND after the first criteria
2. Put the first date in the string
3. Remove the equal sign before the between

DSum("[qryCharges]![ChgAmt]","[qryCharges]","[qryCharges]![ChgID]= 1
AND [qryCharges]![PaymentDate] Between #11/1/2005# And #" & Date() &
"#")

Ok all so far have returned and Error.
 
Given how many different versions have been suggested to you, it might be a
good idea to post what you're actually trying to use!

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Joe Cilinceon said:
Ofer said:
Try this, there are some changes
1. Add the word AND after the first criteria
2. Put the first date in the string
3. Remove the equal sign before the between

DSum("[qryCharges]![ChgAmt]","[qryCharges]","[qryCharges]![ChgID]= 1
AND [qryCharges]![PaymentDate] Between #11/1/2005# And #" & Date() &
"#")

Ok all so far have returned and Error.
 
Ok, let me try it this way. I have a the following:

LEDGER (table)
Transaction (number that links this table to the charges)
PaymentDate (date fields)

CHARGES (table)
Transaction (links to LEDGER to get the dates needed)
ChgID
ChgAmt

Now I want a total amount for all ChgID = 1 (Rent is what 1 is) from 11/1/05
to today).

Now I need the proper syntax for the criteria section of the DSum.
Given how many different versions have been suggested to you, it
might be a good idea to post what you're actually trying to use!


Joe Cilinceon said:
Ofer said:
Try this, there are some changes
1. Add the word AND after the first criteria
2. Put the first date in the string
3. Remove the equal sign before the between

DSum("[qryCharges]![ChgAmt]","[qryCharges]","[qryCharges]![ChgID]= 1
AND [qryCharges]![PaymentDate] Between #11/1/2005# And #" & Date()
& "#")

Ok all so far have returned and Error.
 
I'm assuming that qryCharges is a query that links the two tables together,
and that it works properly (especially that all of the field names it
returns are what you expect, as opposed to Expr1, Expr2)

DSum("[ChgAmt]","[qryCharges]", _
"[ChgID]= 1 " & _
"AND [PaymentDate] " & _
"Between #11/1/2005# And " & _
Format(Date(), "\#mm\/dd\/yyyy\#"))

You do not want [qryCharges]![ChgAmt] as the first argument: you want
strictly the name of the field.

You do not want [qryCharges]![ChgID] or [qryCharges]![PaymentDate] in the
third argument: you want strictly the names of the fields.

If this still doesn't work, please post the actual code you're using. As
well, post the SQL of qryCharges, just in case.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Joe Cilinceon said:
Ok, let me try it this way. I have a the following:

LEDGER (table)
Transaction (number that links this table to the charges)
PaymentDate (date fields)

CHARGES (table)
Transaction (links to LEDGER to get the dates needed)
ChgID
ChgAmt

Now I want a total amount for all ChgID = 1 (Rent is what 1 is) from
11/1/05 to today).

Now I need the proper syntax for the criteria section of the DSum.
Given how many different versions have been suggested to you, it
might be a good idea to post what you're actually trying to use!


Joe Cilinceon said:
Ofer wrote:
Try this, there are some changes
1. Add the word AND after the first criteria
2. Put the first date in the string
3. Remove the equal sign before the between

DSum("[qryCharges]![ChgAmt]","[qryCharges]","[qryCharges]![ChgID]= 1
AND [qryCharges]![PaymentDate] Between #11/1/2005# And #" & Date()
& "#")

Ok all so far have returned and Error.
 
Thank you Douglas that worked perfectly. Now I have another question for you
about the format function. What is the \/ designating?
I'm assuming that qryCharges is a query that links the two tables
together, and that it works properly (especially that all of the
field names it returns are what you expect, as opposed to Expr1,
Expr2)
DSum("[ChgAmt]","[qryCharges]", _
"[ChgID]= 1 " & _
"AND [PaymentDate] " & _
"Between #11/1/2005# And " & _
Format(Date(), "\#mm\/dd\/yyyy\#"))

You do not want [qryCharges]![ChgAmt] as the first argument: you want
strictly the name of the field.

You do not want [qryCharges]![ChgID] or [qryCharges]![PaymentDate] in
the third argument: you want strictly the names of the fields.

If this still doesn't work, please post the actual code you're using.
As well, post the SQL of qryCharges, just in case.


Joe Cilinceon said:
Ok, let me try it this way. I have a the following:

LEDGER (table)
Transaction (number that links this table to the charges)
PaymentDate (date fields)

CHARGES (table)
Transaction (links to LEDGER to get the dates needed)
ChgID
ChgAmt

Now I want a total amount for all ChgID = 1 (Rent is what 1 is) from
11/1/05 to today).

Now I need the proper syntax for the criteria section of the DSum.
Given how many different versions have been suggested to you, it
might be a good idea to post what you're actually trying to use!


Ofer wrote:
Try this, there are some changes
1. Add the word AND after the first criteria
2. Put the first date in the string
3. Remove the equal sign before the between

DSum("[qryCharges]![ChgAmt]","[qryCharges]","[qryCharges]![ChgID]=
1 AND [qryCharges]![PaymentDate] Between #11/1/2005# And #" &
Date() & "#")

Ok all so far have returned and Error.
 
\ is an escape character: it means that the next character will be used as
is.

The reason for using it when formatting dates is that if you use mm/dd/yyyy,
the / will be replaced by whatever has been designated as the date separator
in the Regional Settings. Some people use . or - as the separator, and that
can sometimes lead to problems in SQL statements. Using \/ guarantees that
forward slashes will be used, which are always going to work properly.
Similarly, simply using # without the \ won't work, since # has a specific
meaning in formats.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Joe Cilinceon said:
Thank you Douglas that worked perfectly. Now I have another question for
you about the format function. What is the \/ designating?
I'm assuming that qryCharges is a query that links the two tables
together, and that it works properly (especially that all of the
field names it returns are what you expect, as opposed to Expr1,
Expr2)
DSum("[ChgAmt]","[qryCharges]", _
"[ChgID]= 1 " & _
"AND [PaymentDate] " & _
"Between #11/1/2005# And " & _
Format(Date(), "\#mm\/dd\/yyyy\#"))

You do not want [qryCharges]![ChgAmt] as the first argument: you want
strictly the name of the field.

You do not want [qryCharges]![ChgID] or [qryCharges]![PaymentDate] in
the third argument: you want strictly the names of the fields.

If this still doesn't work, please post the actual code you're using.
As well, post the SQL of qryCharges, just in case.


Joe Cilinceon said:
Ok, let me try it this way. I have a the following:

LEDGER (table)
Transaction (number that links this table to the charges)
PaymentDate (date fields)

CHARGES (table)
Transaction (links to LEDGER to get the dates needed)
ChgID
ChgAmt

Now I want a total amount for all ChgID = 1 (Rent is what 1 is) from
11/1/05 to today).

Now I need the proper syntax for the criteria section of the DSum.

Douglas J. Steele wrote:
Given how many different versions have been suggested to you, it
might be a good idea to post what you're actually trying to use!


Ofer wrote:
Try this, there are some changes
1. Add the word AND after the first criteria
2. Put the first date in the string
3. Remove the equal sign before the between

DSum("[qryCharges]![ChgAmt]","[qryCharges]","[qryCharges]![ChgID]=
1 AND [qryCharges]![PaymentDate] Between #11/1/2005# And #" &
Date() & "#")

Ok all so far have returned and Error.
 
Thanks for the answer Douglas.
\ is an escape character: it means that the next character will be
used as is.

The reason for using it when formatting dates is that if you use
mm/dd/yyyy, the / will be replaced by whatever has been designated as
the date separator in the Regional Settings. Some people use . or -
as the separator, and that can sometimes lead to problems in SQL
statements. Using \/ guarantees that forward slashes will be used,
which are always going to work properly. Similarly, simply using #
without the \ won't work, since # has a specific meaning in formats.


Joe Cilinceon said:
Thank you Douglas that worked perfectly. Now I have another question
for you about the format function. What is the \/ designating?
I'm assuming that qryCharges is a query that links the two tables
together, and that it works properly (especially that all of the
field names it returns are what you expect, as opposed to Expr1,
Expr2)
DSum("[ChgAmt]","[qryCharges]", _
"[ChgID]= 1 " & _
"AND [PaymentDate] " & _
"Between #11/1/2005# And " & _
Format(Date(), "\#mm\/dd\/yyyy\#"))

You do not want [qryCharges]![ChgAmt] as the first argument: you
want strictly the name of the field.

You do not want [qryCharges]![ChgID] or [qryCharges]![PaymentDate]
in the third argument: you want strictly the names of the fields.

If this still doesn't work, please post the actual code you're
using. As well, post the SQL of qryCharges, just in case.


Ok, let me try it this way. I have a the following:

LEDGER (table)
Transaction (number that links this table to the charges)
PaymentDate (date fields)

CHARGES (table)
Transaction (links to LEDGER to get the dates needed)
ChgID
ChgAmt

Now I want a total amount for all ChgID = 1 (Rent is what 1 is)
from 11/1/05 to today).

Now I need the proper syntax for the criteria section of the DSum.

Douglas J. Steele wrote:
Given how many different versions have been suggested to you, it
might be a good idea to post what you're actually trying to use!


Ofer wrote:
Try this, there are some changes
1. Add the word AND after the first criteria
2. Put the first date in the string
3. Remove the equal sign before the between

DSum("[qryCharges]![ChgAmt]","[qryCharges]","[qryCharges]![ChgID]=
1 AND [qryCharges]![PaymentDate] Between #11/1/2005# And #" &
Date() & "#")

Ok all so far have returned and Error.
 

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

Similar Threads

Monthly Totals with a Subquery 7
Dsum Help 0
Parameter Query with DSum 1
Help needed with IF DSum in query 9
dsum - 1
DSum expression not working 6
dsum with multiple criteria and decimals 0
dsum 9

Back
Top