By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,543 Members | 2,085 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,543 IT Pros & Developers. It's quick & easy.

How to display a value from an unrelated query in a report

P: 52
HELP! I'm about to have a total meltdown!

I've been trying all sorts of things to do the following. I have a financial database that contains incomes and expenses. I have it set up so that each entry contains the date deposited, amount, from who, cheque #, etc. Each entry is either an IN (for income) or EX (for expense). I've just created the General Ledger report that shows a chronologic accounting of all entries in a given month. I now want to sum up the incomes and then sum up the expenses. I then want to add the incomes to the start balance, and subtract the expenses. Sound simple? I thought so too!

I've made two queries that output the correct numbers; neither one of them is the underlying query for the report. That query MUST contain all the entries in the given date range and then display them chronologically, as I said. If I could simply group the incomes and expenses, I would have it. But, I cannot. They are all mixed.

So, how do I plunk in a number from the queries I made? I've tried simply using the Expression builder to get to them, but Access doesn't know what they are. I've tried Dsum, DLookup, and can't get them to display the right numbers (always outputs the first entry amount only).

What I REALLY want, while I'm at it, to maintain a running total on the right, that adds things that are incomes and subtracts things that are expenses. That would do it! However, the Running Sum feature in reports only adds. I cannot see how to do it based on a criteria.

Any insights? THANKS! : )
Oct 11 '10 #1
Share this Question
Share on Google+
6 Replies


NeoPa
Expert Mod 15k+
P: 31,494
DSum() should work for the first part of the question. You don't give examples of how you tried this, so I cannot tell you where you went wrong.

As for a running sum, you can create hidden controls on your report which sum (Running Sum) the calculated values determined by whether or not it is INcome or EXpense. This can be prepared in your bound query.

If you want a single running total, then it is also very easy to produce a value which is negated if the type is an EXpense. Summing these values gives you what you require I think.
Oct 11 '10 #2

P: 52
Thanks, NeoPa!

I'm trying Dsum again; still not working. Can you help me figure out why?

Here are some (better!) details:

The report is based on a Query called "Q: Financials - Date filtered for Reporting", which takes as parameters start and end dates (so I can total in a given month). Each record consists of the Amount as well as whether it is an IN or EX. This is working properly.

The Dsum looks like this:
Expand|Select|Wrap|Line Numbers
  1. =Dsum([Amount], "Q:  Financials - Date filtered for Reporting","[Income or Expense?]='IN'")
which, I think, should sum up everything in the Amount field from the Query "Q: Financials - Date filtered for Reporting" for the records whose criteria matches the "IN" (that I have specified as such). What is wrong? It outputs a total that is massively more than it should be (more than 4 times too big). I cannot even work out HOW it came up with that number. There's no mathematical reasoning that I can see.

Any ideas?
Oct 11 '10 #3

NeoPa
Expert Mod 15k+
P: 31,494
If your query filters by start and end date, then your DSum() call certainly doesn't. I expect that is why you are getting a greater value than anticipated.

Why not try the Running Sum option. That will always work for the data within the confines of any relevant filtering of the report (or query).
Oct 11 '10 #4

P: n/a
THANKS! That's exactly what I did. I actually did TWO, with the control source of each specifying to sum ONLY if it was an IN (and then only if it was an EX). Worked BEAUTIFULLY! Yaye! I didn't know you could do that until I tried it! THANKS so much for your help! I'm all set now!

Happy Canadian Thanksgiving!
Oct 11 '10 #5

NeoPa
Expert Mod 15k+
P: 31,494
Very happy to hear it Melody :-)

Happy Canadian Thanksgiving to you too and Welcome to Bytes!
Oct 11 '10 #6

NeoPa
Expert Mod 15k+
P: 31,494
Melody. I moved your new question to a new thread (Totals Not Correct When Printing Report). I'll do what I can for you from there.
Oct 12 '10 #7

Post your reply

Sign in to post your reply or Sign up for a free account.