MS Access Basics PDF
MS Access Basics PDF
Microsoft Technologies
MS Access - Basics
Overview
Microsoft Access is a Database Management System (DBMS) from
Microsoft that combines the relational Microsoft Jet Database Engine with
a graphical user interface and softwaredevelopment tools. It is a member
of the Microsoft Office suite of applications, included in the professional
and higher editions.
It stores data in its own format based on the Access Jet Database Engine.
Like relational databases, Microsoft Access also allows you to link related
information easily. For example, customer and order data. However, Access
2013 also complements other database products because it has several
powerful connectivity features.
It can also import or link directly to data stored in other applications and
databases.
As its name implies, Access can work directly with data from other sources,
including many popular PC database programs, with many SQL (Structured
Query Language) databases on the desktop, on servers, on minicomputers,
or on mainframes, and with data stored on Internet or intranet web servers.
Access can also understand and use a wide variety of other data formats,
including many other database file structures.
You can export data to and import data from word processing files,
spreadsheets, or database files directly.
1|Page
Access can work with most popular databases that support the Open
Database Connectivity (ODBC) standard, including SQL Server, Oracle, and
DB2.
Data Input − After your database is created, the data of every business day
can be entered into the Access database.
Architecture
Access calls anything that can have a name an object. Within an Access
desktop database, the main objects are tables, queries, forms, reports,
macros, data macros, and modules.
If you have worked with other database systems on desktop computers, you
might have seen the term database used to refer to only those files in which
you store data.
But, in Access, a desktop database (.accdb) also includes all the major
objects related to the stored data, including objects you define to automate
the use of your data.
2|Page
1.RDBMS
Microsoft Access has the look and feel of other Microsoft Office products
as far as its layout and navigational aspects are concerned, but MS
Access is a database and, more specifically, a relational database.
Before MS Access 2007, the file extension was *.mdb, but in MS Access
2007 the extension has been changed to *.accdb extension.
Early versions of Access cannot read accdb extensions but MS Access 2007
and later versions can read and change earlier versions of Access.
It provides all the data definition, data manipulation, and data control
features that you need to manage large volumes of data.
A desktop database can also act as the data source for data displayed on
webpages on your company intranet.
Data Definition
Let us now understand what Data Definition is −
In spreadsheet, you can have text data at the top to define a column header
for printing or display, and you might have various numeric formats within
the same column, depending on the function of the row.
An RDBMS allows you to define the kind of data you have and how the data
should be stored.
3|Page
You can also usually define rules that the RDBMS can use to ensure the
integrity of your data.
For example, a validation rule might ensure that the user can’t accidentally
store alphabetic characters in a field that should contain a number.
Data Manipulation
Working with data in RDBMS is very different from working with data in a
word processing or spreadsheet program.
In a word processing document, you can include tabular data and perform a
limited set of functions on the data in the document.
You can also search for text strings in the original document and, with
ActiveX controls, include tables, charts, or pictures from other applications.
In a spreadsheet, some cells contain functions that determine the result you
want, and in other cells, you enter the data that provides the source
information for the functions.
An RDBMS provides you many ways to work with your data. For example,
You can search a single table for information or request a complex search
across several related tables.
You can update a single field or many records with a single command.
You can write programs that use RDBMS commands to fetch data that you
want to display and allow the user to update the data.
Access uses the powerful SQL database language to process data in your
tables. Using SQL, you can define the set of information that you need to
solve a particular problem, including data from perhaps many tables.
Data Control
Spreadsheets and word processing documents are great for solving
single-user problems, but they are difficult to use when more than one
person needs to share the data.
When you need to share your information with others, RDBMS gives you the
flexibility to allow multiple users to read or update your data.
4|Page
The best systems also allow you to group changes (which is also known as
transaction) so that either all the changes or none of the changes appear in
your data.
You might also want to be sure that no one else can view any part of the
order until you have entered all of it.
Because you can share your Access data with other users, you might need to
set some restrictions on what various users are allowed to see or update.
5|Page
2.Objects
MS Access uses “objects" to help the user list and organize information,
as well as prepare specially designed reports. When you create a
database, Access offers you Tables, Queries, Forms, Reports, Macros,
and Modules. Databases in Access are composed of many objects but the
following are the major objects −
Tables
Queries
Forms
Reports
Together, these objects allow you to enter, store, analyze, and compile
your data. Here is a summary of the major objects in an Access
database;
Table
Table is an object that is used to define and store data. When you create
a new table, Access asks you to define fields which is also known as
column headings.
Tables contain fields or columns that store different kinds of data, such as a
name or an address, and records or rows that collect all the information
about a particular instance of the subject, such as all the information about a
customer or employee etc.
You can define a primary key, one or more fields that have a unique value for
each record, and one or more indexes on each table to help retrieve your
data more quickly.
Query
An object that provides a custom view of data from one or more tables.
Queries are a way of searching for and compiling data from one or more
tables.
6|Page
When you build a query in Access, you are defining specific search conditions
to find exactly the data you want.
In Access, you can use the graphical query by example facility or you can
write Structured Query Language (SQL) statements to create your queries.
You can also define queries that create new tables from data in one or more
existing tables.
Form
Form is an object in a desktop database designed primarily for data input
or display or for control of application execution. You use forms to
customize the presentation of data that your application extracts from
queries or tables.
The reason forms are used so often is that they are an easy way to guide
people toward entering data correctly.
When you enter information into a form in Access, the data goes exactly
where the database designer wants it to go in one or more related tables.
Report
Report is an object in desktop databases designed for formatting,
calculating, printing, and summarizing selected data.
You can view a report on your screen before you print it.
If forms are for input purposes, then reports are for output.
Anything you plan to print deserves a report, whether it is a list of names and
addresses, a financial summary for a period, or a set of mailing labels.
Reports are useful because they allow you to present components of your
database in an easy-to-read format.
7|Page
Access offers you the ability to create a report from any table or query.
Macro
This object is a structured definition of one or more actions that you want
Access to perform in response to a defined event. An Access Macro is a
script for doing some job. For example, to create a button which opens a
report, you could use a macro which will fire OpenReport action.
You can include simple conditions in macros to specify when one or more
actions in the macro should be performed or skipped.
You can use macros to open and execute queries, to open tables, or to print
or view reports.
You can also run other macros or Visual Basic procedures from within a
macro.
Data macros can be attached directly to table events such as inserting new
records, editing existing records, or deleting records.
Data macros in web apps can also be stand-alone objects that can be called
from other data macros or macro objects.
Module
Module is an object in desktop databases containing custom procedures
that you code using Visual Basic. Modules provide a more discrete flow of
actions and allow you to trap errors.
Everything that can be done in a macro can also be done in a module, but
you don't get the macro interface that prompts you what is needed for each
action.
Modules are far more powerful, and are essential if you plan to write code for
a multi-user environment, because macros cannot include error handling.
8|Page
3.Create Database
In this chapter, we will be covering the basic process of starting Access
and creating a database. This chapter will also explain how to create a
desktop database by using a template and how to build a database from
scratch.
To view the all the possible databases, you can scroll down or you can
also use the search box.
Let us enter project in the search box and press Enter. You will see the
database templates related to project management.
9|Page
Select the first template. You will see more information related to this
template.
10 | P a g e
Now, press the Create option. Access will download that database
template and open a new blank database as shown in the following
screenshot.
11 | P a g e
Now, click the Navigation pane on the left side and you will see all the
other objects that come with this database.
Click the Projects Navigation and select the Object Type in the menu.
12 | P a g e
You will now see all the objects types — tables, queries, etc.
13 | P a g e
Step 2 − Select Blank desktop database. Enter the name and click the
Create button.
Step 3 − Access will create a new blank database and will open up the
table which is also completely blank.
14 | P a g e
4.Data Types
Every field in a table has properties and these properties define the
field's characteristics and behavior. The most important property for a
field is its data type. A field's data type determines what kind of data it
can store. MS Access supports different types of data, each with a
specific purpose.
The data type determines the kind of the values that users can store in any
given field.
Each field can store data consisting of only a single data type.
Here are some of the most common data types you will find used in a
typical Microsoft Access database.
15 | P a g e
If you use previous versions of Access, you will notice a difference for two of
those data types.
In Access 2013, we now have two data types — short text and long text. In
previous versions of Access these data types were called text and memo.
The text field is referred to as short text and your memo field is now called
long text.
Here are some of the other more specialized data types, you can choose
from in Access.
16 | P a g e
These are all the different data types that you can choose from when
creating fields in a Microsoft Access table.
17 | P a g e
5.Create Tables
When you create a database, you store your data in tables. Because
other database objects depend so heavily on tables, you should always
start your design of a database by creating all of its tables and then
creating any other object. Before you create tables, carefully consider
your requirements and determine all the tables that you need.
Let us try and create the first table that will store the basic contact
information concerning the employees as shown in the following table –
EmployeelD AutoNumber
18 | P a g e
Let us now have short text as the data type for all these fields and open
a blank database in Access.
This is where we left things off. We created the database and then
Access automatically opened up this table-one-datasheet view for a
table.
19 | P a g e
Let us now go to the Field tab and you will see that it is also
automatically created. The ID which is an AutoNumber field acts as our
unique identifier and is the primary key for this table.
The ID field has already been created and we now want to rename it to
suit our conditions. This is an Employee table and this will be the unique
identifier for our employees.
Click on the Name & Caption option in the Ribbon and you will see the
following dialog box.
20 | P a g e
We now have our employee ID field with the caption Employee ID. This is
automatically set to auto number so we don't really need to change the
data type.
21 | P a g e
Choose Short Text as the field. When you choose short text, Access will
then highlight that field name automatically and all you have to do is
type the field name.
Type FirstName as the field name. Similarly, add all the required fields
as shown in the following screenshot.
22 | P a g e
Once all the fields are added, click the Save icon.
You will now see the Save As dialog box, where you can enter a table
name for the table.
Enter the name of your table in the Table Name field. Here the tbl prefix
stands for table. Let us click Ok and you will see your table in the
navigation pane.
23 | P a g e
creating the following fields in this table. These tables will store some of
the information for various book projects.
Project ID AutoNumber
Contracts Attachment
ProjectStart Date/Time
ProjectEnd Date/Time
Budget Currency
24 | P a g e
In the tables group, click on Table and you can see this looks completely
different from the Datasheet View. In this view, you can see the field
name and data type side by side.
25 | P a g e
We now need to make ProjectID a primary key for this table, so let us
select ProjectID and click on Primary Key option in the ribbon.
26 | P a g e
You can now see a little key icon that will show up next to that field. This
shows that the field is part of the table’s primary key.
Click Ok and you can now see what this table looks like in the Datasheet
View.
27 | P a g e
Let us click the datasheet view button on the top left corner of the
ribbon.
28 | P a g e
If you ever want to make changes to this table or any specific field, you
don't always have to go back to the Design View to change it. You can
also change it from the Datasheet View. Let us update the PStatus field
as shown in the following screenshot.
29 | P a g e
6.Adding Data
An Access database is not a file in the same sense as a Microsoft Office
Word document or a Microsoft Office PowerPoint are. Instead, an Access
database is a collection of objects like tables, forms, reports, queries etc.
that must work together for a database to function properly. We have
now created two tables with all of the fields and field properties
necessary in our database. To view, change, insert, or delete data in a
table within Access, you can use the table’s Datasheet View.
A datasheet is a simple way to look at your data in rows and columns without
any special formatting.
Whenever you create a new web table, Access automatically creates two
views that you can start using immediately for data entry.
A table open in Datasheet View resembles an Excel worksheet, and you can
type or paste data into one or more fields.
You do not need to explicitly save your data. Access commits your changes to
the table when you move the cursor to a new field in the same row, or when
you move the cursor to another row.
By default, the fields in an Access database are set to accept a specific type
of data, such as text or numbers. You must enter the type of data that the
field is set to accept. If you don't, Access displays an error message −
Let us add some data into your tables by opening the Access database
we have created.
30 | P a g e
Select the Views → Datasheet View option in the ribbon and add some
data as shown in the following screenshot.
Similarly, add some data in the second table as well as shown in the
following screenshot.
31 | P a g e
You can now see that inserting a new data and updating the existing
data is very simple in Datasheet View as working in spreadsheet. But if
you want to delete any data you need to select the entire row first as
shown in the following screenshot.
Now press the delete button. This will display the confirmation message.
32 | P a g e
Click Yes and you will see that the selected record is deleted now.
33 | P a g e
7.Query Data
A query is a request for data results, and for action on data. You can use
a query to answer a simple question, to perform calculations, to combine
data from different tables, or even to add, change, or delete table data.
As tables grow in size they can have hundreds of thousands of records, which
makes it impossible for the user to pick out specific records from that table.
With a query you can apply a filter to the table's data, so that you only get
the information that you want.
Queries that you use to retrieve data from a table or to make calculations are
called select queries.
Queries that add, change, or delete data are called action queries.
You can also use a query to supply data for a form or report.
The tricky part of queries is that you must understand how to construct one
before you can actually use them.
34 | P a g e
35 | P a g e
In the tblEmployees table, double-click all those fields which you want to
see as result of the query. Add these fields to the query design grid as
shown in the following screenshot.
36 | P a g e
The query runs, and displays only data in those field which is specified in
the query.
37 | P a g e
8.Query Criteria
Query criteria helps you to retrieve specific items from an Access
database. If an item matches with all the criteria you enter, it appears in
the query results. When you want to limit the results of a query based on
the values in a field, you use query criteria.
Some criteria are simple, and use basic operators and constants. Others are
complex, and use functions, special operators, and include field references.
To add some criteria to a query, you must open the query in the Design
View.
You then identify the fields for which you want to specify criteria.
Example
Let’s look at a simple example in which we will use criteria in a query.
First open your Access database and then go to the Create tab and click
on Query Design.
38 | P a g e
39 | P a g e
Let us now add some field to the query grid such as EmployeeID,
FirstName, LastName, JobTitle and Email as shown in the following
screenshot.
40 | P a g e
Let us now run your query and you will see only these fields as query
result.
If you want to see only those whose JobTitle are Marketing Coordinator
then you will need to add the criteria for that. Let’s go to the Query
Design again and in Criteria row of JobTitle enter Marketing Coordinator.
41 | P a g e
Let us now run your query again and you will see that only Job title of
Marketing Coordinators are retrieved.
If you want to add criteria for multiple fields, just add the criteria in
multiple fields. Let us say we want to retrieve data only for “Marketing
42 | P a g e
Let us now run your query again and you will see the following results.
43 | P a g e
If you need to use the functionality of the AND operator, then you have
to specify the other condition in the Criteria row. Let us say we want to
retrieve all Accounting Assistants but only those Marketing Coordinator
titles with “Pollard” as last name.
Let us now run your query again and you will see the following results.
44 | P a g e
9.Action Queries
In MS Access and other DBMS systems, queries can do a lot more than
just displaying data, but they can actually perform various actions on the
data in your database.
Action queries are queries that can add, change, or delete multiple records at
one time.
The added benefit is that you can preview the query results in Access before
you run it.
o Append
o Update
o Delete
o Make-table
45 | P a g e
46 | P a g e
47 | P a g e
Now let us go back to Query design and select the Append button.
In the Query Type, select the Append option button. This will display the
following dialog box.
Select the table name from the drop-down list and click Ok.
48 | P a g e
In the Query grid, you can see that in the Append To row all the field
are selected by default except Address1. This because that Address1
field is not available in the TempEmployee table. So, we need to select
the field from the drop-down list.
49 | P a g e
50 | P a g e
Let us now run your query and you will see the following confirmation
message.
When you open the TempEmployee table, you will see all the data is
added from the tblEmployees to the TempEmployee table.
51 | P a g e
10.Create Queries
Let us understand how to create queries in this chapter.
52 | P a g e
On the Design tab, in the Query Type group, click Update and double-
click on the field in which you want to update the value. Let us say we
want to update the FirstName of “Rex” to “Max”.
53 | P a g e
In the Update row of the Design grid, enter the updated value and in
Criteria row add the original value which you want to be updated and run
the query. This will display the confirmation message.
Click Yes and go to Datasheet View and you will see the first record —
FirstName is updated to “Max” now.
54 | P a g e
55 | P a g e
On the Design tab, in the Query Type group, click Delete and double-
click on the EmployeeID.
In the Criteria row of the Design Grid, type 11. Here we want to delete
an employee whose EmployeeID is 11.
56 | P a g e
Let us now run the query. This query will display the confirmation
message.
Click Yes and go to your Datasheet View and you will see that the
specified employee record is deleted now.
57 | P a g e
Select all those fields which you want to copy to another table.
58 | P a g e
59 | P a g e
You will see the following dialog box. Enter the name of the new table
you want to create and click OK.
60 | P a g e
Click Yes and you will see a new table created in the navigation pane.
61 | P a g e
11.Parameter Queries
The best part about queries is that you can save and run the same query
again and again, but when you run the same query again and again by
only changing the criteria then you might consider the query to accept
parameters.
You can also specify what type of data a parameter should accept.
You can set the data type for any parameter, but it is especially important to
set the data type for numeric, currency, or date/time data.
When you specify the data type that a parameter should accept, users see a
more helpful error message if they enter the wrong type of data, such as
entering text when currency is expected.
If a parameter is set to accept text data, any input is interpreted as text, and
no error message is displayed.
Example
Let us now take a look at a simple example by creating a parameter
query. Let us open your database and select Query Design in the Create
table tab.
62 | P a g e
63 | P a g e
Select the field you want to see as a query result as shown in the
following screenshot.
In the query design grid, in the Criteria row of the ProjectStart column,
type [Enter a project start data]. The string [Enter a project start
data] is your parameter prompt. The square brackets indicate that you
want the query to ask for input, and the text is Enter a project start
data is the parameter prompt displays.
64 | P a g e
Let us now run your query and you will see the following prompt.
Click OK to confirm.
65 | P a g e
As a result, you will see the details of the project which started on
2/1/2007. Let us go to the Design View and run the query again.
Enter the date as in the above screenshot and click Ok. You will now see
the details of the project which started on 5/1/2008.
66 | P a g e
12.Alternate Criteria
Queries come in with many advantages. You can save and run the same
query again and again, and a lot of times you want to add alternate
criteria.
You can also use the query design grid, but instead of specifying criteria on
the same line, you will need to separate it in multiple row.
Example
Let us look at a simple example of alternate criteria. Open database and
in the Create tab select Query Design.
67 | P a g e
You can now see that alternate criterion is specified in different rows of
the LastName field. When you run this query, you will see the
employees whose last name is either Pollard or Manning. Let us now
run this query.
68 | P a g e
As you can see that only two employees have been retrieved, because of
the alternate criteria.
If you want to add alternate criteria in multiple fields then you will have
to use different rows for all the fields. Let us now add another alternate
criterion where we can retrieve information for employees whose last
name is either Pollard or Manning or the job title is Accounting
Assistant.
69 | P a g e
70 | P a g e
13.Relating Data
In this chapter, we will understand the basics of relating data. Before
talking about and creating relationships between different data, let us
review why we need it. It all goes back to normalization.
Normalization
Database normalization, or simply normalization, is the process of
organizing columns (attributes) and tables (relations) of a relational
database to minimize data redundancy. It is the process of splitting data
across multiple tables to improve overall performance, integrity and
longevity.
Let us now look into the following table which contains data, but the
problem is that this data is quite redundant which increases the chances
of typo and inconsistent phrasing during data entry.
71 | P a g e
To solve this problem, we need to restructure our data and break it down
into multiple tables to eliminate some of those redundancy as shown in
the following three tables.
Here, we have one table for Customers, the 2nd one is for Orders and the
3rdone is for Cookies.
The problem here is that just by splitting the data in multiple tables will
not help to tell how data from one table relates to data in another table.
To connect data in multiple tables, we have to add foreign keys to
the Orders table.
Defining Relationships
A relationship works by matching data in key columns usually columns
with the same name in both the tables. In most cases, the relationship
matches the primary key from one table, which provides a unique
identifier for each row, with an entry in the foreign key in the other table.
There are three types of relationships between tables. The type of
relationship that is created depends on how the related columns are
defined.
One-to-Many Relationships
A one-to-many relationship is the most common type of relationship. In
this type of relationship, a row in table A can have many matching rows
72 | P a g e
in table B, but a row in table B can have only one matching row in table
A.
Many-to-Many Relationships
In a many-to-many relationship, a row in table A can have many
matching rows in table B, and vice versa.
For example, the Customers table and the Cookies table have a many-to-
many relationship that is defined by a one-to-many relationship from
each of these tables to the Orders table.
One-to-One Relationships
In a one-to-one relationship, a row in table A can have no more than one
matching row in table B, and vice versa. A one-to-one relationship is
created if both the related columns are primary keys or have unique
constraints.
Store data that is short-lived and could be easily deleted by simply deleting
the table.
73 | P a g e
14.Create Relationships
In this chapter, we will understand the need to create relationships
between related tables. One of the goals of good database design is to
remove data redundancy.
To achieve that goal, you divide your data into many subject-based tables so
that each fact is represented only once.
To do this, all the common fields which are related to each other are placed
in one table.
To do this step correctly, you must first understand the relationship between
your tables, and then specify these relationships in your Access database.
To work with records from more than one table, you often must create a
query that joins the tables.
The query works by matching the values in the primary key field of the first
table with a foreign key field in the second table.
When you design a form or report, MS Access uses the information it gathers
from the table relationships you have already defined to present you with
informed choices and to prepopulate property settings with appropriate
default values.
When you design a database, you divide your information into tables, each of
which has a primary key and then add foreign keys to related tables that
reference those primary keys.
These foreign key-primary key pairings form the basis for table
relationships and multi-table queries.
Let us now add another table into your database and name
it tblHRData using Table Design as shown in the following screenshot.
74 | P a g e
75 | P a g e
76 | P a g e
15.One-To-One Relationship
Let us now understand One-to-One Relationship in MS Access. This
relationship is used to relate one record from one table to one and only
one record in another table.
77 | P a g e
Select tblEmployees and tblHRData and then click on the Add button
to add them to our view and then close the Show Table dialog box.
78 | P a g e
To create a relationship between these two tables, use the mouse, and
click and hold the EmployeeID field from tblEmployees and drag and
drop that field on the field we want to relate by hovering the mouse right
over EmployeeID from tblHRData. When you release your mouse
button, Access will then open the following window −
79 | P a g e
80 | P a g e
Here, on the left-hand side of each and every record, you will see a little
plus sign by default. When you create a relationship, Access will
automatically add a sub-datasheet to that table.
81 | P a g e
Let us click on the plus sign and you will see the information that is
related to this record is on the tblHRData table.
82 | P a g e
Click on the Save icon and open tblHRData and you will see that the
data we have entered is already here.
83 | P a g e
16.One-To-Many Relationship
The vast majority of your relationships will more than likely be this one
to many relationships where one record from a table has the potential to
be related to many records in another table.
Let us first clear the layout by clicking on the Clear Layout option on
the Design tab.
84 | P a g e
85 | P a g e
Click on the Save icon and enter tblTasks as the table name and go to
the Relationship view.
86 | P a g e
Add tblProjects and tblTasks and close the Show Table dialog box.
We can run through the same process once again to relate these tables.
Click and hold ProjectID from tblProjects and drag that all the way over
to the ProjectID from tblTasks. Further, a relationships window pops up
when you release the mouse.
Click the Create button. We now have a very simple relationship created.
87 | P a g e
88 | P a g e
17.Many-To-Many Relationship
In this chapter, let us understand Many-to-Many Relationship. To
represent a many-tomany relationship, you must create a third table,
often called a junction table, that breaks down the many-to-many
relationship into two one-to-many relationships. To do so, we also need
to add a junction table. Let us first add another table tblAuthers.
89 | P a g e
Select the Author field and press the delete button and you will see the
following message.
Click Yes. We will now have to create a junction table. This junction table
have two foreign keys in it as shown in the following screenshot.
90 | P a g e
These foreign key fields will be the primary keys from the two tables that
were linked together — tblAuthers and tblProjects.
To create a composite key in Access, select both these fields and from
the table tools design tab, you can click directly on that primary key
and that will mark not one but both of these fields.
91 | P a g e
The combination of these two fields is the tables’ unique identifier. Let
us now save this table as tblAuthorJunction.
Select the above three highlighted tables and click on the Add button and
then close this dialog box.
Click and drag the AuthorID field from tblAuthors and place it on top
of the tblAuthorJunction table AuthorID.
92 | P a g e
The relationship you’re creating is the one that Access will consider as a
one-to-many relationship. We will also enforce referential integrity. Let
us now turn on Cascade Update and click on the Create button as in
the above screenshot.
93 | P a g e
Let us now hold the ProjectID, drag and drop it right on top
of ProjectID from tblAuthorJunction.
95 | P a g e
18.Wildcards
Wildcards are special characters that can stand in for unknown
characters in a text value and are handy for locating multiple items with
similar, but not identical data. Wildcards can also help with getting
databased on a specified pattern match.
ANSI-89
ANSI-92
You use the ANSI-92 wildcards when you run queries against Access
projects — Access files connected to Microsoft SQL Server databases.
Access projects use the ANSI-92 standard because SQL Server uses that
standard.
? Matches any single alphabetic character. B?ll finds ball, bell, and
bill.
[] Matches any single character within the B[ae]ll finds ball and bell,
brackets. but not bill.
96 | P a g e
! Matches any character not in the b[!ae]ll finds bill and bull,
brackets. but not ball or bell.
# Matches any single numeric character. 1#3S finds 103, 113, and
123.
[] Matches any single character within the B[ae]ll finds ball and bell,
brackets. but not bill.
97 | P a g e
Example
Let us now look at a simple example of using these wildcard characters
by opening the query design.
Add the highlighted tables and close the Show Table dialog box.
Add the fields in the query grid which you want to see as a query result.
98 | P a g e
Let us again go to the query design and add prompt for project name.
99 | P a g e
Now run your query and let us assume that you don’t know the exact
project name, but you know that the project name contains the words
“potion”. Click Ok.
The above step does not generate any result. That is because Access is
looking for an exact match in the project name field. It is looking for
that project which has the word potion in its name.
If you want it so that the users can enter wildcards to replace unknown
characters, then you need to adjust the criteria and include the
operator like.
100 | P a g e
When you run the query, users can use wildcards to replace any number
of characters.
101 | P a g e
Let us assume that you know that the word potion appears somewhere
in the title but you are not exactly sure where.
You can add an * to replace any number of characters before the word
potion and then add another * after the. Click Ok.
It is always good for the users to know the wildcards they can enter. But
there are users who may not know the wildcards they can and cannot
enter. In that case, you can enter the wildcards yourself.
102 | P a g e
Let us now run our query again. Enter the word potion in the prompt
without any wildcards.
The query will now track those wildcards on either side of whatever is
entered here. We need to simply type potion and press enter.
103 | P a g e
We now get the results we were looking for and the results will be the
same regardless of what the users enter.
Let us say we want to find every project with the word “the” in the title.
Then, you need to just type the word and Enter or click Ok.
104 | P a g e
With this query, it becomes easier to search for projects with the word
“the” in their names. The 2nd level of results may also include the project
names with the word “mother” where “the” is part of the word.
105 | P a g e
19.Calculated Expression
In MS Access, an expression is like a formula in Excel. This consists of a
number of elements that can be used alone or in a combination to
produce a result. Expressions can include operators’, constants, functions
and identifiers.
Example
Let us try an example to understand this. We will be retrieving some
information from a variety of tables — tblCustomers, tblOrders,
tblOrdersDetails and tblBooks and reviewing a variety of fields.
106 | P a g e
Let us now run the query and you will see the following results.
We want a very simple calculation for a subtotal which will take the
quantity of the books ordered and multiply that by the retail price of the
book. It is a good idea to begin every expression or any expression with
a name to call that field. Let us call this one subtotal.
look inside that table for a field QTY and multiply that by the retail price
field in tblBooks.
Let us try to run your query and you will see at end the subtotal field.
Let us say we want to calculate our sales tax. In the query grid we will
do in the exact same way we did before and this time we will call the
field simply Tax and Let us multiply Subtotal by nine percent tax rate.
108 | P a g e
Let us run your query again and you will see the new Tax field in the
end.
109 | P a g e
20.Indexing
An index is a data structure, a special data structure designed to improve
the speed of data retrieval. If you often search a table or sort its records
by a particular field, you can speed up these operations by creating an
index for the field. Microsoft Access uses indexes in a table as you use an
index in a book to find data.
An index stores the location of records based on the field or fields that you
choose to index.
After Access obtains the location from the index, it can then retrieve the data
by moving directly to the correct location.
In this way, using an index can be considerably faster than scanning through
all of the records to find the data.
Indexes can speed up searches in queries, but they can also slow down
performance when adding or updating records.
Let us now look into what indexes Microsoft Access creates by default
and how to create them ourselves and learn how to delete any
unnecessary indexes. Open the tblEmployees table in Access database
which we have created.
We haven't really played with indexes in this database but that doesn't mean
we don't have any.
110 | P a g e
111 | P a g e
If you want to make any field indexed you can go to the Field tab.
Select any field that you want indexed and check the Indexed checkbox
in Field Validation section. You also have alternate options for creating or
removing an index. You can go back to the Design View.
112 | P a g e
You can adjust indexes by selecting any field. You can also see how they
are indexed in the field properties area below. Any field that
has No selected next to indexed, means there is no index for that given
field. You can change that by clicking on the drop-down menu and
choosing the other two options — Yes (Duplicate OK) and Yes (No
duplicates).
113 | P a g e
The last option Yes (No Duplicates) means that Access will
automatically prohibit duplicate values in that field. Let us now create an
index for our last name field.
114 | P a g e
If you click on this Indexes button that will bring up a special view
displaying all the indexes created for this table.
We now have two indexes for tblEmployees —one that was created
automatically based on the primary key field and one that we just
created for the LastName field. These are the different ways to deal with
indexes in Microsoft Access tables.
115 | P a g e
21.Grouping Data
In this chapter, we will be covering how to calculate on a group of
records in Access. We have created a field that calculates row by row or
record by record to create a line total or subtotal field, but what if we
wanted to calculate down by a group of records rather than by individual
ones. We can do this by creating what's known as an Aggregate Query.
Aggregate Query
An aggregate query also known as a totals or summary query is a sum,
mass or group particulars. It can be a total or gross amount or a group
or subset of records. Aggregate queries can perform a number of
operations. Here's a simple table listing some of the ways to total on a
group of records.
1. Sum
2. Avg
3. Min
4. Max
5. Count
116 | P a g e
6. StDev
7. Var
Let us open your database and go to the Query Design and include the
following tables −
Close this dialog box and the following two fields will be displayed as
shown in the query grid in the following screenshot.
117 | P a g e
This is a simple query and we are displaying only two fields — book
title and quantity and when we run it we're seeing every single
individual order in our database.
Let us now run this query and you will see the following results.
118 | P a g e
This is why book titles are repeating. Separate orders have been placed
for each of these books here and they were ordered in different
quantities. Let us assume we want to see a summary of only that book
title that has been listed only once. And then the sum of the quantity
listed beside it.
Let us now go to the Design View and in the Design tab, you will see a
Sigma symbol. This is your totals button.
Click the sigma symbol which will open another row underneath your
field in the table row and from here, you can specify how you are
grouping this query.
119 | P a g e
We will now group by book title and also sum our quantity field.
120 | P a g e
You can now see each individual book and also all the individual orders
displayed beside the book name.
Concatenation in Access
We learned the process of normalization, storing information in separate
fields. Sometimes you want to see or view data together like combining
the first name and last name fields as a single field. You can display that
information together by creating a calculated field that concatenates one
or more strings. You can also add other characters like a comma or
period that you may want.
To concatenate in Access, there are two different operators you can use
the ampersand (&) and the plus (+) sign.
The ampersand will combine two strings into one whereas the plus sign will
combine two strings and propagate NULL values, for example, if one value is
NULL the entire expression evaluates to null.
Example
Let us take a simple example to understand the process of creating a
new query using query design. This is going to be a very simple query
that is pulling information from our customers’ table.
121 | P a g e
Let us now add tblCustomers table close that show table dialog box. We
will try some concatenation with some simple named fields.
Let us now add the first name and last name fields and run the query.
As you can see, the first name and the last name are separated into two
different fields.
122 | P a g e
Go back to the Design View and in the third field create a new field
called full name. Now, add the full name and type the expression that
concatenates those two fields together.
123 | P a g e
Let us run the query and you will see a new calculated field.
It can concatenate the information from these two fields together, but it
doesn't exactly appear the way we want it to. It runs all of that text
together because it's performing the way we have asked it to. We will
now have to ask Access to add space in between the information from
these two fields.
124 | P a g e
Let us now go back to the Design View and add another section to this
expression.
Add a Space inside quotes and another ampersand. This makes Access
take the information from that first name field; add it with a space and
then add the information from the last name field at the very end. Now,
run the query again and you will see the following results.
125 | P a g e
22.Summarizing Data
Aggregate queries are great if you are looking just for one specific
number, but if you want summarizing information like a spreadsheet-like
summary you might want to consider trying a crosstab query. When you
want to restructure summary data to make it easier to read and
understand, consider using a Crosstab Query.
A crosstab query is a type of Select Query. When you run a crosstab query,
the results get displayed in a datasheet. This datasheet has a different
structure from the other types of datasheets.
The structure of a crosstab query can make it easier to read than a simple
select query that displays the same data, as shown in the following
screenshot.
In the above dialog box, you can see all kinds of special queries. You can
create a simple query wizard like how we have been doing so far from
126 | P a g e
the Design View. The second one is the one we want — the crosstab
query that displays data in a compact spreadsheet like format. Now,
select the crosstab query and click Ok.
The first screen in the Wizard is going to prompt what table or query
contains the fields that you want for your Crosstab Query results. Click
on the Queries radio button and select qryOrdersInformation — this
is the one that we created earlier which contain the subtotal, sales tax
etc. Click Next.
127 | P a g e
We will now look into the available fields from that query. It will prompt
you to enter the field values that you want as row headings. Let us say
we want a simple list of all of our different book titles. Now select the
book title fields and send that over to your selected field area and
click Next.
128 | P a g e
In the above dialog box, the question is what you want to use as column
headings and that really depends on what you want to evaluate. Let us
assume that you want to view our sales by date,
choose TransactionDate and click Next.
The question in the above dialog box is a specialized one based on the
field we previously selected since we chose a date time column. It is
asking if we want to group our date time column information by a
specific interval. Select the year option and click Next.
129 | P a g e
The next question in the above dialog screen asks what number do you
want calculated for each column in the row intersection. In this case, we
can go by quantity of the books sold by selecting quantity (QTY) and
Sum from the functions and click Next.
130 | P a g e
The very last screen of your wizard is going to ask what do you want
to name your query and further, click Finish to View that query.
We now have book by book information and also information on the total
sales like when each one of those sales occurred.
131 | P a g e
23.Joins
A database is a collection of tables of data that allow logical relationships
to each other. You use relationships to connect tables by fields that they
have in common. A table can be part of any number of relationships, but
each relationship always has exactly two tables. In a query, a
relationship is represented by a Join.
What is Join
A join specifies how to combine records from two or more tables in a
database. Conceptually, a join is very similar to a table relationship. In
fact, joins are to queries what relationships are to tables.
The following are the two basic types of joins that we will be discussing
in this chapter −
Inner Join
Let us now understand Inner Join −
The most common type of join is an inner join which is also the default join
type in Microsoft Access.
Inner Join will display only the rows or records where the joined fields from
both tables are equal.
This join type looks at those common fields and the data contained within. It
only displays the matches.
132 | P a g e
Outer Join
Let us now understand what an Outer Join is −
An outer join displays all rows from one table and only those rows or records
from the other table where the joined fields are equal.
In other words, an outer join shows all rows from one table and only the
corresponding rows from the other table.
You can choose the table that will display all rows.
You can create a Left Outer Join which will include all the rows from the first
table.
You can create a Right Outer Join that will include all the rows from the
second table.
133 | P a g e
Let us now go to the Create tab and create a query from the Design
View. Select tblProjects and tblTasks and close the Show Table dialog
box as in the following screenshot.
134 | P a g e
135 | P a g e
It is showing us only the matches, so when we run this query, there are a lot
of other projects listed in tblProjects that do not appear as part of our
records set in this query, and that is because of how these two tables are
joined together, through that Inner Join, which is again, that default Join for
any query.
However, if you want to alter the relationship, Let us say you want to
create an outer join, or in other words, show all of the projects
from tblProjects, every single record that is in that table, along with all
of the tasks from tblTasks — Open join properties; we can do this
simply by double-clicking on the relationship line.
Access will display the left table name and the right table name in Join
Properties dialog.
The left column name and the right column name and the first radio button is
to only include rows where the join fields from both tables are equal and that
136 | P a g e
is the inner join and that is what is selected by default when creating
relationships, when creating a join in the query, but, you can change it.
We have a third option, include all records from tblTasks and only those
records from tblProjects where the joined fields are equal and this one is
Right Outer Join.
Those are the different types of joins you can create easily from the
Design View. Let us select the second option, which is Left Outer Join,
and click Ok.
When you look at the relationship line, you will see a little arrow pointing
towards ProjectID in tblTasks. When you run this query, you will see
the following results.
137 | P a g e
As you can see that it is showing us every single project name, whether
or not it has a related task. You will also see a bunch of null fields. All of
this will be blank because there is no related information in tblTasks,
where these fields come from. Let us now go to the Design View again
and double-click on the relationship line.
In the Join Properties dialog box, select the third option which is for the
Right Outer Join and click Ok.
138 | P a g e
Now look at our relationship line. You will see that a little arrow is now
pointing towards ProjectID in tblProjects. When you run this query
you will see the following results.
139 | P a g e
Self-Joins
Self-join is another type of Join. A Self-join relates matching fields from
within the same table. For example, look at the employee's table with a
supervisor field, which references the same kind of number stored in
another field within the same table — the employee ID.
140 | P a g e
This table is not the ideal structure for a relational database because it's
not normalized.
If we have a situation where we want to create a query that just lists the
employee names alongside the names of their supervisors, there is no
easy way we can query that unless we create a Self-join.
To see a Self-join, create a table with the following fields and enter some
data.
141 | P a g e
Here we want to create a list again with the first name of the employee
and then the name of the supervisor. Let us create a query from
the query design view.
142 | P a g e
Now, add the first name and last name for our employees.
We now need a way to create a relationship between this table and itself.
To do that, we need to open the show table dialog box and add
tblEmployees one more time.
143 | P a g e
We have created another copy of the same table in this query view. Now,
we need to create Self-join. To do that, click on Supervisor
in tblEmployees table and hold the mouse button and drop it right on
top of the EmployeeID in that copied table — tblEmployees_1. Then,
add the first name and last name from that copied table.
144 | P a g e
Let us now run your query and you will see the following results.
It displays the names of the employees along side the names of their
supervisors. And, this is how you create a Self-join in Microsoft Access.
145 | P a g e
Example
In a customer's table, you can have the same customer accidentally
added twice. In such cases, the customer will have the same address,
but different customer IDs, which can create problems with reporting. In
this situation, you can make use of the duplicates query wizard to
quickly locate possible duplicate entries.
Let us now open our Access database which contains tblAuthers table
and go the Create tab and, in the queries group, select query wizard.
If you see the following screenshot, you have four different wizards to
choose from. Select the find duplicates query wizard and click Ok.
146 | P a g e
The very first screen of the find duplicates query wizard will ask what
table or what query you want to search for possible duplicates. Let us
say we want to check our author's table to make sure that the same
author hasn't accidentally been entered twice. So, select tblAuthors and
click Next.
147 | P a g e
The second screen in the wizard will ask what fields might contain duplicate
information.
Typically, you will not be using your primary key field, because, again, when
you designate a field in Access as a primary key, Access will not allow
duplicates to be entered.
We can search by the last name or the first name and the last name, or
you can search by their street address, or to be more specific with their
telephone number or birthday.
Let us now search by the first name, the last name, and birthday and
click Next.
148 | P a g e
The following screen in this wizard will ask for the fields we want to be
displayed in our query. For this, hit the double arrow, all of the fields will
move over to the additional query fields area, and will be added to our
query results.
149 | P a g e
Let us now click Next. It will take us to the last screen in this query
wizard.
In the following screen, enter how do you want to name your query.
150 | P a g e
By default, it's going to name it find duplicates for plus whatever the
name of the object that you're querying. In this case, tblAuthors,
but you can give it any other name too and click finish.
151 | P a g e
This one has definitely been entered twice by accident. We have now
added all of the fields to our query, we could just go and delete the
record. We also have to make sure that we don't have any related
records in another table.
152 | P a g e
Select any record and choose Delete as in the following dialog box.
Access gives you a prompt, “You are about to delete one record.” Click
Yes if you want to continue.
If you'd like to see how that wizard has created this query, go into the
Design View and see what all has been added to this query.
153 | P a g e
As you can see in the above screenshot, we have our fields and some
specific criteria underneath the first name field.
154 | P a g e
This is the default join in Access, for example, if we design a query with two
tables, tblCustomers and tblOrders, and join those two tables by the
CustomerIDs, this query will return only the results that match. In other
words, the customers who have placed orders.
There are times when we don't want to see the matches, for instance, we
may not want to see any customer in our database — the customers who
have not placed orders as yet.
There are many other possible uses for this kind of query as well.
155 | P a g e
In our database, we can use it to see which authors have not yet written
a project or you could use it to see which employees have not yet elected
any health benefits. Let us now open your database which
contains Customers and Orders table; go to the Create tab and click on
the query wizard button.
In this scenario, we will look out for those customers who have not
placed an order. In the first screen it's asking which table or query
contains the records you want in the query results.
156 | P a g e
157 | P a g e
This will typically be some kind of primary key, foreign key, field, or
relationship.
If you have an existing relationship in your database, Access will select and
match those fields for you.
But, if you have other fields that you can join together, contain similar
information, you can choose that here as well.
158 | P a g e
In the following screen, you can pick and choose the fields you want to
see displayed in the query results.
159 | P a g e
Let us now select all the available fields and click on the double-headed
arrow. This moves all the available fields over to the selected
fields area. Now, click Next.
The last screen will allow you to choose a name for your query and
click Finish.
160 | P a g e
Here we have one customer listed as that customer who has not placed
an order with us yet.
You can also see how that query was created. For this, you need to go
back to the Design View.
161 | P a g e
162 | P a g e
26.Create Form
Forms in Access are like display cases in stores that make it easier to
view or get the items that you want. Since forms are objects through
which you or other users can add, edit, or display the data stored in your
Access desktop database, the design of your form is an important aspect.
There's a lot you can do design-wise with forms in Microsoft Access. You
can create two basic types of forms −
Bound forms
Unbound forms
Bound Forms
Let us now understand what Bound Forms are −
Bound forms are connected to some underlying data source such as a table,
query, or SQL statement.
Bound forms are what people typically think of when they think of the
purpose of a form.
Examples of bound forms will typically be what users use to enter, view or
edit data in a database.
Unbound Forms
Let us look into Unbound Forms −
In other words, unbound forms are typically used to navigate or interact with
the database at large, as opposed to the data itself.
163 | P a g e
Split Form
The form is divided into halves, either vertically or horizontally. One half
displays a single item or record, and the other half displays a list or
provides a datasheet view of multiple records from the underlying data
source.
Creating Forms
There are a few methods you can use to create forms in Access. For this,
open your Database and go to the Create tab. In the Forms group, in
the upper right-hand corner you will see the Form Wizard button.
164 | P a g e
On this first screen in the wizard, you can select fields that you want to
display on your form, and you can choose from fields from more than
one table or a query.
Let us assume we want to simply have a quick form that we are going to
use for data entry for our employee information.
Let us just leave it with that one table, and click Next.
165 | P a g e
The following screen in the Form Wizard will ask for the layout that we
would like for our form. We have columnar, tabular, datasheet and
justified layouts. We will choose the columnar layout here and then
click Next.
166 | P a g e
In the following screen, we need to give a title for our form. Let us call
it frmEmployees.
Once you have given your form a title, you can open the form to see
what that form looks like, or you can begin entering information into
your table. Or you can choose the option to modify the form's design. Let
us choose the first option to open the form to view or enter
information and click Finish.
Now, take a look at the following screenshot. This is what your form
looks like. This is a single item form, meaning one record is displayed at
a time and further down you can see the navigation buttons, which is
telling us that this is displaying the record 1 of 9. If you click on that
button then, it will move to the next record.
167 | P a g e
If you want to jump to the very last record in that form or that table, you
can use the button right beside that right arrow, the arrow with a line
after it, that's the last record button. If you want to add new employee
information, go to the end of this records and then after 9 records you
will see a blank form where you can begin entering out the new
employee's information.
168 | P a g e
169 | P a g e
This is one example of how you can create a form using the Form
Wizard. Let us now close this form and go to the Create tab. Now we will
create a slightly more complicated form using Wizard. Click the Form
Wizard and this time, we will choose fields from a couple of different
tables.
170 | P a g e
Now select tblTasks for Tables/Queries and send over the TaskID,
ProjectID, TaskTitle, StartDate, DueDate and PercentComplete.
Click Next.
171 | P a g e
172 | P a g e
In the following screen, you can choose a layout for your subform. The
Datasheet View gets selected by default. The Datasheet View is similar to
Table View. Now, click Next.
173 | P a g e
In the following screen, you need to provide a name for your forms.
Enter the name you want and click Finish.
174 | P a g e
Access will give you a preview of what your form looks like. On top, you
have the controls on your main form, which is from our Projects table.
As you go down, you will see a subform. It's like a form within a form.
175 | P a g e
To create this type of form, you will need to select the object in
navigation pane first. Let us select tblEmployees here.
176 | P a g e
177 | P a g e
The above step will further create a Multiple Items form, listing out all
the employees.
Split Form
This type of form is divided in equal halves, either vertically or
horizontally. One half displays a single item or record, and the other half
displays a list or a datasheet view of multiple records from the underlying
data source.
178 | P a g e
27.Modify Form
We have learnt several ways to create simple data entry forms. Although
the forms ease the process of data entry; these may not serve other
purposes that you would want. They may not be catchy or user-friendly
for what you have intended.
Upon creating a form, the first thing you will probably want to do is resize or
move the controls around.
Controls
It is merely a generic term used to describe any object on a form or
report that displays data, performs actions or items used for decorations
such as a line. In other words, a control is just about anything that is
placed on a form or report.
Unbound or bound text boxes that you can use to add or edit or even
calculate an expression.
179 | P a g e
As you can see a list of employees, but doesn't really look like a very
user friendly list. Our controls are oversized. They are too big, spaced
apart and do not provide a very useful list view.
To edit the appearance of your controls on this form, you have two form
views that you can use. In the Home tab, click the View drop-down.
180 | P a g e
You have the Layout View or the Design View, and both of these views
are used to edit your form. The Form View opens up by default; this is
the view you will use to interact with or edit the underlying data source.
181 | P a g e
When you switch to the Layout View, you will see a series of contextual
tabs appear.
At the top of Access, you will see an area marked Form Layout
Tools with three tabs — Design tab, an Arrange tab, and a Format tab
and each of these tabs have different options for formatting the look or
appearance of the form.
When you take your mouse and click on any one of these controls, you
will notice that Access will highlight a given area of that form and all
controls within that area are shaded a light orange whereas the actual
control that you select will be shaded darker than the previous one or
have a darker orange border around where you click.
182 | P a g e
Here you can resize your controls as you want by clicking and dragging
your mouse to resize the height or width or both of that one control.
183 | P a g e
On this particular form, when you resize any single control, you also
change the size of the rest of your controls on your form, this is because
of how these controls are grouped. Let us now adjust all the fields the
way you want by using the click and drag function of the mouse.
That is one quick way of editing the height and width of controls in your
form from this Layout View.
Themes
In Access, there are some basic ways to format your forms by using
built-in themes, colors, and font styles, customizing fill colors and
shading alternate rows. Let us now open frmEmployees.
184 | P a g e
The forms that Access creates are plain and simple. They have a blue bar
on the top and a white background.
If you want to see how else you can stylize these forms, you can go to
the Design View or Layout View and explore some of the options you
have on the Design tab in the Themes area.
185 | P a g e
If you click on the Themes' drop-down gallery, you have many pre-
created themes to try out from. Hovering your mouse over any one of
them will give you a preview of changing things like colors and font sizes
and the actual font used. To apply a particular style, simply click your
mouse on it and you can see what that looks like.
186 | P a g e
If you like the theme but you want to change the colors, you can adjust
the colors by going back to the Themes group on the Design tab and
choosing the color you like. You can also create custom colors to match
your company's colors.
187 | P a g e
Similarly, you also have a series of font styles to choose from. You can
choose one from the many that come prebuilt with the Office Suite or
you can customize those fonts, choosing a specific heading font, a body
font and even creating a custom name for that font group and saving.
Let us go back to frmEmployees. In this form, you will see that every
alternate row is shaded light gray.
188 | P a g e
189 | P a g e
Select that detail section and then go to the Format tab and in
background group you should see an option for Alternate Row Color.
You can change the colors for alternate rows. To see what that looks like,
simply go to the Form View or the Layout View.
190 | P a g e
If you don't want any shading at all, you can choose No Color as
your Alternate Row Color and that is more the traditional look from
earlier versions of Access.
191 | P a g e
28.Navigation Form
Access includes a Navigation Control that makes it easy to switch
between various forms and reports in your database. A navigation form
is simply a form that contains a Navigation Control. Navigation forms are
a great addition to any desktop database.
Microsoft Access offers several features for controlling how users navigate
the database.
We have already used navigation pane to navigate through all of the Access
objects we create, such as forms, queries, tables, etc.
If you want to create your own navigational structure and make it easier for
the users to find the specific objects that they really need, you can build
navigation form, which is a form that uses a navigation control so users can
use or view forms and reports right from within that main navigation form.
Example
Let us now take a simple example in which we will create the navigation
form. For this, go to the Create tab; in the Forms group, you will see this
navigation drop-down menu.
192 | P a g e
In this menu, you will see different layouts for how to arrange your forms
and reports that you would like to embed on this navigation form.
There is one with horizontal tabs, one with vertical tabs — where all the tabs
are aligned to the left, a vertical tabs layout where all the tabs are aligned to
the right.
There is a horizontal tabs layout that has two levels to it, so if you have a lot
of objects that you want to display across the top, you can make use of this.
You can have one where you have both horizontal tabs and vertical tabs,
either aligned to the left or to the right.
193 | P a g e
Let us now drag frmProjects form from the navigation pane and drop it
on the [Add New] on the top.
Similarly, drag frmAuthers form from the navigation pane and drop it to
the left of the Add New Button.
194 | P a g e
Let us now add additional tabs across the top. We will first add
the frmEmployees form.
195 | P a g e
Now, you will see that your other project buttons have disappeared from
the left and that is because they are attached to Project tab. All the
buttons you view on the left are linked to whatever you have selected up
the top. Now with the Employee tab selected, let us drag employees-
related information to the left.
196 | P a g e
197 | P a g e
29.Combo BOx
When you enter data in any form, it can be quicker and easier to select a
value from a list than to remember a value to type. A list of choices also
helps ensure that the value entered in a field is appropriate. A list control
can connect to existing data, or it can display fixed values that you enter
when you create the control. In this chapter, we will cover how to create
a combo box in Access.
Combo Box
A combo box is an object or control which contains a drop-down list of
values that the user can select from.
The combo box control provides a more compact way to present a list of
choices.
A combo box also gives you the ability to enter a value that is not in the list.
In this way, the combo box control combines the features of a text box and a
list box.
Example
Let us now take a simple example of creating a combo box. We have
created a form for an employee as shown in the following screenshot.
198 | P a g e
We now want to create a combo box for Phone type because we know
that phone type should be either Home, Cell or Work. This information
should be available in the dropdown list and the user need not type this
information.
Let us now go to the Design View for this form. Select the Phone
Type field and press delete.
199 | P a g e
200 | P a g e
Let us now select Use Control Wizards option from the Controls menu
and then Select the Combo Box Control from the menu as shown in the
following screenshot.
201 | P a g e
Now, draw the combo box where you want and when you release your
mouse then you will see the Combo Box Wizard dialog box.
202 | P a g e
Here you have different option for data; let us select the 2 nd option
wherein, we will add the values and click Next.
Enter the values you want to be displayed in the drop-down list and
click Next.
Enter the label for your combo box and click Finish.
204 | P a g e
You can see that combo box is created but it is not aligned to other field.
Let us do that first by selecting all fields and then go to the Arrange tab.
To the left, you will see the Stacked option. Click this button.
205 | P a g e
To make the size of each field same we have different options, let us
click the Size/Space button.
206 | P a g e
207 | P a g e
208 | P a g e
A user can now easily select any option for the Phone type.
209 | P a g e
30.SQL View
In this chapter, we will be covering the SQL view. Whenever you create a
query in query design, Access automatically creates the SQL query for
you. This actually retrieves data from the tables. To see how your query
is created in sql when you create it in query design, let us open your
database.
Select the Query Design from the Create tab and add
the tblEmployees table.
210 | P a g e
Select the field you want to see as query result and then run your query.
211 | P a g e
You can now see all the employee information as query result. You have
selected certain fields in the Query Grid; at the same time, MS Access
has also created an SQL Query with the results obtained from your Query
Grid.
To view the SQL, go to the Home tab. Select SQL View from the View
menu and you will see the SQL of your query.
212 | P a g e
Example
The following is another example wherein, we will see the projects in
progress.
213 | P a g e
214 | P a g e
215 | P a g e
To see the SQL, select the SQL View from the View menu.
216 | P a g e
You can see the SQL query which is generated by Access automatically.
This helps retrieve data from two tables.
217 | P a g e
31.Formatting
One especially useful formatting tool in Access is the ability to
apply Conditional Formatting to highlight specific data. Let us take a
simple example of conditional formatting.
Example
In this example, we will be using a form fSubCurrentProjects in our
database.
We have a list of all of the projects in this database and we have also got
a couple of new fields like the On Time Status and the Number of Late
Tasks. This form is created from another query.
218 | P a g e
In this query, we have a join between a table and a query that will
display the count of due dates or how many projects have tasks that are
overdue. We also have a calculated field here that uses the IF function to
determine whether or not the count of the due date is greater than zero.
It will then display the words Late if the project is late or On Time if
that specific project does not have any overdue tasks.
219 | P a g e
Example 1
In this example, we will be using the above form to understand how you
can use Conditional Formatting to highlight specific pieces of information.
We will now highlight every single project that is currently running late.
To apply Conditional Formatting to one field or more than one field, we
will need to switch over to the Layout view.
220 | P a g e
221 | P a g e
On that Format tab, you should see a group called Control Formatting
and a special button for Conditional Formatting. Let us now click on
Conditional Formatting.
222 | P a g e
You will now see a Conditional Formatting Rules Manager and currently
we have no rules applied to this control. Let us now create a new rule by
clicking on the New Rule button.
You will now see a New Formatting Rule dialog box. We will first specify
the type of rule we will be creating and here we have two options. The
first option is to check the values in the current record or to use an
expression, and the second option is to compare this record with the
other records.
We now have only one of two values in our form; either On Time or the
word Late and that is from the given query. Let us now select the “Field
Value Is” from the first combo box and then select “equal to” from the
second combo box. Now, type the word “Late” in quotation marks.
223 | P a g e
We can now set our Conditional Formatting, how we want this field to
look like if the word Late appears in that field. Let us now change the
font color to red and make it bold, italic and underline, and that's our
conditional rule. Let us now click Ok and then click Apply, and Ok again.
224 | P a g e
You can see that the word Late is formatted now. This is one example of
how to create a very basic conditional format rule.
Example 2
Let us take another example. Here, we will make the title or the name of
the project red and bold, italic and underline. Select the project name
control on your form.
225 | P a g e
Here, we will not be checking the value of the current field we have
selected, but we will be checking it against another field on this form.
Select Expression Is in the first combo box and then click on … button
at the end as in the above screenshot.
226 | P a g e
In the Expression Categories, you have every single object that is on this
form. Doubleclick on CountofDueDate. This will send the reference to
that control or that field up to our expression builder and condition if it is
greater than zero. Now, click Ok.
227 | P a g e
Example 3
Let us now look at another example of conditional formatting. Let us
assume, we want to see which projects are more late or have more late
tasks than other late projects. Select the Conditional Formatting option.
228 | P a g e
Click on the New Rule button to create a new rule and then click Ok as in
the above screenshot.
In the New Formatting Rule, we will now select a rule type “Compare to
other records”. Let us further change the Bar color to red. We want
our shortest bar to represent the lowest value and the longest bar to
represent the highest value. Let us now click Ok and then, click Apply
and Ok again.
229 | P a g e
You can now see Conditional Shading applied as in the above screenshot.
Let us now go to the Form view.
230 | P a g e
231 | P a g e
The most frequently used control is the text box, but other controls include
command buttons, labels, check boxes, and subform/subreport controls.
There are different kinds and types of controls you can create, but all of
which will fall into one of the two categories — bound or unbound.
Bound Controls
Let us now understand what Bound Controls are −
Bound controls are ones that are tied to a specific data source within your
database such as a field and a table or a query.
Values can be either text, dates, number, check boxes, pictures or even
graphs.
You use bound controls to display values that come from fields in your
database.
Unbound Controls
Let us now understand what Unbound Controls are −
Unbound controls on the other hand are not tied to a data source, and they
exist only in the form itself.
Control Types
You can create different types of controls in Access. Here, we will discuss
a few common ones such as Text box, Label, Button Tab Controls etc.
Text Box
Typically, anything that is in a text box will be bound, but not always.
232 | P a g e
You can use these controls to interact with the data stored in your database,
but you can also have unbound text boxes.
Labels
Labels are used to label other controls on your form such as text boxes.
Button
Buttons are usually used to interact with the data or objects within your
database.
Tab Controls
Tab controls give you a tabbed view of controls or other controls in your form.
Adding tabs to a form can make it more organized and easy to use, especially
if the form contains many controls.
By placing related controls on separate pages of the tab control, you can
reduce clutter and ease your work with data.
Hyperlink
Hyperlink creates a hyperlink on your form to something else. It can either
be a web page or even another object or place within your database.
You can also create a web browser control and navigation control, groups,
page breaks, combo boxes.
233 | P a g e
You can create charts, lines, toggle buttons, list boxes, rectangles, check
boxes, unbound object frames, attachments, option buttons, subforms and
subreports, bound object frames and even place images on your form.
Example
Let us now look at a simple example of some of these controls by
creating a new blank form. Go to the Create tab in the forms group and
click on Blank Form.
The above step will open an unbound form, which is not attached yet to
any item in our database.
234 | P a g e
235 | P a g e
236 | P a g e
On the Property Sheet, click on the drop-down arrow and make sure
Form is selected, and then go to the Data tab.
On the Data tab, you will see that the Record Source remains blank. Let
us assume, we want to create a form that's going to be tied to two
different tables in our database. Now click on … button. It will further
open its own query builder.
237 | P a g e
Select the tables that contain the data you want to display; click on the
Add button and then close this dialog box.
238 | P a g e
Let us now select all the fields from tblEmployees and drag to query grid,
and similarly add all the fields from tblHRData.
Let us call it qryEmployeesData and click Ok and then close the query
builder.
239 | P a g e
You can now see the query as its Record Source. We have now bound
this form to an object in our database, in this case qryEmployeesData.
We can now start by adding some controls to this form and to add any
one of the controls, go to the Design tab and view your options from the
controls group.
240 | P a g e
From the Controls menu, you will see that the Use Control Wizard is
highlighted as in the above screenshot. This little button has that
highlighted box around it by default. This means that the control wizards
are turned on. This is like a toggle switch. When you click on the toggle
switch the wizards turn off. Clicking it again will turn the wizards on.
Let us now click on the Label and drag this label and enter Employee
Information and then go to the Format tab to format it as in the following
screenshot.
241 | P a g e
You can choose to apply a bold style or change the font size of text inside
that label etc. This control appears inside the detail section of your form.
It makes more sense to position this label inside the form header section,
which is not visible yet.
242 | P a g e
Right click anywhere in the background of that form and choose Form
Header as in the above screenshot.
243 | P a g e
Move this control into the Form Header area. Let us now create some
other controls from the Design tab. At this point, Let us say, we want to
distribute all our fields into two different tabs.
244 | P a g e
From the control menu, you can see the Tab Control which will create
tabs on your form. Click on the tab control and draw it on your form in
the detail section as in the above screenshot.
245 | P a g e
It will create two tabs — page 2 and page 3 as in the above screenshot.
246 | P a g e
To bring the existing fields to the page, select all the fields available in
the Field List as in the following screenshot.
247 | P a g e
Now, drag the fields to Page2 of the tab control as in the following
screenshot.
248 | P a g e
249 | P a g e
On the second page, let us now add the remaining fields from this query.
250 | P a g e
You can go through and make any adjustments to the size and width of
these controls to get it looking the way you like.
Once you are done with formatting click on the Save As icon to save the
form with the name you want.
Click Ok and go to the Form view to view all the information in that form.
251 | P a g e
The tab control is breaking up our controls or our fields into two screens
to make viewing and adding information easier.
252 | P a g e
253 | P a g e
33.Reports Basics
In this chapter, we will be covering the basics of reports and how to
create reports. Reports offer a way to view, format, and summarize the
information in your Microsoft Access database. For example, you can
create a simple report of phone numbers for all your contacts.
The tables or queries that provide the underlying data are also known as the
report's record source.
If the fields that you want to include all exist in a single table, use that table
as the record source.
If the fields are contained in more than one table, you need to use one or
more queries as the record source.
Example
We will now take a simple example to understand the process of creating
a very simple report. For this, we need to go to the Create tab.
254 | P a g e
Before clicking on the Report button to create a basic report, make sure
the proper query is selected. In this case, qryCurrentProjects is
selected in your navigation pane. Now click on the Report button, which
will generate a report based on that query.
255 | P a g e
You will see that the report is open in Layout view. This provides a quick
way to adjust the size or width of any of your fields that you see on the
report. Let us now adjust the column widths to make everything fit in a
better way.
256 | P a g e
257 | P a g e
This was a very quick way to create a very simple report. You could also
make minor changes and adjustments from the report design view.
258 | P a g e
You have the detail section, which is where all of your data lives for the most
part.
You also will see a page header and a page footer section; these appear at
the top and at the bottom of every single page in your report.
Let us now change the Title of the report and give it another name.
259 | P a g e
Enter a name for your report and click Ok. If you want to view what this
report will actually look like, in Print Preview, you can go back to the
View button and click on Print Preview to see what this report would look
like when printed either on paper or as a PDF.
260 | P a g e
Using the tools on the lower right-hand corner, you can zoom in or zoom
out. You also have some buttons on the Print Preview tab that appear
automatically when you switch to Print Preview. In the zoom section,
you've got a view for one page, two pages; or if you have a longer
report, you can view four pages at once, eight pages or twelve pages.
You can also adjust simple things such as the size of the paper that you
are using to print, the margins for your report, the orientation, the
number of columns, page set up, etc. And that is how you can create a
very quick simple report using the Report button on the Create tab.
261 | P a g e
Let us now go to the Create tab and click on the Report Design button.
262 | P a g e
On the Design tab in the Tools group, select the Property Sheet. This will
open up the Property pane.
263 | P a g e
Select qryLateProjects from the drop-down and now, the next step is
to go through and add some fields to this report by clicking on Add
Existing Fields list button on the Design tab.
264 | P a g e
265 | P a g e
Drag the fields to you report as in the above screenshot. Go the Arrange
tab, and in the Table group, you have a couple of options to choose from.
266 | P a g e
You can see that it moves all of the labels up to the page header area.
These labels will appear only once at the top of every page and the data
query will repeat for every record in the Details section. Now, you can go
through and make some adjustments to make your ProjectName field
wider.
267 | P a g e
As you can see in the above screenshot, there is a lot of space between
Detail section and Page Footer.
Let us drag the Page Footer up to reduce the space as in the following
screenshot. We will now go to the Design tab and click on the View
button and choose Report View.
268 | P a g e
269 | P a g e
You can now see that some project names are not complete; you can
adjust this with either the design view, or you can use the layout view to
do that.
270 | P a g e
That is how we create a simple report just from the Design View.
271 | P a g e
34.Formatting Reports
In this chapter, we will learn how to format reports. You will find that
there are a lot of similarities between formatting reports and formatting
forms but there are a few tools and tricks that are specific to reports. Let
us now look into the concept of report sections and grouping.
For this, we need to open a report that we created in the last chapter.
Here, we will see how some of this information is displayed on the report.
272 | P a g e
You can see that there's not a lot to look and here only page header,
details section, and page footer are visible. You can add an additional
couple of sections very easily.
273 | P a g e
Right click anywhere on that report and you will see Page Header/Footer
and Report Header/Footer. This particular report does not have that
Report Header/Footer visible. Let us select that option and go back to the
Report View.
You can see it just adds a little colored area at the very top of the report.
In the Design View, expand that area by hovering the mouse right at the
top of that page header divider, clicking and dragging down. This will add
more area to the report header.
274 | P a g e
In the Report View, you will now see more area at the very top of the
report as in the following screenshot.
275 | P a g e
The Report Header and Footer controls appear at the top of the first page
of that report. The report footer controls what you see at the very last
page at the bottom of the report.
The Report Header and Footer is different from your Page Header and
Page Footer. Anything that is placed in the Page Header will appear at
the top of every page. Likewise, anything that is placed in the Page
Footer will repeat at the bottom of every page.
276 | P a g e
Now you can add additional grouping levels, and to do that, you want to
make sure you have the group sort and total area turned on.
In the Grouping and Totals section of the Design tab, click on the Group
and Sort button which will open Group, Sort, and Total area at the
bottom as shown in the following screenshot.
277 | P a g e
You can now add additional groups or grouping on any control that you
have in your report. Let us now click on Add a Group.
278 | P a g e
In the above screenshot, you can see the underlying control source for
report with the project name, task title, due date and percent complete.
Let us now say we want to group all of our late tasks by project, so
select Project Name from the list.
279 | P a g e
You can now go to the Report View and see the adjustments made to
group the things in the report as in the following screenshot.
280 | P a g e
Every single project has its own little level on its own line, and then
underneath that area you will see all of the tasks that are late for the
above project. With that changed now, you can go through and start
formatting your report in the Layout View.
If you want to make the project name bigger, then drag the line below
and change the font size to 20 in the Format Tab.
You can increase the width of the control to cover the entire width of the
page.
281 | P a g e
To remove the border around the control, click on the Shape Outline in
the Format tab as in the following screenshot.
282 | P a g e
283 | P a g e
Adjust the task title to the left of your page as in the following
screenshot.
284 | P a g e
Let us now bring the data from the Page Header section to
the ProjectName header section using Ctrl+X and Ctrl+V.
Let us now go back to the Report View. You will now see that the labels
appear directly above the controls that they describe.
285 | P a g e
If you notice, you will see that there is no space between the tasks and
the next project name. There should be additional space in between. For
that, we need to add ProjectName Footer.
286 | P a g e
In the Group, Sort and Total area click on the More button next to the
project name.
You will now find all the options for how to group and sort by project
name as in the following screenshot.
287 | P a g e
288 | P a g e
289 | P a g e
As you can see in the above screenshot that the ProjectName Footer
section beneath the Details section is added. This will act as the footer
for that project name group.
290 | P a g e
Let us change the Details section first by clicking on the detail divider
and then open Properties sheet.
291 | P a g e
292 | P a g e
You can now see how the report looks. To see how your data will print
page by page, let us go to the Print Preview.
293 | P a g e
35.Built-In Functions
In this chapter, we will be working with Built-in Functions. In Access,
there are close to a hundred built-in functions and it is almost impossible
to cover every single one of them. In this chapter, we will cover the basic
structure, syntax, and use some of the more popular functions, and also
the pitfalls, so that you can go exploring some of the other functions on
your own.
Functions
A function is a VBA procedure that performs a task, or calculation, and
returns a result. Functions can generally be used in queries, but there
are other places that you can use functions.
You can use functions in table properties, for example, if you want to specify
a default value for a date/time field, you can use the date or
the Now function to call up the current date/time information from your
system, and input that value automatically.
You can also use functions in an expression when you create a calculated
field, or use the functions inside form or report controls. You can use
functions even in macro arguments.
On the other hand, they can also get quite complicated, with multiple
arguments, field references, and even other functions nested inside another
function.
The Date() function is designed to return the current system date. This
function does not require any function arguments or additional information.
All you have to do is write the name of the function and those open and
close parentheses.
294 | P a g e
There are two very similar built-in functions Time() and Now().
The Time() Function returns the current system time only and the Now()
Function returns both the current system date and time.
Depending on the data that you want to track, or store, or query, you have
three built-in, easy-to-use functions to help with that task.
Let us now open your database and create a new query using query
design and add tblProjects and tblTasks.
295 | P a g e
You can now see all the different tasks from all projects. If you want to
view the project tasks that are in progress as on today’s date, then we
have to specify a criterion using a Date() Function to look at projects
that start on or after today's date.
296 | P a g e
When we run this query, all the tasks will occur either on today's date or
in the future as in the following screenshot.
297 | P a g e
This was an example of how you can use the Date() function as query
criteria.
Let us now say this query needs to be more flexible in terms of the dates it is
pulling starting this week.
We do have a couple of different tasks that began this week, that are not
showing up in this current list, because of our criteria. It's looking at start
dates that are equal to today or above.
If we want to view the tasks that started this week, that have not yet
completed or should complete today, let us go back to the Design View.
298 | P a g e
If we type minus seven and run the query, you can see the tasks that
started this week as well.
299 | P a g e
DateDiff() Function
The DateDiff() Function is another very popular date/time function. The
DateDiff Function returns a Variant (long), specifying the number of time
intervals between two specified dates. In other words, it calculates the
difference between two dates, and you get to pick the interval by which
the function calculates that difference.
Let us now say we want to calculate our authors' age. For this, we first
we need to create a new query and add our authors table and then add
FirstName, LastName, and the BirthDay fields.
300 | P a g e
301 | P a g e
Let us call it Age followed by a colon, and then write DateDiff Function.
The first function argument for the DateDiff function is the interval, so type
“yyyy”.
The next function argument is the first date that we want to calculate by,
which, in this case, will be the Birthday field.
Now, run your query and you will see the new field which shows the age
of each author.
302 | P a g e
Format() Function
The Format() Function returns a string, containing an expression
formatted according to instructions contained in a format expression.
Here is the list of user-defined formats which can be used in Format()
function.ss
Setting Description
yyyy Year
q Quarter
303 | P a g e
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second
Let us now go back to your query and add more fields in the same using
the Format() function.
304 | P a g e
305 | P a g e
It is now taking the date from the birthday field, 4 is the month and 17 is
the day.
Let us add “mmm” and “mmmm” instead of “mmdd” in the next fields as
in the following screenshot.
306 | P a g e
Run your query and you will see the results as in the following
screenshot.
307 | P a g e
In the next field, it is returning the first 3 character from the name of the
month for that birthday and in the last field you will get the full month
name.
To see the month followed by year from birthday, let us add the “yyyy”
as well as shown in the following screenshot.
308 | P a g e
You will now see the month followed by a comma and then the year.
IIf() Function
The IIf() Function is an abbreviation for “Immediate If” and this function
evaluates an expression as either true or false and returns a value for
each. It has up to three function arguments, all of which are required.
The next argument stands for the true part, which can be a value or an
expression returned if your first expression is true.
The last argument is what you want returned if your expression is false.
Example
Let us take a simple example. We will create a new query using query
design and add tblAuthors table and then add the following fields.
309 | P a g e
310 | P a g e
Now, you can see the result of the query, but you will also notice that
some records do not have a middle initial. For example, the Joyce Dyer
record does not have a middle initial, but in the FullName field you will
see the period that really doesn't need to be there. So, go back to the
Design View. Here, we will concatenate the name in a different way using
the IIf Function.
311 | P a g e
Let us write the name in another field and call it FullName1 and then
type the IIf function.
The first function argument for the Immediate If function is going to be your
expression. In the expression, we will see if the middle initial field is blank or
is null.
The next argument is the true part. So, if the middle initial is null then we
would want to display the FirstName and the LastName.
Now, for our false part — if the MiddleInitial is not null, then we would want
to display the FirstName, MiddleInitial, and LastName.
Let us now run your query and you will see the results as in the following
screenshot.
312 | P a g e
313 | P a g e
36.Macros
In this chapter, we will cover the basics of Macros in Access. A Macro is a
tool that allows you to automate tasks and add functionality to your
forms, reports, and controls.
Macros in Access work a bit different from Macros in Word or Excel, where
you essentially record a series of keystrokes and play them back later.
Access Macros are built from a set of predefined actions, allowing you to
automate common tasks, and add functionality to controls or objects.
Macros provide a way to run commands without the need to write or even
know VBA code, and there is a lot that you could achieve just with Macros.
Creating a Macro
Let us start be creating a very simple Macro that opens a form when a
command button is clicked. For this, we need to open your database and
frmEmployeeData form in which we have created two tabs.
314 | P a g e
In this form, we can add a button allowing users to open up all of the job
information.
Let us now go to the Design View of this form and add button form the
Controls menu. When you release your mouse, you will see the
Command Button Wizard dialog box.
315 | P a g e
There is a couple of ways to build that Macro action, but the simplest
way is to simply use the Command Button Wizard.
For common actions like opening a form, select Form Operations from
the Categories list and then select Open Form from the Actions list and
click Next as in the above screenshot.
316 | P a g e
You need to specify which form you would like to open with the
command button. For now, let us select frmJobs and click Next.
In this screen we have two options, we can open the form and display
a very specific record, or we can open the form and show all the
records. Let us select the second option and click Next as in the above
screenshot.
317 | P a g e
We could have the command button itself display a picture or you can
select the Display Text. Here, we want the text View Jobs to display and
now click Next.
318 | P a g e
You will now see a View Jobs button on your form. Let us click on it.
319 | P a g e
Now you have a form open, but you will not be viewing any information.
Let us go back to the frmEmployeeData form Design view. Make sure
that the command button is selected and click on the Event tab on the
Property Sheet.
Upon clicking, you will see an embedded Macro created by the Wizard. If
you now want to modify this Macro, click on the … button to open up the
Macro generated by the Wizard.
320 | P a g e
This is the Macro Designer and on the right you will see the Action
Catalog. This is where all of your actions will live in folders. You have the
Data Entry options, Data Import/Export and so on, and on the left in the
main area you have another Macro. It only contains one action, and
clicking on that one action you can view other properties for that specific
action.
321 | P a g e
You will see the form name and you can hit that drop-down arrow to
view the forms available in your database. You can change how that form
is viewed, you can have it open to Form view, Design view, Print Preview
at your choice. You can apply a filter name or a Where condition. Here
we want to change the Data Mode because frmJobs is set to the Add
Mode which only allows the addition of new records. We can override this
here in this Macro by changing it to the Edit Mode.
322 | P a g e
Now save your Macro, and then close the Macro Designer and go back to
the Form View.
323 | P a g e
You can now see that it opens your frmJobs form and allows you to scroll
through all of the available jobs in our database.
324 | P a g e
37.Data Import
In this chapter, we will be talking about importing data in Access and
what kinds of data you can import using Access. Normally data is stored
in various formats, files, and locations, which makes it hard to get and
use it. If you have data in a spreadsheet, a SharePoint list, or some
other format, you can import it into an Access database with just a few
steps, making it much more, easily available in Access.
In Access you can’t use the Save As command in the same way, you can
save Access objects as other Access objects, but you cannot save an Access
database as a spreadsheet file.
To save Access as a spreadsheet file, you will need to use the import feature
on the External Data tab.
325 | P a g e
In the import & Link group, you can see the different kind of options
available for data import in Access. Following are the most commonly
used data import formats.
XML Files
Example
Let us look at a simple example of data importing from an Excel file.
Here is the data in Access file.
To import the data in Access, we first need to open the Access database
and then go to the External Data tab as in the following screenshot.
326 | P a g e
In Import & Link group, you will see an option Excel. Let us click on that
option.
327 | P a g e
Browse the Excel file from which you want to import data and the then
we have different options to store data. Let us select the first option and
click Ok.
Here you will see the preview of your data. Now, click Next.
328 | P a g e
In the Preview, you can now see that the first row contains the column
headings. Let us now check the check box and click Next.
329 | P a g e
You will now see a dialog box where you can set the data type for each
column/field. If you don’t want to import any field, just check the check
box which says do not import field. Once you are done with the
FirstName field, just click on the MiddleInitial field.
Let us now go through all the fields and then, click Next.
330 | P a g e
Here are the different options for primary key. Let us select the first
option and click Next.
In the last dialog box, you can enter the table name of your choice and
click Finish.
331 | P a g e
If you want to save all these steps, then check the checkbox and close
the dialog box.
Let us now go to the Navigation pane. You will see a new table is added
here and when you open the newly added table you will see all of your
data in Access.
332 | P a g e
Example
Let us now look at another example of importing data from the Access
database. Let us go to the External Tab again.
333 | P a g e
Browse the Access database from which you want to import the data and
then select the first option which says Import tables, queries, form etc.
Now, click Ok.
334 | P a g e
In the above dialog box, you can see different tabs for Tables, Queries,
Forms etc. from where you can select what kind of data you want to
import.
335 | P a g e
Let us go to the Reports tab and select any report you want to import;
you can also select all the data by clicking on the Select All button. Let
us select Projects and click Ok.
336 | P a g e
Now, close the dialog box. In the navigation pane, you will see that a
new report is added. Let us open this report and you will see all the data
in that report.
337 | P a g e
338 | P a g e
38.Data Export
In this chapter, we will understand how to export data from Access. Data
export is actually the opposite of importing data. In importing data, we
bring data from other formats in Access, while in exporting we save the
data in other formats.
To understand what kind of data you can export from Access data, let us
open your database and go to the External Data tab.
In the Export group, you can see the different kind of options available
for data export from Access. Following are the most commonly used data
export formats −
XML Files
339 | P a g e
Example
Let us look at a simple example of data export from Access. Open your
database where you want to export the data from. In the Navigation
Pane, select the object that you want to export the data from.
You can export the data from table, query, form, and report objects etc.
Let us select the qryAllProjects and then, go to the External Data tab.
On the External Data tab, click on the type of data that you want to
export to. For example, to export data in a format that can be opened by
Microsoft Excel, click Excel.
340 | P a g e
Access starts the Export wizard. In the wizard, you can set the
information such as the destination file name and format, whether to
include formatting and the layout, which records to export. Once you are
done with the required information, click Ok.
341 | P a g e
On this screen of the Wizard, Access usually asks you if you want to save
the details of the export operation. If you think you will need to perform
the same operation on a recurring basis, select the Save export
steps check box and close the dialog box.
342 | P a g e
Let us now suppose you want to export data to a text file, on the
External Data tab, click on the Text File.
343 | P a g e
Specify the export options and click Ok. You will see the Encode dialog
box, wherein we want to export the data in default encoding.
344 | P a g e
On this screen of the wizard, Access usually asks you if you want to save
the details of the export operation. If you think you will need to perform
the same operation on a recurring basis, select the Save export
steps check box and close the dialog box.
345 | P a g e
346 | P a g e