Another DLookup problem

T

Tony Williams

I'm trying to calculate for a report the previous year to date value of a
control I'm using this:
=DLookUp("[Sum of
txtDomfactot]","qryFDASalesV2","Year([txtmonthlabel])=Year([txtprevyr])")
The report is based on a query "qryFDASalesV2" and the value I'm trying to
calculate is the year to date total of "txtdomfactot" The control
"txtmonthlabel" is the current month as a mmmm yyyy date/time field and
"txtprevyr", also formatted mmmm yyyy, is a calculated control which gives
me the previous year calculated using:
=DateAdd("m",-12,[txtmonthlabel])
But I don't get the correct value showing. It does return a figure but it
doesn't equate with the total caluculated manually.
What am I doing wrong?
TIA
Tony Williams
 
J

Jeff Boyce

Tony

<Using periods (".") helps readability.>

see in-line below

Tony Williams said:
I'm trying to calculate for a report the previous year to date value of a
control I'm using this:

Is that control on a form? on a report? where?
=DLookUp("[Sum of
txtDomfactot]","qryFDASalesV2","Year([txtmonthlabel])=Year([txtprevyr])")
The report is based on a query "qryFDASalesV2" and the value I'm trying to
calculate is the year to date total of "txtdomfactot" The control
"txtmonthlabel" is the current month as a mmmm yyyy date/time field and

?"txtmonthlabel" is the name of a ?label or a ?textbox control?
?It displays the current month, based on an underlying Date/Time field?
"txtprevyr", also formatted mmmm yyyy, is a calculated control which gives

?"txtprevyr" is based on a Date/Time value, formatted to display 'mmmm
yyyy'?
me the previous year calculated using:
=DateAdd("m",-12,[txtmonthlabel])

The year (yyyy) previous to a date/time value can also be calculated using
Year([yourdate]-1
if you only need the year. Why do you need the month?
But I don't get the correct value showing. It does return a figure but it
doesn't equate with the total caluculated manually.
What am I doing wrong?
TIA
Tony Williams

If you have dates (real dates, with day, month and year, no matter how
formatted for display), you can use them to select a (date) range of
records. You haven't provided the SQL statement of your query,
"qryFDASalesV2", so it's difficult to guess what it might be doing. Since
your result depends on that query, please post back the SQL statement.
 

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