Generating Reports

  • Thread starter avarusbrightfyre
  • Start date
A

avarusbrightfyre

So I've been working on creating a personal finance database, both to use and
learn a little bit about access. So far I've been able to create forms for
entering information into two tables, Income and Expenditures. The forms
work fine and enter the information as I want it two, but the problem comes
in when I want to generate reports. I want to lay out all of my information
on one report so I can get a monthly snapshot of my finances using bill
collector, employer and payment amounts.

I can get reports of either income or expenditures, but not both. I'm aware
that I need to add relationships between the tables, but there's no
correlating information between the two tables. At first I tried using the
autonumber contact ID, and it worked great....until I deleted a record and it
threw the whole thing off. When I try to add a column with the same value in
both tables, I get two or three copies of each record in the table with less
entries.

I think my solution is to find a way to renumber the contact ID column for
each table when something is changed. Is there a way to do this, or another
way around this?
 
K

Ken Sheridan

You don't really need separate tables for income and expenditure. You could
have used just one table and either entered debits (expenditure) as a
negative values in the same column as credits (income), or by having separate
credit and debit columns. However, you can still combine the tables in a
UNION query, and base a report on that. Even better you could use the UNION
query to append rows into a new single Transactions table, and then ditch the
original separate tables.

You'd only need to join the tables if individual income items are related to
individual expenditure items on a one-to-one basis, but that's unlikely. I'm
assuming each table has columns (fields) such as TransactionDate, Item,
Amount and, if you are categorizing each transaction Category. If you do
have the latter then you should also have a Categories table with one row per
category and relate the income and expenditure tables to this on the Category
columns, enforcing referential integrity in the relationships so that only
valid categories can be entered in the income and expenditure tables.
Cascade updates should also be enforced in the relationships so that if a
Category is changed in the categories table the change will automatically be
applied to all matching rows in the other two tables. If you do have a
Category column in each of income and expenditure tables, but don't have a
Categories table you can create one and fill it using two append queries, one
based on the income table, the other on the expenditure tables. The Category
column of the categories table (its only column in fact) should be made its
primary key. For each category in the other two tables only one row will be
inserted into the Categories table by virtue of the category column being the
primary key.

With you two existing tables a UNION query, use directly by a report or as
the basis for creating a new single Transactions table would be along the
following lines. You have to do this in SQL view as a UNION query can't be
created in design view so you'd open the query designer; don't add any
tables; switch to SQL view and then enter the SQL:

SELECT YEAR([TransactionDate]) AS [TransactionYear],
MONTH([TransactionDate]) AS [TransactionMonth],
[TransactionDate], [Item], [Amount], [Category]
FROM [Income]
UNION ALL
SELECT YEAR([TransactionDate]) AS [TransactionYear],
MONTH([TransactionDate]) AS [TransactionMonth],
[TransactionDate], [Item], [Amount] * -1, [Category]
FROM [Expenditure];

Multiplying the expenditure amounts by -1 will make them all negative
values. Using the YEAR and MONTH functions to return the year and month of
each transaction will enable you to group the report by month, so when you
create the report based on this query, in report design view you'd group the
report, using the Sorting and Grouping dialogue, first by TransactionYear,
then by TransactionMonth, then by Category and then by TransactionDate. Give
the TransactionMonth group a group header and put a text box in it with a
ControlSource property of:

=Format([TransactionDate], "mmmm yyyy")

This will show the month in the format February 2009.

Give the Category group a group header and put a text box bound to the
Category column in this.

Put controls bound to the TransactionDate, Item and Amount columns in the
detail section. If you set the format property of the Amount control to:

$#,##0.00;($#,##0.00)[Red]

assuming you are using USD that is, the expenditure amounts will show in red
and enclosed in parentheses, the usual convention for negative amounts.

You can include group footers for whatever you want to summarize the values
on, so you could have a Category group footer to get subtotals by category
and a TransactionMonth group footer to get subtotals by month. For grand
totals use the report footer. In each case you'd use text boxes with the
following ControlSource properties:

For an income subtotal:

=Sum(IIf([Amount]>0,[Amount],0))

For an exp[enditure subtotal:

=Sum(IIf([Amount]<0,[Amount],0))

For the balance:

=Sum([Amount])

Finally, if you do decide to create a new single Transactions table, don't
include TransactionYear or TransactionMonth columns in it, just the
TransactionDate. The year and month can be obtained any time in a query with
the Year and Month functions, so the UNION query on which an append query to
fill the Transactions table would be:

SELECT [TransactionDate],[Item], [Amount], [Category]
FROM [Income]
UNION ALL
SELECT [TransactionDate],[Item], [Amount] * -1, [Category]
FROM [Expenditure];

If you decide to create a Transactions table with separate Credit and Debit
columns then the UNION query would be:

SELECT [TransactionDate],[Item], [Amount] AS [Credit],
0 AS [Debit], [Category]
FROM [Income]
UNION ALL
SELECT [TransactionDate],[Item], 0, [Amount], [Category]
FROM [Expenditure];

Note how constant zeros are used in each case to enter this as a value in
the credit or debit column where appropriate. When designing this table
you'd set the Default Value properties of the Credit and Debit columns to
zero and their Required properties to True (Yes) so that they can't be Null
(Nulls cause problems in calculations). In this case the debits, being in a
separate column would be positive amounts, not negative, as with a single
Amount column, so you'd have to subtotal these rather differently to get the
balances in the report:

=Sum([Credit] - [Debit])

Ken Sheridan
Stafford, England
 
J

John W. Vinson

I can get reports of either income or expenditures, but not both. I'm aware
that I need to add relationships between the tables, but there's no
correlating information between the two tables. At first I tried using the
autonumber contact ID, and it worked great....until I deleted a record and it
threw the whole thing off. When I try to add a column with the same value in
both tables, I get two or three copies of each record in the table with less
entries.

I think my solution is to find a way to renumber the contact ID column for
each table when something is changed. Is there a way to do this, or another
way around this?

Autonumbers - for for that matter renumbering the ID <SHUDDER!> - are
certainly NOT going to work. As you say, income and expenditures are
independent; you CAN'T relate every record in your income table to "the
corresponding record" in the expenditures table, unless you have every single
paycheck allocated out to a fixed set of expenditures.

Instead, you can use a Report with two Subreports - one for income, one for
expenditures. Both these subreports can have totals and subtotals, and you can
pick these up on the mainform to get net balance.
 

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