Training Module Access
Training Module Access
Training Module
9th January 2010
Training Module – MS Access
Limitations
Introduction– MS Access
In comparison, Access stores data in tables that look much the same as worksheets
but are designed for complex querying in relation to data stored in other tables and
locations, and even in fields in other tables.
So, while both programs work well for managing data, each one has clear
advantages depending on the type of data you are managing and what you want to
do with it.
Training Module – MS Access
"In Access, you have a primary key. In Excel, you have a cell
reference. In life, you have a PAN number. It's the best unique
identifier you have."
Ever noticed how, when at the office or calling an insurance company, you're asked
for your PAN number as well as your name?
Last name and even full name are often not unique. Unique identifiers are almost
always numeric. They preserve the integrity of your data and allow no duplicate
records or data in cells that you don't recognize (called Null values). Numeric
identifiers also provide the quickest way to retrieve data when searching or
sorting.
Introduction– MS Access
What is a database?
A database is a collection of similar information; storing
it on a computer provides a means of analyzing and
Processing this information.
Introduction– MS Access
Creating forms in Microsoft Access 2007 You can use filters and/or queries to
search a database. Access also has a report function which enables you to
analyze the results of a search in printed format or in another application such
as Microsoft Excel or Microsoft Word.
MS Access 2007 – 10 Benefits
Get better results faster with the Office Fluent user interface.
Get started quickly using prebuilt solutions.
Create multiple reports with different views of the same information.
Create tables quickly without worrying about database complexity.
Enjoy new field types for even richer scenarios.
Collect and update your information directly from the source.
Share your information with Microsoft Windows SharePoint Services.
Track Windows SharePoint Services lists with the rich client capabilities of
Office Access 2007.
Move data to Windows SharePoint Services for better manageability.
Access and use information from multiple sources.
Introduction– MS Access
tables
Queries • ask questions about information stored in your
Access-2007 Access-2003
File Extensions accdbx accdb
Creating a Database
1) Select Blank Database 2) In the File Name field enter a name for the database
Click Create
Creating a Database
Continue this until all necessary fields have been entered into the
table.
Note: The order that you enter the field names is the order the fields
will appear in the table and on a form.
To Enter Fields in a Table:
Entering Data in a Table
Once you have entered the fields and set the data types it is now time to enter
the records in a table.
To Enter Data in a Table:
1) Make sure you are in Datasheet View
2) Enter the data into the table by pressing the tab key to move from one cell
to another
3) When you have completed the record (row), press Enter
Entering Data in a Table
Use the arrows at the bottom of the table to navigate among records. You are able
to navigate from the first record, previous record, next record, last record, and
create a new record (as shown in the picture below).
Notice that the total number of records in the table is shown at the right end of
the navigation arrows.
At the Right bottom of the table, you may see the shortcut buttons
1. Datasheet View
2. PivotTable View
3. PivotChart View
4. Design View
Sorting Records in a Table
By sorting your records in a table, you are easily able to view/locate records in
your table.
To Sort Records in a Table:
1) Position your cursor in the field that you wish to sort by, by clicking on any
record in that field.
2) Click either the Sort Ascending or Sort Descending icon
Import / Link Data into Access
Sometimes, you will be required to pull data from Excel and from some other
sources and put it into Access. To do this,
go to External Data and click Excel. Import the source data into a new table
In the current database by browsing for the file you wish to import. From there,
you will be prompted through several options, which include selecting your
primary key, as well as selecting the data type.
Import / Link Data into Access
We can Import / Link data into Access from many sources Like
If you simply want to view the latest source data within Access for richer querying and
reporting, create a link to the text file in your database by using the Link Text Wizard.
A text file contains unformatted readable characters, such as letters and numbers, and
special characters such as tabs, line feeds and carriage returns. Access supports the
following file name extensions —.txt, .csv, .asc, and .tab.
Import / Link Data into Access
Import / Link Data from a Text file
During the import operation, you can specify how the source file is organized, and whether
you want to create a new table or append the data to an existing table.
Import / Link Data into Access
Import / Link Data from a Text file
When the process goes further, you have to choose the import style, as per the description
of your data.
To use a text file as a source file for importing or linking, the contents of the file
must be organized in such a way that the importing and linking wizards can divide
the contents into a set of records (rows) and each record into a collection of fields
(columns). Text files that are organized properly fall into one of two types
Delimited files :
In a delimited file, each record appears in a
separate line & the fields are separated by
a single character, called the delimiter. The
delimiter can be any character that does
not appear in the field values, such as a
tab, semicolon, comma, space, and so on.
The following is an example of comma-
delimited text.
Import / Link Data into Access
Import / Link Data from a Text file
Fixed-width files:-
In a fixed-width file, each record appears on a separate line and the width of
each field remains consistent across records. E.g. the first field of every record
is always seven characters long, the second field of every record is always 12
characters long, & so on.
If the actual length of a field's value varies from record to record, the values
that fall short of the required width must be padded with trailing space
characters. The following is an example of fixed-width text.
Import / Link Data into Access
Import / Link Data from a Text file
After specifying your data description and if your is data in delimited format,
please choose your delimiter…
Check the “First Row Select your delimiter and then press click button.
Contain field name button”
to make your first row, your
data Column heading
Import / Link Data into Access
Import / Link Data from a Text file
If your data hasn't got a column heading, you can give your column heading here and set
your data type…
There are two types of Keys in Access Primary Key & foreign Key?
Import / Link Data into Access
Primary & Foreign Key ………
Primary Key
If a column is declared as primary then there wont be any repeated values in that
column throughout that table, as well as it wont take any null values and we can
use primary key only once in a table.
Import / Link Data into Access
Primary & Foreign Key ………
Foreign Key
If a column is declared with this key then we have to use a reference i.e. we need
to give the column which will have the same values as this column and the table
that column belongs to.. this referred column of other table will be the primary
key of that table.
Import / Link Data into Access
Import / Link Data from a Text file
Please set a specific name to your table to complete the import process
Import / Link Data into Access
Import / Link Data from a Text file
At the end of the import operation, you can choose to save the details of the import
operation as a specification. An import specification helps you repeat the operation at a
later time without you having to step through the Import Text Wizard each time.
Import / Link Data into Access
Import / Link Data from a Text file
TIP:-
if you forgot to set the column heading at the time of importing, You can do column
heading name by clicking twice on the column heading
We can Import / Link data into Access from many sources Like
You are a long-time user of Excel but, going forward, you want to use Access to work
with this data. You want to move the data in your Excel worksheets into one or more new
Access databases.
Your department or workgroup uses Access, but you occasionally receive data in Excel
format that must be merged with your Access databases. You want to import these Excel
worksheets into your database as you receive them.
You use Access to manage your data, but the weekly reports you receive from the rest of
your team are Excel workbooks. You would like to streamline the import process to
ensure that data is imported every week at a specific time into your database.
Import / Link Data into Access
If this is the first time you are importing data from Excel
There is no way to save an Excel workbook as an Access database. Excel does not provide
functionality to create an Access database from Excel data.
(in the File Open dialog box, change the Files of Type list box to Microsoft Office Excel
Files and select the file you want),
Access creates a link to the workbook instead of importing its data. Linking to a
workbook is fundamentally different from importing a worksheet into a database.
Import / Link Data into Access
Start the import operation:-
On the External Data tab, in the Import group, click Excel.
In the Get External Data - Excel Spreadsheet dialog box, in the File name
box, specify the name of the Excel file that contains the data that you want
to import.
Click Browse and use the File Open dialog box to locate the file that you
want to import.
Specify how you want to store the imported data.
To store the data in a new table, select Import the source data into a new
table in the current database. You will be prompted to name this table
later.
To append the data to an existing table, select Append a copy of the
records to the table and select a table from the drop-down list. This option
is not available if the database does not contain any tables.
Import / Link Data into Access
Swift move to
your access file
and the paste
the data
Import / Link Data into Access
But before Copy & Paste, please keep some key Elements in your mind …
Element Description
The number of source columns that you want to import cannot exceed 255,
Number of columns because Access does not support more than 255 fields in a table.
Ensure that the cells are in tabular format. If the worksheet or named range
Tabular format includes merged cells, the contents of the cell are placed in the field that
corresponds to the leftmost column, and the other fields are left blank
If one or more cells in the worksheet or range contain error values, such as #NUM
Error values and #DIV, correct them before you start the operation.
To avoid errors during importing/copy the data, ensure that each source column
Data type contains the same type of data in every row.
If the first row in the worksheet or named range contains the names of the
columns, you can specify that Access treat the data in the first row as field names
First row during the import operation. If your source worksheet or range doesn't include
the names, it is a good idea to add them to the source before you start the import
operation.
Import / Link Data into Access
We can Import / Link data into Access from many sources Like
We can also import another Access table into Access … by following the same
process as we saw to import Text and Excel files..
Click the External Data and select Access from the menu to
import the access file into your database. Access will
ask you about the table name which you want to import in
your current database. We can also link the table by following the same process.
If you will link the table from another Access database, your linked table will
show the sign same as showing in the top left corner of the below picture
Working With Queries
In simple words Queries are questions you ask of your database. They
allow you to select certain fields out of a table, or pull together data
from various related tables and display it together. Queries can be used
to perform calculations, and to edit the data in your tables.
When you run a query, Access pulls data out of tables and puts the data in a database for
you to see. The original table and database stay connected, so that if you make changes to
the data in your database, the results of the query also change. When you save a query,
you save the query design, rather than the results, so that you can ask the same questions
again.11111
Working With Queries
Types Of Queries
Select Create new table in your database based on the results of a query.
Make Table Makes a new table based on the criteria within the query from an existing table.
Update Updates records in an existing table based on the criteria within the query
Delete Deletes records from a table based on the criteria within a query.
To Append your data in a another table of your database based on the criteria within a
Append query..
Working With Queries - Select
Select Query
When you want to select specific data from one or more sources, you
can use a select query. A select query helps you retrieve only the data
that you want, and also helps you combine data from several data
sources. You can use tables and other select queries as data sources for
a select query.
A select query is a database object that shows information in Datasheet
view(Datasheet view: A view that displays data from a table, form, query, view, or
stored procedure in a row-and-column format. In Datasheet view, you can edit
fields, add and delete data, and search for data.)
A query does not store data, it displays data that is stored in tables. A query can
show data from one or more tables, from other queries, or from a combination of
the two.
Working With Queries - Select
Showing all
table in your
database
Working With Queries - Select
As you select your desired field your query will look like:-
We need to understand below mentioned
row as shown in the picture
As we want to see those customer number where customer balance is > 500,
type >500 in criteria as shown in the picture below.
And then press run button (on the left top corner of your screen)
When working with select queries, you may need to specify one or more
criteria to limit the scope of information shown. You specify criteria by using
comparison operators in equations and calculations.
Use mathematical and string operators for creating calculated fields; use
relational and logical operators for specifying the criteria.
Working With Queries - Select
Not In
Working With Queries - Select
Common Operators Used in Select Queries
Using these operators, you can make out groups of records like these:
• Records that meet both AND and OR criteria, such as all record that have > Rs.
500 Usages & Or not either a particular service class.
Working With Queries - Select
Common Operators Used in Select Queries
Where you can use these operators:- Go to Create >> Query Design >> Select
Recharge Table.
Here are some more Examples:- Open your database and Try It ( txn_amt = MRP )
Working With Queries - Select
Common Operators Used in Select Queries
Select data with multiple tables We can also retrieve data from more than one
table in access.. Lets see HOW?
Please select another table from which you want to get the data. For example
please select the “MOU Report” table from show table window.
Working With Queries - Select
To capture the data from multiple tables in access, we need to set a relation
between the tables..
Like Lookups in Excel.. In Lookup function we need to have one field common in
between our data, the same concept in Access is called “Relationship “
What is Relationship
between the tables?
Relationship in Access
Relationship
These foreign key-primary key pairings form the basis for table relationships and multi-
table queries. It is important, therefore, that these foreign key-primary key references
stay synchronized.
Relationship in Access
Relationship
As you can see in the above picture the line between the two similar fields in
different tables, This is called relationship.
Relationship in Access
Relationship
To set Relationship between two fields we need to keep the following in mind:-
• 1st Option:- Query will return ONLY those numbers or row where joined
field have similar data.
• 2nd Option:- Query will return all number of your left table and also
give the desired data from the right table where the field of both
tables are equal.
• 3rd Option:- Query will return all number of your right table and also give
the desired data from the left table where the field of both
tables are equal.
Relationship in Access
As we have already done.. Now we have all the customer numbers having
balance > 500 Rs balance. Now we also want to see the MOUs of
these customers.
Pervious New
Query Query
with with
Single Multiple
Table Table
Working With Queries – Make Table
You use a make table query when you need to copy the data
in a table or archive data based on some criteria.
Working With Queries – Make Table
Process to Run a Make Table query is same as “Select” query. Set your
desired format or data as we have already done in Select Query and
then select the "Make Table Query” from the Query Tools option.
Working With Queries – Make Table
As you click on the Make Table Query Option.. Access will ask you the
New Table name which you want to make. As you enter the name of
your new table name
Access will create the table with your desired data.
You can also the save the
new table in the same database or into a
another database by selecting the “
Current Database” Or “Another Database” as shown in above
picture.
Working With Queries - Update
Update Query
Update Query updates specified values in a table for all records or for
those records that match a specified criteria.
The best way to handle this type of event, the updating of many records in a
database table, is to use an Update Query to make the changes to data in one
operation. You will save yourself time, and eliminate the possibility of manual
errors.
Working With Queries - Update
Update Query
Suppose we have table called Service Class Table
Update Query1
Update Query1
Select “Field name” from the table and in the Table Row “table name“ will show
automatically.
As you click on the “Builder"Button, One window will appear where you have to
Build your criteria.
With the help of builder expression
we can build our own logics and
formula to get / update the desired
info.
Click on the Table option and then
select your table “Service Class”. In
the next box list of all fields will
appear which are available in your
selected table. Double click on the
field name “service_class”.
Working With Queries - Update
Update Query
Given criteria in the builder Expression will Reflect in the Criteria Row
Working With Queries - Update
Press the “RUN” command And then Click Yes, Now you have updated your
records as per given criteria.
Note:- Please be careful while updating records. If you are not confident about your
criteria, it is suggested that before updating records please take a Backup copy of
your database.
Working With Queries - Update
Updated
Records
Working With Queries - Delete
Delete Query
Of all the queries, the delete query is the most dangerous. Unlike the other
types of queries you’ve worked with, delete query remove records from tables
permanently. Like other action queries, delete query acts on a group of
records on the basis of scoping criteria.
Because of the permanently destructive action of a delete query, always
make back-up copies of your tables before working with them.
Working With Queries - Delete
Delete Query
Will take the same example as we had done in the update query… but
this time we won’t update the records. We will in fact delete the records
based on the given criteria.
Delete Query
Delete Query
Delete Query
If you choose “Yes"Access will remove all the records where Service Class was “5066”
Working With Queries - Append
Append Query
For example, if you need to append all fields and all records from one table to a
new table, the append query is not the best way to do it. Instead, use the Copy and
Paste options on the Edit menu when you’re working with the table in a datasheet.
Working With Queries - Append
Append Query
Customer Master-1 has some data around 371790 Rows & on the other
side Customer Master- 2 has just 8 records.
Append Query
Append Query
As you select the append query, Access will ask you the table name
where you want to append the records.
Working With Queries - Append
Append Query
Select the table name from dropdown button or you can append your
records to another table of some other database by choosing “Another
Database”.
Or if you want to
append all fields,
Select field name
with SHIFT KEY.
Working With Queries - Append
If both the tables have the same field heading, so Access will take the field
name automatically..
Otherwise you to choose the field name manually from Append To Row. As
shown in the below mention picture.
Working With Queries - Append
After choosing the field name you have to set the criteria in criteria row, Based
on this criteria your records will be copied to another table.
?
Error …..!, lets see what was the Problem … Read the Error carefully and
Move to the Next slide.
Working With Queries - Append
Error was showing the “Duplicate Output destination” which means we are
appending some column twice..
Select the correct field from Append To Row, And Press RUN again..
Working With Queries - Append
You are about to append 787 Row (s) based on your criteria …
Press ok to copy 787 records into customer master - 2.. Click on No to hold the
operation.
Working With Queries - Append
Suppose you have a table that contains the sales figures of your entire
inventory for the whole year, and you want to know how much money was
made per product during each month of the year. This would be a perfect
opportunity to construct a crosstab query to display the information.
How many times have you used Pivot table in Excel, Crosstab Query is just like
the pivot table.. It’s the shortest way to see your data in a summarized way.
We have the data like Customer Master & in the same table we have Service
Class, Status of the customer etc.
Want to see this data like, What is my Customer Status by Service Class?, How
many customers are in Grace & How Many are Active…?
So Get Ready…
Working With Queries Wizard
List of tables in
your database
List of field(s)
selected by you
List of available
fields in your
selected table
Service Class
Count Of Customer
by cust_status
Working With Queries Wizard
Access 2007 has a built-in query wizard to help you find and fix
duplicate records in a table. This wizard can be quite powerful
since it not only helps you identify the duplicate records, it
allows you to include additional fields so that you can find
exactly where the duplicate records reside in your data table.
Working With Queries Wizard
Select the table where you want to find the duplicate records:-
One of the main advantages of Access is that it can finish thing much faster
However, this wizard only allows you to use one criteria to select
the non-matching records.
Working With Queries Wizard
For Example:- We have our Customer Master and MOUs report. We want to
check that how many customers have not generated MOU’s.
To solve this purpose we will use “Find Unmatched Query”.
Working With Queries Wizard
Want to reduce it … ?
Use “Compact & Repair”
• When you delete a database object, the disk space that the object occupied is
not automatically reclaimed — the database file still uses that disk space,
even though the object has been deleted.
How to Compact & Repair Database?
Open the Access database or Access project that you want Microsoft Access to compact
automatically.