Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subtotals based on Yes/No field

Status
Not open for further replies.

Carenne

Programmer
Sep 17, 2000
27
US
Hi everyone --

I'm having trouble producing some calculations in a report and hope you can help me. This is in Access 97, and the report is based on a query that contains two related tables - a customer name table and a service log table. The service log table has a column for dollar total per visit and a yes/no column to check off if the visit was in response to an ad.

The report is sorted/grouped on customer name, with each visit detailed under the customer. At the end I have a grand total of all dollar amounts.

What I would like, in addition to the grand total, are two additional subtotals - one for total dollar amount based on "response to ad" (yes/no field = true), and one for total "other" dollar amount (yes/no field = false).

And this is where I'm running into trouble. Of course, I had success doing it by creating additional queries and subreports, but I know there must be a simpler way. I tried experimenting with various IF statements in the report and was totally unsuccessful with that.

My current approach is adding two additional columns in the query - one for the yes/no = true figures and one for the yes/no = false figures. The query works fine, but when I try to run the report, I get an error message that I have an invalid data type. The two new "query-only" fields are called ad-y and ad-n. In the textbox (on the report footer) where I want the totals, I have =Sum([ad-y]) and =Sum([ad-n]) as the data control source. I have made sure that the properties in the query as well as the report subtotal field are set to currency (same as the original data).

If this is the correct way to do this, what am I doing wrong? If it's not the best approach, I welcome any help you can offer for doing it the right way!

Thanks in advance!
Carenne :)
 
Include your check box in the query but don't add the extra columns for yes and no values.

Unbound text box 1 control source:
=DSum("[cost]","qryLog","[AdCheckBox]= -1")

Unbound text box 2 control source:
=DSum("[cost]","qryLog","[AdCheckBox]= 0")






 
Wow, sko - this is awesome! It works perfectly, and there's virtually no extra work involved. Thank you SOOO much for the prompt fix-it - you just made my night! -- Carenne :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top