Вы находитесь на странице: 1из 43

INTRODUCTION TO DATABASE

LAB 01
Introduction To database

Objectives:

After completing this experiment you will be able to:

 Learn what is database?

 Learn about MS ACCESS.

Tools/ Apparatus:

MS ACCESS 2016

Requirements:
Something required, something wanted or needed

 Need- something you have to have

 Want -something you would like to have

MS ACCESS:

Microsoft Access is a Relational Database Management System (RDBMS), designed primarily


for home or small business use.

Microsoft Access (or MS Access) is bundled as part of the Microsoft Office suite. It is only
available on the PC version.

Access has traditionally been known as a desktop database system because its functions are
intended to be run from a single computer.

Access File Extensions

When you save a database in Microsoft Access, it is saved with a .accdb extension.
Older Access databases Extensions

.mdb extension or sometimes a .mde extension.

In 2007, Microsoft started to phase these out in favor of the .accdb extension. If you're unable to
open an older database, you may need to convert to .accdb first using an older version of Access.

Download Microsoft Access

If you don't currently have Microsoft Access installed on your computer, you can download it
from the Microsoft website.

Access Versions

We will use Access 2016.

Create a Blank Database


You can create a database from two different places:

1. From the Access Welcome screen

2. From the File > New menu


3. Name the Database

Creating Table
A table stores information in a row-column format a database similar to the way an Excel worksheet
stores information in a workbook.

Create a Table in Design View


Datasheet View is what we used when we created our table previously.

Datasheet View displays the table as a grid. The fields are displayed as columns, and the records are
displayed as rows. The field names are listed as the column headers.

Datasheet View displays the data. If this table had data, it would be displayed in the cells.

Customize the Blank Table


First, we're going to add a field to the existing table. Then we'll
rename the existing field.

Select a Data Type for the New Field


Right-click Click to Add and select Short Text from the combo box.
Name the Field
Once you've selected a data type, the field header will be
highlighted with the text Field1 so that you can provide a name for the
field.

Enter ArtistName as the name of the field.

Rename the First Field


The first field in our table is currently called ID. We'll rename it.
Right-click on the ID field header, and select Rename Field. The field will be
highlighted for you to rename it.
Enter ArtistId.
Save the Table
Right-click on Table1 to save the table.

Enter Artists at the prompt.

Lab Task 1. Create New table called Album

Add 4 fileds and remname first one as shown below

Create a Table in Design View


Design View can make it easier to set up a table. It provides a different view of the table to
Datasheet View, and is typically used to configure the table.

Design View is used to create a tables, set up data types for each field, specify default values,
specify how data should be entered and displayed, and more.
Most tasks can be achieved using either Design View or Datasheet View, however there are some
advanced settings that can only be changed in Design View. Also, you might find that you prefer
to do certain tasks in Design View and other tasks in Datasheet View.

Design View doesn't display any data. Therefore, there's more space available to display other
settings.

In Design View, the fields are listed vertically. They are listed above and below each other as
opposed to side-by-side.

In Design View, you can see the data type listed next to each field.

We will now use Design View to do two things:

1. Create a new table

2. Set field properties for our existing table

1. Create a new Table in Design View


1. Click Table Design from the Ribbon (ensuring that the Ribbon is on the Create tab).
2. A blank table called Table1 will be displayed in Design View.
3. Enter each field and select their data type.
In the first cell under Field Name add a field called GenreId. Select Autonumber as its
data type.
Under that field, create a new one called Genre and select Short Text for its data type.

4. Change the Genre Field Properties

Ensuring the Genre field is selected (by clicking on it), look at the bottom Field Properties
frame.

Double-click somewhere in the Required row, so that the value now reads Yes.

Now, double-click in the Allow Zero Length field so that it changes to No.

We have just made the Genre field a required field — all records must have a value in this
field, and it can't just contain a blank string.
5. Set a Primary Key
A primary key is the unique identifier for the table. Each value in this field
will be unique — no two records in the table can have the same value in the
primary key field.

Right-click on the GenreId field and select Primary Key from the drop down list.

This makes the field a primary key field. Once you've done this, you'll see a little key icon to
the left of GenreId.

Note that a table can only have one primary key.

6. Save the table as Genre and close it

2. Set the Field Properties for an Existing Table


1. Right-click the Albums table in the left menu and select Design View from the
contextual menu.

2. Set the AlbumName field to be a required field. Also set Allow Zero Length to No.

3. Set the ArtistId field to be a required field.

4. Save the table.


Create an Input Mask
The Input Mask Wizard helps you create an input mask. An input mask restricts how data is entered
into the database.

An input mask is a set of simple rules that specifies the format in which data can be entered into a field.

Example: For example, an input mask of (999) 000-0000 could be used to determine how phone
numbers are entered. In this example, the area code is optional, but the rest of the number is must be
entered. This is because, with any input mask, a 9 specifies an optional number, a 0 specifies a
mandatory number.

1. Open the Albums table in Design View.

2. Click on the ReleaseDate field then look to the bottom frame. The bottom frame
displays the properties for this field.

3. n the bottom frame, click somewhere in the Input Mask row. A small button with
three dots will appear. This button launches the Input Mask Wizard.

4. Click that little [...] button with the three dots.

5. The Input Wizard Mask presents you with some options for how you'd like the
data to be entered.

6. Select Medium Date and click Next >.


7. Customise the input mask

a. This screen allows you to make adjustments to the input mask.

b. Add two zeros, so that the input mask becomes: 99->L<LL-0000. This will
ensure the user enters the date as DD-MMM-YYYY. For example, 20-
Mar-2016.

c. Click Next.

8. Click Finsh

Add Data to a Table


There are many ways of adding data to an Access 2016 table. You can use a form, import from an
external file, use SQL, and you can enter data directly into the table.

Add Records Directly into Datasheet View


Lab Task 2. Open the Genres table in Datasheet View and enter the following
data:

Data types for Access desktop databases


Data Type Usage Size

Short Text Alphanumeric data (names, titles, Up to 255 characters.


(formerly etc.)
known as
“Text”)

Long Text Large amounts of alphanumeric Up to about 1 gigabyte (GB), but


(formerly data: sentences and paragraphs. controls to display a long text are
known as See The Memo data type is now limited to the first 64,000
“Memo” called “Long Text” characters.

Number
1. Numeric data. 1, 2, 4, 8, or 16 bytes.

Date/Time
2. Dates and times. 8 bytes.

Currency
3. Monetary data, stored with 4 8 bytes.
decimal places of precision.

AutoNumber
4. Unique value generated by 4 bytes (16 bytes for
Access for each new record. ReplicationID).
Yes/No
5. Boolean (true/false) data; Access 1 byte.
stores the numeric value zero (0)
for false, and -1 for true.

OLE
6. Object Pictures, graphs, or other ActiveX Up to about 2 GB.
objects from another Windows-
based application.

Hyperlink
7. A link address to a document or Up to 8,192 (each part of a
file on the Internet, on an intranet, Hyperlink data type can contain up
on a local area network (LAN), or to 2048 characters).
on your local computer

Attachment
8. You can attach files such as Up to about 2 GB.
pictures, documents,
spreadsheets, or charts; each
Attachment field can contain an
unlimited number of attachments
per record, up to the storage limit
of the size of a database file.
Note, the Attachment data type
isn't available in MDB file
formats.

Calculated
9. You can create an expression that Dependent on the data type of the
uses data from one or more fields. Result Type property. Short Text
You can designate different result data type result can have up to 243
data types from the expression. characters. Long Text, Number,
Note, the Calculated data type Yes/No, and Date/Time should
isn't available in MDB file match their respective data types.
formats.

Field properties

Field With these data To


Property types
Field
1. Size  Text Text: Enter a value from 1 to 255. Text fields can range
from 1 to 255 characters.
 Number
Number:
 Auto Number
 Byte(0 to 255) Storage=1 Byte
 Integer(-32,768 to +32,767) Storage= 2 Byte
 Long integer(-2,147,483,648 to +2,147,483,647)
Storage=4 bytes
 Single(floating point values) Storage= 4 bytes
 Double(floating point values) Storage=8 bytes
 Decimal(Numeric Value from range from -
9.999... x 1027 to +9.999... x 1027) Storage=12
bytes
 Replication ID(For storing a globally unique
identifier that is required for replication. Format
Storage requirement is 16 bytes.)

Format
2.  Text Customize the way that the field appears by default when
it is displayed or printed.
 Memo
Number: Displays the number as it was entered.
 Number
Currency: Displays the number by using the thousand
 Date/Time separator, and applies the settings in the Regional and
 Currency Language Options in Control Panel for negative
amounts, decimal and currency symbols, and decimal
 AutoNumber places.
 Yes/No For example, 3456.789 is displayed as $3,456.79.
 Hyperlink  EURO: For example, 3456.789 is displayed as
€3,456.79, and 3 456,789 becomes 3 456,79€.
 Fixed: For example, 3456.789 is displayed as
3456.79.
 Standard: Displays the number by using the
thousand separator. This format does not display
a currency symbol.For example, 3456.789 is
displayed as 3,456.79.
 Percent:Multiplies the value by 100 and displays
the number with a percent sign appended to the
end. For example, 0.3456 is displayed as 35%.
Date/Time:
Select one of the following predefined display formats:
 General Date — Displays the value by using a
combination of the Short Date and Long Time
settings.
 Long Date — Displays the value by using the
Long Date setting of the Regional and Language
Options in Control Panel.
 Medium Date — Displays the value by using the
format dd-mmm-yy (14-Jul-06, for example).
 Short Date — Displays the value by using the
Short Date setting of the Regional and Language
Options in Control Panel.
 Long Time — Displays the value by using the
Time setting of the Regional and Language
Options in Control Panel.
 Medium Time — Displays the value by using
the format HH:MM PM, where HH represents the
hour, MM represents the minute, and PM
represents either AM or PM. The hour value can
range from 1 to 12. The minute value can range
from 0 to 59.
 Short Time — Displays the value using the
format HH:MM where HH is the hour and MM is
the minute. The hour can range from 0 to 23.

Yes/No:
 True/False — Displays the value as either True
or False.
 Yes/No — Displays the value as either Yes or
No.
 On/Off — Displays the value as either On or Off.
Decimal
3.  Number Specify the number of decimal places to use when
Places displaying numbers.
 Currency
New
4.  AutoNumber Set whether an AutoNumber field is incremented or
Values assigned a random value when a new record is added.
Input
5.  Text Display editing characters to guide data entry.
Mask
 Number
 Date/Time
 Currency
Caption
6.  All data types Set the text displayed by default in labels for forms,
reports, and queries.
Default
7.  Text Automatically assign the specified value to a field when
Value a new record is added.
 Memo
 Number
 Date/Time
 Currency
 Yes/No
 Hyperlink
Validation
8.  Text Supply an expression that must be true to add or change
Rule the value in this field.
 Memo
For example, entering a rule such as >100 And <1000 in
 Number the Validation Rule property forces users to enter values
 Date/Time between 100 and 1,000.
 Currency A rule such as [EndDate]>=[StartDate] forces users to
enter an ending date that occurs on or after a starting
 Yes/No date.
 Hyperlink
Validation
9.  Text Enter text that appears when a value entered in this field
Text violates the expression in the Validation Rule box.
 Memo
Entering text such as "Enter values between 100 and
 Number 1,000" or "Enter an ending date on or after the start date"
 Date/Time in the Validation Text property tells users when they
have made a mistake and how to fix the error.
 Currency
 Yes/No
 Hyperlink
Required
10.  All Data types Require that this field must contain a value in every
except Auto record.
Number
Allow
11.  Text Allow entry (by setting to Yes) of a zero-length string
Zero ("") in a Text or Memo field.
Length  Memo
 Hyperlink
Text
12. Align  All data types Specify the default alignment of text within a control.
except
Attachment
Show
13. Date  DateTime Specify whether Access displays a date picker (calendar
Picker control) when users edit a field value.

Import Data into Access


Access provides an easy way to import data from external files
import data from a variety of different sources, including text, Excel, XML, HTML, ODBC
datasources and more.
You can also link to external data sources, so that changes in the source file are reflected in your
Access database.
Generally, when importing data, you have these options:
 Import the data into an existing table;
 Have Access create a new table based on the data; or
 Establish a link to the external file, so that future updates are reflected automatically.
Import a CSV File into an Existing Table
We will import the following CSV file into the Artists table.

Steps:
1. Launch the Import Wizard: o launch the wizard for a CSV file, click Text File from the
External Data tab on the Ribbon(both the source file, and the destination table are closed).

2. Select the Source File & Destination Table

a. Use the Browse... button to navigate to and select the import file (in our case,
artists.csv).

b. Select Append a copy of the records to the table and then select the Artists table
from the drop down list of tables.

c. Click OK to continue.
3. Review the Format Options(his part of the Import Wizard will ask you to confirm the file's format). If
all looks OK, click Next >.

4. Select/Review the Delimiter. Access will ask you to select the file's delimiter. If it was wrong, you
can click another delimiter and see how the data updates to reflect the new delimiter.

5. You can also select whether or not the file contains header rows. If the first row of your file
contains headers, click First Row Contains Field Names. Otherwise, leave it unchecked.

6. Before continuing, click the Advanced... button, as we need to tell Access to skip the extra
field.
7. Click Finish to run the import.

8. Close the Wizard.

9. Check that the data has been Imported.

Create a Relationship

Access allows you to create relationships between tables so that you can query related data from
multiple tables.

In relational database terms, a relationship is a situation where multiple tables can contain related
data that is linked by a common field.

A relationship consists of a parent table and a child table. The child table references the parent
table by having a field that matches a field in the parent table. The child's field is referred to as a
foreign key. The parent's field is the primary key.

In a relationship, any data entered into the child's foreign key field must match a value from the
parent's primary key field.

Create a Lookup Table


Access 2016 provides a Lookup Wizard that makes it easy to create lookup tables.
A lookup table is a table that contains data that is referenced by another table. The other table will
have a lookup field that can "lookup" the data in the lookup table.
In Access, the lookup field displays the data as a drop down list (or combo box) so that the user
can select the desired value from the list. The values of the lookup field come directly from the
lookup table.
We will now turn our Genres table into a lookup table. The Albums table will then have a
lookup field that gets its values from the Genre table.
Steps:
1. Launch the Lookup Wizard.

 Open the Albums table in Design View.


 In the GenreId field, click in the Data Type cell and select Lookup Wizard from the combo
box.
 The Lookup Wizard will appear.

2. Choose how the Lookup Field will get its Values.

 Leave the default option (I want the lookup field to get the values from another
table or query.) selected and click Next >.

3. Choose the Lookup Table.


 choose which table will provide the values for your lookup field.
 Select Table: Genres and click Next >.
4. Choose the Field/s to display in the Lookup Field.
 choose which field will be displayed in the lookup field of the table referencing
the lookup table.
 Double-click Genre so that it moves to the right pane, then click Next >.

5. Choose the Sort Order for the Lookup Field.


 Choose how the data will be sorted in your lookup field.
 For this example, we will sort by the Genre field in ascending order.
 Select Genre from the first drop down, then click Next >.
6. Select the Column Width of the Lookup Field.
 choose to display or hide the lookup table's primary key column. Leave it hidden.
 Click Next >.
7. Choose a Lable for the Lookup Field.

8. Save the Table.


9. Check your Lookup Field.
Create a Query
One of the main functions of a database is to provide the ability to query the data. The ability to
create complex queries across multiple tables with various data types is one of the features that
distinguishes a database management system from a simple spreadsheet application.

 Access has a Query Wizard that allows you to choose the type of query you want to run,
then walks you through the creation of the query.

 Access also allows you to go straight to Query Design view which gives you more control
over creating the query.

First, Ensure Data is in your Tables

Lab Task 3. First import album.cvs file into your album table
Query Design: Steps:
1. Launch the Query Designer.
 Click Query Design from the Create tab on the Ribbon.
 The Show Table dialog box will appear.
2. Select the Tables for the Query.
 Select both the Artists and Albums tables and click Add.
 Click Close to close the dialog box.
3. Design the Query.
 Create a query that returns all albums from Iron Maiden.
 Run the query by clicking the ! Run button on the Ribbon.
 If you can't read the screenshot, the query options are:
 Albums.AlbumName
 Albums.Genre
 Albums.ReleaseDate
 Artists.ArtistName
 Show: All except Artists.ArtistName.
 Criteria: Apply "Iron Maiden" to the Artists.ArtistName field.
4. View the Query Results.
 The query results are displayed in Datasheet View.
 Notice that the results only display the fields for which we selected Show against.

View the Query in SQL View

 You can view the code that Access generates behind the scenes by switching to SQL View.
 To switch to SQL View, click on SQL in the bottom right corner.
 Alternatively, you can use the View button on the Ribbon to switch to SQL View. To use this
option, click the little "down arrow" below the word View. This will expand all of the "View" options.
Click SQL View from the list.

Save the Query


 You can save a query so that you can run it again later.
 To save the query, right-click on the query tab and select Save.
Create a Query with User Input
You can create a query that relies on user input. The value that the user provides determines the
result set.
In Access, queries can accept parameters that can be used to determine the results of the query.
When the query is run, the user is first prompted to enter a parameter (or multiple parameters). Once
the parameter has been supplied, the query can return the results, based on the parameter provided.

For example, we previously created a query that returns all albums from Iron Maiden. This query
could be modified so that it returns all albums from a given artist. The artist can be specified by the
user.
Steps:
1. Make a Copy of the Existing Query
 In the left navigation pane, right-click on the Iron Maiden Albums query and select
Copy from the contextual menu.
 Now right-click again inside the navigation pane and select Paste.

 Name the query at the prompt and click OK.

2. Modify the Query


 In the left navigation pane, right-click the query and select Design View.
 Replace Iron Maiden with [Which Artist?].
 The square brackets will cause a parameter dialog box to open when the user runs the
query. The text inside the square brackets will be displayed to the user, and an input field
will be displayed for their input.

 Now run the query (either by clicking Run or View in the Ribbon, or clicking the
Datasheet View icon in the bottom right corner of the screen).
 A prompt will display, asking for an artist. Enter an artist.
Expression Builder
Access 2016 includes an Expression Builder that simplifies the process of building expressions.
You can use the Expression Builder to create queries, set a default value on a field, set a
validation rule against a field, and more.
An expression is any legal combination of symbols that results in a value. The Expression Builder
includes the following to help you build an expression:
 Built-in functions. For example, Count(), Date(), and MsgBox().
 Constants. Such as True, False, NULL.
 Operators. For example >=, &, And
 Fields. From tables, queries, forms, and reports.

Using the Expression Builder to help Create a Query


Steps:
1. Launch the Query Designer
 Click Query Design from the Create tab on the Ribbon.
 The Show Table dialog box will appear.
2. Select the Tables for the Query.
 Select both the Artists and Albums tables and click Add.
 Click Close to close the dialog box.
3. Select the Fields to Display.
 Add the following fields:
o Albums.ReleaseDate o Albums.Genre
o Albums.AlbumName o Artists.ArtistName
 Keep Show checked against all fields.
4. Launch the Expression Builder.
 Under the ReleaseDate column, click inside the Criteria cell.
 Now click the Builder button on the Ribbon under Design tab. This will launch the
Expression Builder.
5. Add a Built-in Function.
 First, click Functions on the left pane to expand its options.
 Click Built-in functions and then Date/Time in the middle pane.
 On the right pane, scroll down until you see the Year() function. Double-click
Year() so that it appears in the top pane.

6. Add a Field.
 In the top pane, click «date» inside the function's brackets so that it becomes
highlighted.
 Now, expand Music.accdb, then expand Tables, then click on Albums to reveal all
the fields of that table. Double-click ReleaseDate so that it replaces «date» at the
top pane.

7. Add an Operator.
 click to the right of the function so that you can continue building the expression.
 On the left pane, click Operators, then Comparison in the middle pane to reveal the
comparison operators.
 Double-click the greater than sign (>) so that it's added to the top pane.

8. Return the Current Year.


 Our query will be comparing two "Year" values, so add another Year() function,
and click the «date» to highlight it, like before.
 Now, in the right pane, scroll up to the Date() function. Double-click it so that it
replaces «date».

9. Add another Operator.


 Click to the right side of the expression so that you can add a "less than" operator
(-).
 On the left pane, click Operators, then Arithmetic in the middle pane to reveal the
arithmetic operators.
 Double-click - so that it's added to the top pane.
 Add a Fixed Value. Type 25 at the end of the expression.
10. The expression is now complete. Click OK to add the expression to your query and
close the Expression Builder.

Query now has the full expression listed in the Criteria field.
11. Click View or Run to run the query.

Lab Task 4. Construct query according to the given


snapshot

Lab Task 5. Construct Parametrized Query according to snapshot


Forms:
One thing that separates Access (and other desktop database systems) from most client/server
database management systems (DBMSs), is the ability to create forms. Most client/server
systems require you to use separate tools to build forms. With Access, you can create forms
straight from within your database.

In Access 2016, you have the option of creating a blank form from scratch, using the Form
Wizard, or having Access automatically create a form from a table or query.

Create a Form from a Table

Create the Form:


Select the table in the left menu that you want to use for the form (in our case, the Albums table)
and click Form from the Create tab on the Ribbon.

Access immediately creates a form based on the selected table.


The form displays all fields as label/field pairs.
The label allows users to see which field is which.
The field is presented in an editable form element such as a text box, combo box, etc. The user
can then edit the underlying data using the form elements.
Form Views:
There are three different views for working with forms:

1. Design View
2. Layout View
3. Form View

1. Design View

Design View provides a more detailed view of the form's structure than Layout View.
Design View also allows you to modify the form without having any data getting in the way.
Most tasks can be done in either Design View or Layout View, but there are some form properties
that can only be changed in Design View.
2. Layout View

Layout View provides a more visual layout for editing the form. It bears a close resemblance to
the actual form that the user will see.
Layout View allows you to edit the form properties while it has real data.

3. Form View

Form View is how the user will see the form. You can't edit the form's properties, but you can use
the form just as a user would.

The Design Tab


You can use the Design tab to change the color of the form, change fonts, or change the whole
theme.
You can also upload a logo, add/edit a title, add the date and time, etc.
The Design tab also allows you to add form controls such as buttons, text input, combo box, etc.
The Arrange Tab
Use the Arrange tab on the Ribbon to arrange individual elements. Select the element/s and click an
option to re-arrange them.
For example, you can move a field under the field beneath it by using the Move Down option. You can also
set padding, margins, add arbitrary spaces, etc.

Form Properties
Access provides the Property Sheet for setting properties against a form and its elements. Here's an
overview.

The Property Sheet


 You can use the Property Sheet to apply settings to individual elements, or the whole form.
 There are many different properties that can be applied across a form. These aren't just limited to
formatting properties, they include data validation properties, event based properties, and more.
 The Property Sheet displays properties for the selected element. When you select another
element, the properties in the Property Sheet will update to reflect the properties for that element.
 To open the Property Sheet, click Property Sheet from the Design tab in the Ribbon.

The Date Picker vs The Input Mask


You can use the Property Sheet to set a date picker for date fields.
In fact, Access automatically sets date fields to use a date picker, so in many cases, you won't
need to do anything.
However, if you have set an input mask (like we did previously), the date picker won't be shown
on the form.
In Access, you can't use a date picker on a field that has an input mask applied.
So, if you want to use a date picker, you'll need to remove the input mask. You can do this via the
Property Sheet. The Input Mask is under the Data tab.
Add a Combo Box to a Form
Access provides a "Combo Box Wizard" to walk you through adding a combo box to a form.

Add a Combo Box with the Artists' Names


Add a combo box containing a list of all artists' names to the form. This will allow users to select artists by
their name, rather than their ID. However, the form will still insert the ID into the Albums.ArtistId field.
Steps:
1. Add the Form Control.
 Open the form in Layout View.
 Click the Combo Box icon from the Design tab on the Ribbon.
 Now click the form in the location that you want the combo box to be inserted. The Combo
Box Wizard will open.
2. The Combo Box Wizard: Select a source for the Values.
 Select the first option: I want the combo box to get the values from another table or query
and click Next >

3. Select Table: Artists and click Next >


4. Click >> to move both fields across to the right pane, then click Next >
5. Select Sort Order.
 Select ArtistName and Ascending, then click Next >

6. Select where to store the Value.


 Click Store that value in this field: and select ArtistId
 Then click Next >

7. Type a label for the combo box and click Finish.


8. Test the Form/Combo Box
 Go to a New Record
 Switch to Form View
 Enter data as a user would
 Tabbing or pressing Enter past the last field will submit the form and insert the
contents into the table.

Create a Report
In Access 2016, you can create a report from a table or query with the click of a button. You can
also use the Report Wizard to walk you through the process. And more experienced users can
start with a blank report and build it exactly as they wish.
A report is a printed document that displays information from a database. Reports are created
through the Report Wizard, then modified as necessary in the Design view.
The columnar (vertical) report is the simplest type of report. It lists every field for every record in
a single column (one record per page). The records in this report are displayed in the same
sequence as the records in the table on which the report is based.
The Tabular report displays fields in a row rather than in a column. Each record in the underlying
table is printed on its own row. Only selected fields are displayed, so the tabular report is more
concise than the columnar report.

A report is divided into sections. These are:


 Report header & footer o
 Page header & footer
 Group header & footer
 Detail section
Create a Report based on a Query

Create a report based on the Albums by Artist query we created previously.


Steps:
1. Create the Report.
 Ensuring the report Albums by Artist is selected in the left navigation pane, click
the Report button in the Ribbon.
2. Provide the parameter.
 Enter the name of an artist and click OK
 The report displays the fields in columns, with the field names as column headers.
 It has basic formatting applied, and this can easily be changed using the various
formatting options.

3. Add the Query Parameter to the Report.


The problem with the above report is that it doesn't display the artist name. So there's no
indication of which artist the albums belong to.
 Switch to Design View
 Increase the Height of the Report Header.
 Select a new Text Box Control. From the Design tab of the Ribbon, click the
Controls button and select the text box option.

 Add the Text Box to the Report.


o Click in the report header, under the title, and drag it so that it's wide
enough to display the longest text that will be displayed.

 Add the parameter to the text box by entering the following:


=[Reports]![Albums by Artist]![Which Artist?]
Also change the label to read Artist:
 Alternatively, you can add the parameter into Control Source on the Properties
Sheet under data tab.
4. Run the report by clicking the Report View icon in the bottom right corner of the screen.
 You will be prompted to enter an artist name. Enter Artist Name and click ok.
Add Command button to Form

Create a Macro
A macro is a set of actions that can be run automatically, and on demand. Macros can be used to
automate repetitive tasks, which can save time and effort for the user.
Macros are usually configured to run whenever a particular event occurs. You specify what that
event is when you create the macro.

You can create macros for almost any task, or set of tasks. The great thing about macros is that
they can run many tasks, one after the other, all at the click of a button. They can even be
configured to run automatically as soon as the database is opened.

Create a Simple Macro


Create a macro that opens a form automatically whenever the database is opened.
Steps:
1. Create a new Macro.
 Click the Macro button from the Create tab on the Ribbon.
 This creates a blank macro, ready to be set up.
2. Select an Action.
 Select OpenForm from the combo box.
3. Configure the Action.
 Select Albums from the Form Name combo box.
 Set View to Form and Window Mode to Normal.

4. Select another Action.


 Select GoToRecord from the combo box.
5. Configure the Action.
 Select New from the Record combo box.

6. Right-click on the macro's tab and select Save from the contextual menu.Name the macro
AutoExec and click OK.
 Be sure to name this macro AutoExec. This is a special name that makes the macro
run whenever the database is opened.
7. Run the Macro.
 The only way to test the macro is to run it.
 One way to run it is to double-click on it in the left navigation pane.
 But to test it properly, we need to make sure that it will run when the database is
opened. Therefore, we'll need to close the database and open it.
8. Click the File tab on the Ribbon. Then click Close from the menu.
9. Click the File tab on the Ribbon again. Then click Open from the menu. Then click the
database to open it. In our case, click Music.
10. The database opens and the form automatically appears.

Add Command Button to Form

 Click the Command button tool. The mouse pointer changes to a tiny crosshair attached to
a command button when you point anywhere in the form.
 Click and drag in the form where you want the button to go, then release the mouse. This
draws a button and simultaneously opens the Command Button Wizard.
 Click the Record Operations in the categories list box. Choose Add New Record as the
operation. Click Next.
 Click the Text option button in the next screen. Click Next. Type Add Record as the name
of the button, then click the Finish command button. The completed command button
should appear on your form. Save the form.
Create the Additional Command Buttons
 Click the Command button tool. Click and drag in the form where you want the second
button to go.
 Click Record Navigation in the categories list box. Choose Find Record as the operation.
 Click Next command button. Click the Text option button in the next screen. Click Next
command button.
 Type Find Record as the name of the button, then click the Finish command button. The
completed command button should appear on your form.
 Repeat these steps to add the command buttons to delete record (Record Operations) and
close the form (Form Operations). Save the form.
Reset the Tab Order
 Click anywhere in the Detail section. Pull down the View menu. Click Tab Order to
display the Tab Order dialog box.
 Click the AutoOrder command button so that the Tab key will move to fields in left-to-
right, top-to-bottom order as you enter data in the form. Click OK to close the Tab Order
dialog box. Save the form.
Lab Task 5. Generate the report given below using Report wizard under create tab

SubForms:
Subform is a form within a form. A main form can have multiple subforms. Main table can have
multiple levels of subforms. Subform is useful for displaying a one-to-many relationship within a
one-to-many relationship.
The easiest way to create a subform is by using the Subform Wizard.
Steps:
1. First select the table and the fields from that table using form wizard under creat tab.
2. Add Columns
from both
tables Artist
and
album.
We want to diplay
albums by artists.
3. Click next
4. Choose how you want to view the records. Select by Artsts.

5. Choose a layout.

6. Save your form and subform as separate objects. And click Finish.
Lab Task 7. Create the given below tables and then create subforms using following
snapshot.
The Switchboard Manager
A switchboard is a user interface that enables a nontechnical person to open the objects in an
Access database by selecting commands from a menu. The switchboard itself is stored as a form
within the database, but it is quite different from the forms you have learned in the previous
sections, it is not used for data entry, but rather as a menu for the user.