EXCESS PROJECT Raza
EXCESS PROJECT Raza
COMPUTER
SUBMITTED TO SIR MUBASHER
HASSAN
Microsoft Access stores data in its own format based on the Access Jet Database Engine. It can
also import or link directly to data stored in other applications and databases.
Once you successfully launch and create your first database, Access opens up the “Table Tools”
View to create tables, because really, Access is all about tables!
Here, we will create a simple budget application with 3 tables: Regular Expenses, Monthly
Income and Monthly Expenses. The columns highlighted in blue are unique, and can hence be
used as the primary key. (Do note that where more than one column is highlighted in blue, the
combination together is unique.)
To add the Regular Expenses table, use the right-hand side tab.
The first column (ID) is auto-generated by Access and serves as the default primary
key. (We can change this later.)
Click on “Click to Add” to enter the next Column name. You will be given a (drop-
down) choice for type of column. Choose Text, and enter “Expense Name”.
Again Click to Add next column, choose Text and enter “Type”.
Again Click to Add next column, choose Number and enter “Amount”.
Finally, save your newly created table (using Control Key + “S” keys). When prompted
for a name, type “Regular Expenses”.
And there, freshly created, is your very own first Microsoft Access table. Hurray!
From the CREATE tab, use Create -> Table and follow the above steps to similarly create tables
“Monthly Income” and “Monthly Expenses”.
In this step, we will manually enter data into the tables. But do note that Access offers several
other effortless ways to import data into tables (from an Excel sheet, from a text file, etc.).
Here, we must mention that Access wins over Excel in data validation if the tables are rightly
designed. To understand the relevance of table design, we will simply add data to the “Regular
Expenses” table and explore the challenges.
The “Datasheet View” is best used to add/delete/alter table data, and opens up any time
you double click on a table’s name in the left-side tab. You can also access it using
DESIGN Tab -> View -> Design View. Once you’re in this view, choose the table you
will work with (“Regular Expenses”) in the left-side tab. On the right-side tab,
Click on the second column (Expense Name) and type “Rent”.
Click on the third column (Type) and type “Fixed”.
Click on the fourth column (Amount) and type “2000”.
You have completed the first row. Repeat for remaining rows.
Repeat the same for “Income” and “Monthly Expenses” table.
Did you notice how Access automatically sorts the data in increasing order of amount? If you
want to change this, you can right-click on the Amount field and change the sort order.
As you are sure to have observed, Access automatically generates a unique number for the first
column (ID), as this treats this as the default primary key. This is the column that is typically
used to retrieve unique rows of data from the table.
But this value may be difficult for us to remember as it has no relevance to our data. Also, we
have already identified our unique primary keys and should capture this in the table design. The
next step will show you how to re-design the table to take care of this.
Once you’ve created your tables, we bet you’re curious to see if they turned out okay. In fact, it’s
important to do this so you can include any additional rules for data validation and accuracy.
You can verify this in the “Design View”.
The more flexible Design View of Access is easily accessed using the DESIGN Tab -> View ->
Design View. (Alternately, you can click on the table name in the left-side tab, and choose
“Design View”.)
If you explore the “Regular Expenses” table (screenshot above), you’re sure to catch some
inconsistencies. Let’s fix this as follows:
By default, the auto-generated ID column is set as the primary key, and hence the small key icon
to its left. We change this by highlighting (single click) the Expense Name column, and choosing
the “Primary” Key icon on the top tab. (You can also right-click on the column name and choose
“Primary Key”). The key icon will change accordingly.
We no longer need the ID column. So right click on it and choose “Delete Rows”. This will
automatically delete this column (and all previously inserted values for it) from this table.
The Amount column is set to data type Number. Change this to Currency.
Now our table looks good. You can similarly edit the other 2 tables in Design view, to alter their
primary key, set currency data type and add additional data into all the tables so we can play with
it in successive steps.
Any time you want to simply “view” your table data, the Datasheet View can be used. But we
reckon you’d like to view the combined results of all your tables. This can be cumbersome to do
in Excel but is effortless in Access. The key is in defining table relationships.
Relationships define how our tables are “connected” to each other. These connecting links are
called “foreign keys” in Database jargon.
Once all 3 tables are visible, you can move them around the screen as you please.
But right now, there is nothing special about this view. Our tables are simply
listed, disconnected. To change this, click on REGULAR EXPENSES. Expense Name field, and
drag it towards MONTHLY EXPENSES. Expense Name field. A dialog box should open as
follows:
What we are doing here is creating a one-to-many relationship between the Expense Name of
Regular Expenses table, and the Expense Name of Monthly Expenses table.
For this,
“Enforce Referential Integrity” should be checked. This will ensure all added values in Monthly
Expense will be checked against the values of Regular Expenses table before addition.
Uncheck the tabs to “Cascade Update/ Delete Related Fields”. This will cascade all updates/
deletes in the primary key table (in our case, Regular Expenses). So if the amount is updated for
a particular expense, it will be cascaded in all related tables. Likewise with delete. We
deliberately uncheck this so we can catch any mismatch at a later time. Finally, click on Create.
Similarly, create a relationship between the Month Name of Monthly Expenses and Month Name
of Monthly Income. Uncheck “Enforce Referential Integrity” option here.
You have defined your first table relationship and are ready to get more out of your data!
This is perhaps the most significant and useful part of using Access over Excel. You see, we’ve
created our tables with the right design, added data and defined relationships. The next important
step is to put this all together and view what our combined data looks like. And this is done
through a QUERY.
Here, we will create a simple query to capture any mismatches in “fixed” expenses.
You can create a Query using the CREATE tab -> Query Wizard, the easiest way to create a
basic query. You will be prompted for:
Table names and fields. Choose Expense Name, Type & Amount from Regular Expenses, and
Month & Amount from Monthly Expenses.
Type “Fixed Expense Mismatch Report” when the wizard prompts you for a name and click on
Finish to generate the report query.
The generated query should look like this (without the red highlights):
But as you can see, this query shows all expense records, and not just the mismatched ones (as
highlighted in red). We can fix this using the Query Design (right-click on the query name in the
left-side tab and select “Design View”).
Under Regular Expenses.Type, add the value ‘Fixed’ under Criteria (include single quotes). This
restricts the data records retrieved to have type=Fixed.
Under any one of the amounts, add the special Criteria to check for a mismatch: “[Regular
Expenses].Amount <> [Monthly Expenses].Amount” (without quotes). The <> sign stands for
“not equal to”). This will pick up only mismatched records.