Learning Microsoft Access 2007 - Invoices
Learning Microsoft Access 2007 - Invoices
Learning Microsoft Access 2007 - Invoices
By Greg Bowden
Chapter 12
Setting up an
Invoice System
www.gct.com.au
© Greg Bowden
Every effort has been made to ensure that images used in this
publication are free of copyright, but there may be instances where
this has not been possible. Guided Computer Tutorials would
welcome any information that would redress this situation.
Chapter
12
Setting up an Invoice System
To fully understand the value of relational databases you need to create a detailed
system. In this chapter you will setup an invoicing system for a computer mail order
company, PC Direct, which sells computer peripherals through the mail. The invoice
system will then be completed in the following three chapters. There are three main
sections to the system, customers, products and the sales invoice.
In the creation of any database system you should do some careful planning. In
general there are four steps that you should undertake.
1 Decide how many tables you think you might need.
2 Decide how the tables will be related to one another.
3 List the fields in each table trying to avoid having the same field in more than
one table. Decide which fields will be the PRIMARY KEY and FOREIGN KEY
fields to link the tables.
4 Decide what forms and/or reports (or printouts) are required.
In the case of PC Direct an initial TABLE RELATIONSHIP diagram might be:
The ONE invoice can have MANY items sold within it. The ONE product can be sold
MANY times. By adding the LINE ITEMS table to the system a series of ONE TO MANY
relationships are created and a relational database system can accommodate these.
The next step is to decide on the fields to be placed in each table. The following TABLE
STRUCTURE diagram shows one possibility. Remember, we do not want to store data
more than once (except for PRIMARY KEY or FOREIGN KEY fields).
Customers Invoice Line Items Products
1 1 1 Product ID
Customer ID Invoice No Invoice No
Title Customer ID M Product ID Product Name
First Name M Date Sold Qty Sold M Cost Price
Last Name Retail Price
Organisation Instock
Street Reorder Number
Suburb Location
State
Postcode
Phone
Fax
The PRIMARY KEY and FOREIGN KEY fields need to be considered. In the previous
diagram you would have see that CUSTOMER ID is used to link the CUSTOMERS and
INVOICE tables, INVOICE NO is used to link the INVOICE and LINE ITEMS tables and
PRODUCT ID is used to link the LINE ITEMS and PRODUCTS table. The INVOICE table
is not directly linked to the PRODUCTS table, it will obtain values from the PRODUCTS
table via the LINE ITEMS table.
The final consideration in the planning is what reports will be required. The following
diagram shows some of the reports that could be made from the various tables. We will
create some of these reports in the next chapter.
12-2 © Guided Computer Tutorials 2008
Setting up an Invoice System 12
NOTE: The LINE ITEMS table will record each line of the invoice. It will have two
main purposes:
(A) to list each product sold as a separate record so that the company
can calculate monthly sales and carry out stock checks.
(B) to provide product data to the invoice. If you look at the diagram
at the centre of page 12-2 you will see that the PRODUCTS table is
not directly connected to the INVOICE table so some data, such as
Product Name and Retail Price, will need to be linked to the LINE
ITEMS table via a relationship to the PRODUCTS table so that the
INVOICE can display them.
12-4 © Guided Computer Tutorials 2008
Setting up an Invoice System 12
NOTE: The AUTONUMBER field type will tell the program to provide a new
number every time an invoice is created so that no two invoices will
ever have the same number.
NOTE: i The PRIMARY KEY will index the table so that it is listed in INVOICE
NO order.
ii The format (00000) will set each number to five digits, for example,
00001, 00002, etc.
12-6 © Guided Computer Tutorials 2008
Setting up an Invoice System 12
3 To allow for linking of tables we should enter some test data which can be deleted
later.
NOTE: The AUTONUMBER command enters the INVOICE No for you and it
was formatted to 5 digits.
12-8 © Guided Computer Tutorials 2008
Setting up an Invoice System 12
5 Close the SHOW TABLE dialogue box
and move the CUSTOMER DETAILS,
LINE ITEMS and PRODUCT DETAILS
tables down by about 2 centimetres.
NOTE: The INVOICE DETAILS table is basically the control centre of the
system so we will display that table higher than the other tables.
12-10 © Guided Computer Tutorials 2008
Setting up an Invoice System 12
B Relating the Invoice Details and Line Items Tables
The INVOICE DETAILS table is related to the LINE ITEMS table as a ONE TO MANY
relationship using the INVOICE NO field. The ONE invoice can have MANY line items.
NOTE: The INVOICE NO field in the INVOICE DETAILS table is the PRIMARY
KEY (or PARENT) field and the INVOICE NO field in the LINE ITEMS
table is the FOREIGN KEY (or CHILD) field.
12-12 © Guided Computer Tutorials 2008