Lecture 2
Lecture 2
IN3193
Database
Management
Instructor
Dr. Muhammad Waqar
muhammad.aslam@purescollege.ca
Forms in MS Access
• A form is a database object that you can use to create a user
interface for a database application.
• Think of forms as windows through which people see and reach
your database in a more visually attractive and efficient way.
• It is mainly used to ease the process of data entry or editing.
• Data in a form can be selected from one or more tables.
• Forms can also be used to control access to data, like which fields
or rows of data are visible to which users.
• Help you to display live data with easy creation of new data.
1
6/17/2020
Create a Form
• To understand form download Fourth Coffee database from google
class.
• Open Coffee inventory table from this database
Creating a Form
• There are four primary ways to create the form as mentioned
below:
• Form Wizard
• Form
• Multiple Item
• Split Form
2
6/17/2020
3
6/17/2020
Final Form
4
6/17/2020
• By default, populate all the column from the selected table in 'form
view,'
• The user can delete non-required column manually
10
Steps
10
5
6/17/2020
11
11
12
12
6
6/17/2020
13
13
14
Step 1
14
7
6/17/2020
15
Step 2
15
16
16
8
6/17/2020
17
Step 1
17
18
Step 2
18
9
6/17/2020
19
19
20
Step 1
20
10
6/17/2020
21
Step 2
Save the form and then open the original table to see if it has been
updated.
21
22
22
11
6/17/2020
23
Step 1
23
24
Step 2
Save the form and then open the original table to see if it has been
updated.
24
12
6/17/2020
25
Applying Theme
• The Themes command applies a predefined color and font scheme
to a form or report. A theme modifies a form by controlling the color
and fonts of its text.
• To apply a theme, first change to Layout view. On the Form Layout
Tools Design contextual tab, in the Themes group, click the
Themes button to view a gallery of theme styles from which to
choose.
• You can point to each option to see the name of that format and a
live preview before it is applied to the form.
25
26
Applying Theme
26
13
6/17/2020
27
27
28
Sorting in Form
• You can sort data in the Form view of a form.
• The order that is chosen when a form is designed becomes that
object’s default sort order.
• But when viewing the form, users can sort the records in whatever
way is most useful for them.
• You can sort the records in a form on one or more fields.
28
14
6/17/2020
29
Sorting
• Create Coffee Inventory form for Coffee Inventory table in Fourth
Coffee Database
• Right-click the Product Name field to display the shortcut menu.
• Click Sort A to Z. The form is sorted by Product Name from A to Z.
The record with the first alphabet is displayed first.
• Click the Next record button on the record navigator at the bottom
of the form. Continue clicking through all the records to see the
records in order according to price.
• On the Home tab, in the Sort & Filter group, click the Remove Sort
button. The records have resorted back to their original order.
29
30
Filtering
• Common filters are built into every view that displays data.
• The filters available depend on the type and values of the field. When
you apply the filter, only records that contain the values that you are
interested in are included in the view.
• Filter settings remain in effect until you close the form—even if you
change to another view.
• If you save the form while the filter is applied, it will be available the
next time you open the form.
• To permanently remove a filter, on the Home tab, in the Sort & Filter
group, click the Advanced button and then click Clear All Filters.
30
15
6/17/2020
31
Filtering
• Open Coffee Inventory form for Coffee Inventory table in Fourth Coffee
Database
• Right-click the Product Name field to display the shortcut menu, click
Text Filters, and then select Contains. Click Contains to display the
Custom Filter dialog box.
• In the product name contains box, type vanilla and then click OK.
• Click the Next record button on the record navigator at the bottom of
the form. Continue clicking to see the five records that contain the word
“vanilla” in the Product Name field.
• Similarly Right-click the Pounds field to display the shortcut menu, click
Numbers Filters, and then select less than and use a value of 29 to see
all records with pounds less than 29.
31
32
Filtering by Form
• Filter by form is useful when you want to filter several fields in a form or
if you are trying to find a specific record.
• To use filter by form, open the form in Form view and make sure the
view is not already filtered
• On the Home tab, in the Sort & Filter group, click Advanced and then
click Filter By Form. Click the down arrow in a field to display the
available values.
• Enter the first set of values on the Look for tab at the bottom of the
page and then click the Or tab and enter the next set of values. Each
time you click the Or tab, Access creates another Or tab; so you can
continue to add additional filter values. Click the Toggle Filter button to
apply the filter.
32
16
6/17/2020
33
Filtering by Form
• Open Coffee Inventory form for Coffee Inventory table in Fourth Coffee
Database
• On the Home tab, in the Sort & Filter group, click the Advanced Filter
Options button and then click Filter By Form. A form filter appears.
• Place the insertion point in the Pounds Box and then click the down
arrow on the right to display the list of options.
• Select 25. An or option appears at the bottom, click there an chose
second Pounds option as 30.
• Nine values with Pounds equal to 25 or 30 will be displayed
33
34
Reports
• A report is a database object that is used to organize and display data
pulled from tables and queries.
• You can create a report using the Report button, Report Wizard button,
Report Design button, and Blank Report button, depending on the
amount of customization desired.
• You can also create labels using the Labels button.
• After creating a report, you can instantly apply a Theme to create a
professional look.
• You can also sort and filter data in a report to display the records to suit
your needs.
34
17
6/17/2020
35
Reports
• A report’s record source is the table or query that provides the data
used to generate a report.
• Before you can create a report, you need to define the record source
by clicking in the Navigation Pane on the table or query on which you
want to base the report.
• Then, click the Report button and a report is automatically generated
based on the table or query you selected.
• You can modify a report’s design, print, or save and close a report. You
should save a report’s design if you are likely to use it again. To save a
report, click the Save button on the File tab or in the Quick Access
Toolbar.
35
36
Report Generation
• Open Coffee Inventory table in Fourth Coffee Database
• On the Create tab, in the Reports group, click the Report button.
• The report appears in Layout view. Notice the Report Layout tools that
appear in the Ribbon.
• You can change the layout, font, color, page numbering etc. of the page
from those tools.
• Click the Product ID header to select it. Position the pointer over the
right border until you see a double-sided arrow. Click and drag, resizing
the column to remove excess white space.
36
18
6/17/2020
37
Report Wizard
• The Report Wizard displays a series of questions about the report you
want, and then it creates the report for you based on your answers.
• The Report Wizard knows what makes a good report, so the questions
are designed to help you create a professional report with little effort.
• The Report Wizard is usually the easiest way to create a report when
you want to choose which fields to include. It guides you through a
series of questions and then generates a report based on your
answers.
• If you want to skip steps such as Sorting or Grouping in the Report
Wizard, click the Next button to go to the next screen. You can click the
Finish button anytime it is available to create the report with the choices
you have specified.
37
38
38
19
6/17/2020
39
39
40
40
20
6/17/2020
41
41
42
42
21
6/17/2020
43
43
44
44
22
6/17/2020
45
QUERY
• A query is a set of instructions used for working with data.
• Creating a query is similar to asking the database a question.
• Running a query performs these instructions and provides the
answers.
• You can sort, group, or filter the results that a query returns.
• Basic queries can be used to extract useful information from one or
more tables in the database, while more advanced queries can be used
to manipulate data in tables
45
46
Creating a Query
• A query can get its data from one or more tables, from existing queries,
or from a combination of the two.
• The tables or queries from which a query gets its data are referred to
as its record source.
• When one table provides the information that you need, you can create
a simple select query using the Query Wizard.
• You can also use a query to find records with duplicate field values in a
single table.
46
23
6/17/2020
47
Creating a Query
• To create a simple select query, click the Query Wizard button in the
Queries group on the Create tab.
• Click Simple Query Wizard and then click OK. Specify the table you
want to use as the record source and the fields that you want to show.
Name the query and then click Finish.
• When you close the query, it is automatically saved.
• You can also save a query as a PDF, XPS, or as a Query, Form, or
Report using the Save As Object option.
47
48
48
24
6/17/2020
49
Query Exercise
• In the Tables/Queries drop-down list, Table: Coffee inventory table
would be automatically selected.
• Under Available Fields, select product name and Pounds fields.
• Select Finish
• Query will be created and will be shown on left hand navigation pane
and a name will be automatically given to it
• This query can be executed anytime by clicking on the query name on
the left hand menu. That will show the product name and Pounds for
that product.
49
50
50
25
6/17/2020
51
51
52
52
26
6/17/2020
53
53
54
54
27
6/17/2020
55
55
56
56
28
6/17/2020
57
57
58
58
29
6/17/2020
59
59
60
Macros
• A macro in Access is a tool that allows you to automate tasks and add
functionality to your forms, reports, and controls.
• For example, if you add a command button to a form, you associate the
button's OnClick event to a macro, and the macro contains the
commands that you want the button to perform each time it is clicked.
• Macro can be considered as a simplified programming language that
you write by building a list of actions to perform.
• Macros enable you to add functionality to forms, reports, and controls
without writing code in a Visual Basic for Applications (VBA) module.
• Macros provide a subset of the commands that are available in VBA,
and most people find it easier to build a macro than to write VBA code.
60
30
6/17/2020
61
Macros
• To create a Macro, go to Create tab and click on Macro in the Macro
and Code group.
• That will create a Macro and will ask you to add a list of actions.
• You can click on Action Catalogs to see a list of actions available
• Show all Actions lists all actions available including those which are not
recommended by MS Access
• You can click on Add new action and select any action. Alternatively,
you can also search for an action in Action list available.
61
62
62
31
6/17/2020
63
63
Thank You
64
32