Professional Documents
Culture Documents
STUDENT EDITION
APPENDICES - ..................................................................................................... 1
INDEX .................................................................................................................. 82
CONCEPTS OF NORMALISATION
Discussion
The theory of database design includes standards called normal forms. The process of
arranging your data into the standards is called Normalisation or Normalising data. By
normalising your database, you eliminate redundant data and organise your tables so
that managing data and future changes to the structure of the database is easier.
By normalising your database you split larger tables into smaller tables which are more
manageable and easier to maintain. To work with the related data you must then
reconnect the tables via relationships between common fields.
Data normalisation is not specific to Access, but is part of the database design process.
There are five normal forms; each addresses specific problems and each assumes the
requirements of the preceding form have been satisfied.
A Table is in the First Normal Form when each field contains the smallest meaningful
value and the table does not contain repeating groups of fields.
Tables that are not in the first normal form usually have fields containing data that can
be broken down into smaller meaningful parts e.g. placing a complete name into one
field instead of splitting it into first and last names. They also contain repeating groups
of fields which list the same category of data in multiple fields. This can be corrected by
creating separate tables for each of related values.
The Second Normal Form applies only to tables with a multiple field primary key. In
these tables any non key fields should relate to the entire primary key. In other words,
any non key fields should be a fact about the entire primary key.
Tables that are not in the second normal form usually have repeating values in a field
due to the fact that the field does not relate entirely to the primary key. If a fields value
depends only on part of the primary key it should be removed and placed in a separate
table.
The third normal form applies only to tables with a single field primary key. In these
tables each non key field should be a fact about the primary key. That is a non key field
should not be a fact about another non key field.
Tables that are not in the third normal form usually have repeating values in a field due
to the fact that the field does not relate to the primary key. If a fields value does not
describe the primary key it should be removed and placed in a separate table.
A Table is in the Fourth Normal Form when there are no independent one-to-many
relationships between what should be the primary key and non key fields.
Tables not in the fourth normal form usually contain blanks in non key fields and
duplicate values in the field you want to set as the primary key. The usual reason for
this is the table has been based on two different subjects. Separate the data into two new
tables each about one specific topic.
A Database is in the fifth normal form when the tables are broken down into the
smallest possible tables to eliminate redundant non key fields. Usually, tables that are
not in this form contain repeating values of data in the non key fields.
Putting a database in this form allows you to control database integrity. Because each
piece of non key data normally only appears once in the data base it is relatively easy to
update the data.
Junction Tables
A normalised database will sometimes not contain common fields which allow you to
create relationships between tables. To over come this create a table, sometimes called a
junction table, which contains the fields which can link the tables. For example if you
have a table which has a list of employee numbers and names and a table which
contains project numbers and descriptions. Create a Junction table which contains the
fields for employee number and project number and use this to assign employees to
projects.
When designing tables there are three basic rules that you can
follow to ensure a good database design.
1. Make each table only about one specific subject.
2. Each non key field should be a fact about the entire
primary key.
3. Each field should contain the smallest meaningful data
value.
Discussion
Once a database has been normalised it will contain many smaller tables of related
information. To combine information from these separate tables relationships can be set
up so that when the tables are combined in a query to compile information from more
than one table the common fields are automatically joined and the appropriate
information is retrieved. If this is the case and the appropriate relationships have not
been set up then a join between two tables can be created from within the query.
To create a join in a query drag the appropriate field from the first field list with the
mouse and drop it on the appropriate field on the second field list. The join is created,
but is only effectual within the query it was created and does not affect the rest of the
database.
Once created the type of join can be changed. The default join type is called an inner or
equi join. This type of join will only include records in the recordset where the common
fields match.
This can be changed to a outer join where the all the records in one of the tables plus all
the matching fields from the other table are included in the recordset. This type of outer
join can be changed to include all the records from either the left hand or fight hand of
the two tables plus the remaining matching fields.
Once created the join type can be changed by double clicking on the join in the design
view of the query and selecting the appropriate type required from the resulting dialog
box. Outer joins are indicated in the query design view by placing an arrow on either
the left or right hand side of the join line.
To remove a join from a query select the join with the mouse and then press the delete
key.
When adding more than one table to a query the Control and
Shift Keys can be used to make multiple selections of tables in
the show table window.
Procedures
1. Open the database.
2. Create a new query in Design view
3. Select the tables required and add then to the query
4. Create any required joins by dragging one common field from one
field list to another common field on the second field list.
5. Select the required fields for the query as usual
6. Run the query.
CROSS PRODUCTS
Discussion
When a query of more than one table is created without any relationships or joins
Access has no way of matching common fields between these tables. When this
happens the recordset is said to be called a cross product.
A cross product recordset will match every single record on one table with every single
record on the second table. For example if you create a query with two tables and no
join. If there was 100 records on one table and 40 records on the other the cross product
record set would contain 4,000 records (100 * 40).
To correct a cross product query create an appropriate join between the two tables in the
query.
Discussion
By using the is null criteria in combination with an outer join it is possible to get a
record set from a query that was previously not available.
For example in the previous example the query was created with an inner join and
displayed 82 results of customers and their orders. By changing the join type to an outer
join the recordset displayed 84 results including two companies who had yet to place an
order. By applying a criteria of is null to the Order Number Field only the two
customers who haven’t placed an order will be displayed in the recordset.
Discussion
You can create a query to which you add different criteria each time you run it; such a
query is called a parameter query. A parameter query is designed to prompt the user for
input each time it is run; Access then runs the query based on the criterion (parameter)
entered. A parameter query allows you to quickly and easily change query criteria
without having to redesign the query.
You can add multiple parameters to a query; when you run the
query, a prompt will appear for each parameter in it.
Procedures
1. Open the desired query in Design view.
2. Select the Criteria row in the desired field.
3. Type an open bracket ([), the desired prompt, a colon, and the close
bracket (]).
4. Press [Enter].
Discussion
A concatenation query allows you to combine two or more text fields into one field. In
other words, concatenation enables you to append one text string to another. In addition,
you can insert characters between the text strings as needed. For example, you can
concatenate the City, State, and Postal Code fields and store the concatenated text
string in a fourth field, the Address field, adding commas and spaces between the text
strings as needed.
When typing a concatenation expression, the first part of the expression defines the
name of the new field and the second part of the expression defines the fields which are
to be concatenated. All field names must be surrounded by brackets. The concatenation
character (the ampersand - &) appears between field names, and you must enclose any
additional characters in double quotes. For example, the expression Names: [Last
Name]&", "&[First Name] concatenates the Last Name and First Name fields and
inserts the concatenated text string into a field called Names. The new field displays the
last name, a comma, a space, and the first name for each record in the table.
Procedures
1. Open the desired query in Design view.
2. Select any blank Field row in the design grid.
3. Type the desired concatenation expression.
4. Press [Enter].
EXERCISE
DESIGNING ADVANCED QUERIES
Task
Design advanced queries.
Create a query and set the join type. Create a parameter and a concatenation query.
View subdatasheets
Discussion
Tables can be joined, or related, in order to access and coordinate information in all the
fields of the related tables. Joining tables is a useful way to avoid entering duplicate
information in various, related tables. In addition, it allows you to create reports, forms,
and queries from the related data tables and save them in the database file. Relating
tables allows you to create smaller, more efficient tables that can be referenced when
you need access to the data.
When you relate tables, the table from which you select a field to join is the primary
table, and the second table containing the field you want to associate is the related table.
The tables must have at least one common field that contains the same type of data.
This common field is called the join field. The join fields in both tables must have the
same or equivalent data types and, if they are Number fields, they must have the same
field size. In addition, the join field in the primary table must be the primary key in
order to avoid duplicate entries.
For example, the following table consists of customer names and address fields, along
with a unique identification number for each customer, which serves as the primary key
in the table. You can create this number or allow Access to create it for you.
You could then create a separate table consisting only of orders placed by customers.
This table would also contain the field for the unique customer identification number,
but not the customers’ names and addresses.
ID # Order
1 Office Work Center
2 All-In-One Corner Desk and Hutch
3 Open-Front Steel Bookcase
4 2-Drawer Letter File
5 Executive Leather Chair, Black
By relating the two tables through the common customer identification number field,
the customers’ name and address does not have to be entered for every order. All that
has to be entered is the customer identification number, along with the orders.
Access includes two basic types of relationships: one-to-many and one-to-one. A one-
to-many relationship occurs when one record from the primary table matches many
records from the related table (e.g., one customer record matches many order records).
A one-to-one relationship occurs when one record from the primary table matches one
record from the related table. Access determines the relationship type automatically
when you create the relationship.
Discussion
The Relationships window displays a graphic representation of database relationships
and allows you to create relationships between tables. You drag field lists in the
Relationships window to reposition them as needed. In addition, any field name that
represents a primary key is bolded in the corresponding field list.
You can add tables to the Relationships window for additional joins. For example, if the
Relationships window displays only two related tables and you need to access
information from a third table, you can easily add the required table to the Relationships
window and then create the join.
You can select multiple tables in the Show Table dialog box
by holding the [Ctrl] key as you click each table. Selecting
Add adds all the selected tables to the Relationships window.
Procedures
1. Click the Relationships button on the Database toolbar.
Discussion
When you create a relationship between two tables, you can set referential integrity.
Referential integrity is a built-in set of rules Access uses to make sure that the
relationship is valid. Referential integrity can also prevent accidental deletion or editing
of data. In order to use referential integrity, the following conditions must be true: the
related field in one table must be its primary key, the related fields in both tables must
have the same data type, and both tables must belong to the same database.
When you set referential integrity, you must observe the following three rules; First,
you cannot enter data in the join field in the "many" table that does not have a match in
the join field in the "one" table. Second, you cannot delete records from the "one" table
if there are matching records in the "many" table. Third, you cannot edit primary key
values if related records exist.
If you want to perform any of the changes listed above, however, and still maintain
referential integrity, you can select the Cascade Update Related Fields and Cascade
Delete Related Records options in the Edit Relationships dialog box. If either or both
of these options are selected, Access automatically makes the necessary changes to
related tables to maintain referential integrity. It is recommended that these two options
be selected only after careful consideration, since the changes cannot be undone.
When referential integrity is enforced, Access displays symbols above the join line to
indicate the type of relationship, one-to-one or one-to-many. The number 1 above a join
line indicates “one”, and the mathematical symbol for infinity (which resembles a
horizontal 8) indicates “many”.
Procedures
1. Open the Relationships window.
2. Double-click the middle segment of the desired join line.
3. Select the Enforce Referential Integrity option.
4. Select the Cascade Update Related Fields option, if desired.
5. Select the Cascade Delete Related Records option, if desired.
6. Select OK.
VIEWING SUBDATASHEETS
Discussion
Subdatasheets are datasheets nested in the primary table and display the data in joined
tables. When you join tables in a one-to-many relationship, Access creates
subdatasheets in the table containing the primary key.
When tables are joined, Access inserts a column containing plus signs to the left of the
first field in the primary table. Clicking the plus sign expands a subdatasheet with the
data in the related table displayed. If the table contains additional joins, you can expand
subdatasheets to display each related table. Access can display up to eight levels of
subdatasheets.
In addition to viewing data, you can edit data right in the subdatasheet; the edited data is
saved back to the table in which it is stored.
Displaying subdatasheets
Procedures
1. Open the primary table in Datasheet view.
2. To display a subdatasheet, click the plus sign next to the record you
want to expand.
3. Display additional subdatasheets, if available.
4. Click the minus sign next to any subdatasheet you want to collapse.
Discussion
Deleting a join line removes the relationship between two tables. You may want to
delete a join line if you no longer need to relate the tables or you want to create a
different relationship.
You must select a join line before you can delete it.
Procedures
1. Open the Relationships window.
2. Click the middle segment of the join line you want to delete.
3. Press [Delete].
4. Select Yes.
EXERCISE
CREATING RELATIONSHIPS
Task
Create relationships between tables and set referential integrity.
1. Open Train08x.
2. Open the Relationships window.
3. Add the Client and Project tables to the Relationships window.
4. Create a relationship between the Client ID field in the Client table
and the Client ID field in the Project table; set referential integrity
for the relationship.
5. Add the Trainer table to the Relationships window.
6. Create a relationship between the Trainer Initials field in the
Project table and the Initials field in the Trainer table; set
referential integrity for the relationship.
7. Close the Relationships window and save the changes.
8. Open the Client table in Datasheet view and view the subdatasheet
for the CONCORD client. Then, collapse the subdatasheet and close
the Client table.
9. Open the Relationships window. Delete the relationship line between
the Project and Trainer tables and remove the Trainer field list,
since it is no longer related to any tables. Then, close the
Relationships window and save the changes.
10. Close the database file.
Discussion
You can create or customize a form in Design view. A form has three basic sections:
Detail, Form Header/Footer, and Page Header/Footer.
The Detail section contains the information from the table or query. You create controls
in the Detail section that allow you to display or enter information. Access provides a
variety of control types you can add to the form to simplify the data entry process. For
example, you can replace a text box with a list box or an option group so that you can
select a value rather than type it during data entry. In many cases, it is quicker and
easier to select a value from a list rather than to remember the value you want to use and
then type it. Having a list of choices also helps to ensure the consistency of the data
being entered.
The Form Header and Form Footer sections display at the top and bottom of a form
in Form view. They are stationary when you scroll the Detail section, making them
useful for displaying titles or instructions you want visible on the form at all times. If
you print the form, these sections appear at the top of the first page and at the bottom of
the last page. You can also place controls, including images, labels, and fields in the
form header or footer.
The Page Header and Page Footer sections display at the top and bottom of the form
in Design view. They do not appear in Form view. Rather, they display at the top and
bottom of every page when the form is printed. Page headers and footers can contain
images, lines, and text, or any other controls you want printed on every page.
When you enable the display of either the page or form header/footer section, both the
header and the footer appear. You can drag the header and footer sections to resize
them.
A form with form and page headers and footers in Design view
Discussion
You can create a combo box on a form. A combo box provides you with a list of values
from which you can choose. Choosing from a list is much faster and more accurate than
remembering a value to be typed. However, you can also type a value directly into a
combo box if the appropriate value is not available from the list.
A combo box can be bound to a field, meaning that when you select or enter a value,
that value is entered into that field in the corresponding table. A combo box can also be
unbound, meaning that when you select or enter a value, it is held in memory to be used
in another control or calculation.
Access provides a Combo Box Wizard that guides you through the process of creating a
combo box. You can select the list of values from an existing table or query, or you can
create the values for the list yourself. If you choose to select the list from an existing
table or query, the wizard prompts you to enter the table or query and the field name. If
you choose to create the list of values yourself, the wizard displays a column for the
entries. Either way, once the values are entered into the wizard, you then specify
whether the values should be entered into a field in the table or held in memory for later
use. You complete the combo box by entering a label.
When you use the Combo Box tool, the mouse pointer changes into a copy of the tool
with a plus sign (+) above and to the left of it.
Procedures
1. Open the desired form in Design view.
2. Display the toolbox.
Discussion
You can create a list box on a form. A list box provides you with a list of values from
which you can choose. Choosing from a list is much faster and more accurate than
remembering a value to be typed. However, unlike a combo box, you can only choose
an item from the list; values not present on the list cannot be entered into the table.
A list box can be bound to a field, meaning that when you select or enter a value, the
value is entered into a field in the corresponding table. A list box can also be unbound,
meaning that when you select or enter a value, it is held in memory to be used in
another control or calculation.
The List Box Wizard guides you through the process of creating a list box. You can
select the list of values from an existing table or query, or you can create the values for
the list yourself. If you choose to select the list from an existing table or query, the
wizard prompts you to enter the table or query and the field name. If you choose to
create the list of values yourself, the wizard displays a column for the entries. Either
way, once the values are entered into the wizard, you then specify whether the values
should be entered into a field in the table or held in memory for later use.
When you use the List Box tool, the mouse pointer changes into a copy of the tool with
a plus sign (+) above and to the left of it. The center of the plus sign (+) indicates the
position of the top left corner of the list box.
You can set the default value for a list box by opening the
property sheet and typing the desired value in quotation marks
in the Default Value property box on the Data page.
Procedures
1. Open the desired form in Design view.
2. Display the toolbox.
5. Select the desired option for the source of the list box values.
6. Select Next.
7. Type the number of columns for the list box.
8. Press [Tab].
9. Type the first value for the list box.
10. Press [Tab].
11. Continue to type values as desired.
12. Select Next.
13. Select the desired storage option for the field.
14. Select the Store that value in this field list, if applicable.
15. Select the desired field name, if applicable.
16. Select Next.
17. Type a label for the list box.
18. Select Finish.
Discussion
You can create an option group on a form. An option group provides you with a limited
set of values from which you can choose. Choosing from a set of values is often much
faster and more accurate than remembering a value to be typed. With an option group,
you can only select one option from the set of alternatives. Therefore, option groups are
best utilized when there are five or less values from which to choose. Adding more than
five values to an option group can crowd a form and is less effective for quick data
entry.
An option group has a frame that encloses the set of values. These values appear beside
option buttons or check boxes, or on top of toggle buttons.
The Option Group Wizard guides you through the process of creating an option group.
An option group can be bound to a field in a table or query. However, only the frame is
bound to the field. Within the frame, Access assigns each option a numeric value,
starting with the number 1. When the option is selected, this numeric value is entered
into the corresponding field. Access assigns a number because the value of an option
group cannot be text. For example, if a product comes in three colors (white, black, and
green), you can use an option group in an order entry form to select the color being
ordered. By default, Access assigns the number 1 to the White option, the number 2 to
the Black option, and the number 3 to the Green option. You only see the White,
Black, and Green options on the form, but Access actually stores the assigned numbers
in the corresponding field in the table.
When you use the Option Group tool, the mouse pointer changes into a copy of the
tool with a plus sign (+) above and to the left of it. The center of the plus sign (+)
indicates the position of the top left corner of the option group.
Procedures
1. Open the desired form in Design view.
2. Display the toolbox.
14. Select the Store the value in this field list, if applicable.
15. Select the desired field name, if applicable.
16. Select Next.
17. Select the desired option for the control type.
18. Select the desired style option.
19. Select Next.
20. Type the caption for the option group.
21. Select Finish.
Discussion
Some tables contain fields that have a Yes/No field type. These fields can contain a Yes
(True) value, a No (False) value, or no value at all.
When working with a form that contains a Yes/No field, you can create a logic control
that is bound to the Yes/No field. Logic controls give a visual display of the value in a
Yes/No field, such as a check box where a check mark appears when the field value is
Yes and does not appear when the value is No. Another type of logic control is the
toggle button, which appears “sunken” for a value of Yes and “raised” for a value of
No. The logic control for a field with a null value (neither Yes nor No is chosen)
appears the same as the field with a No value.
Logic controls improve the visual effectiveness of a form and facilitate data entry. With
a logic control, the value of a Yes/No field is selected with a single click of the mouse
button rather than multiple keystrokes.
The way in which the different controls indicate a Yes or No value are described in the
following table:
Control Appearance
Toggle button Appears “sunken” with a Yes value and “raised” with
a No value.
Option button Contains a dot with a Yes value and appears empty
with a No value.
Check box Appears checked with a Yes value and unchecked
with a No value.
Procedures
1. Open the desired form in Design view.
2. Display the toolbox.
3. Click the desired logic control tool in the toolbox.
4. Click in the form where you want the logic control to appear.
Discussion
The tab order determines the order in which form fields and controls are selected when
you press the [Tab] key during data entry. The default tab order is the order in which
the fields or controls were added to the form. If you have added, rearranged, or deleted
fields or controls, the tab order may not be suitable for data entry. You can choose to
have Access automatically rearrange the tab order to reflect the order of the fields on
the form. The fields are then accessed from left to right across each row.
You can also open the Tab Order dialog box by right-clicking
in the Design window and then selecting the Tab Order
command.
Procedures
1. Open the desired form in Design view.
2. Select the View menu.
3. Select the Tab Order command.
4. Select Auto Order.
5. Select OK.
Discussion
The tab order determines the order in which form fields and controls are selected when
you press the [Tab] key during data entry. The default tab order is the order in which
the fields or controls were added to the form. If you have added, rearranged, or deleted
fields or controls, the tab order may not be suitable for data entry. You can adjust the
tab order manually to reflect whatever order is best for your data entry needs.
Procedures
1. Open the desired form in Design view.
2. Select the View menu.
3. Select the Tab Order command.
4. Select the record selector to the left of the field you want to move.
5. Drag the field to the new position.
6. Select OK.
Discussion
The Form Header and Form Footer sections display at the top and bottom of the form
in Form view. They are stationary when you scroll the Detail section, making them
useful for displaying titles or instructions you want visible on the form at all times. If
you print the form, these sections appear at the top of the first page and the bottom of
the last page.
You can place controls, including images, labels, and fields, in the form header or
footer.
You can also display the Form Header and Form Footer
sections by right-clicking in the Design window and then
selecting the Form Header/Footer command.
You can also add Page Header and Page Footer sections to a
form. Page headers and footers only appear when the form is
printed. These sections can be added to the form by selecting
the View menu and then selecting the Page Header/Footer
command.
Procedures
1. Open the desired form in Design view.
2. Display the toolbox.
3. Select the View menu.
4. Select the Form Header/Footer command.
Discussion
You can create a form from scratch in Design view. For example, if a form does not
currently exist for a particular table or query, you can create one using the fields in the
selected table or query. You can then determine the design of the form by adding fields,
control, and options.
Procedures
1. Display the Forms object list.
EXERCISE
USING ADVANCED FORM DESIGN
Task
Use advanced form design.
1. Open Train18x.
2. Create a new form in Design view based on the Project table.
3. Add the Client ID, Course Name, and Sales Rep fields to the 2.5cm
(1”) mark on the horizontal ruler on the form. Move all the controls
so that the labels begin at the 3.8cm (1/2”) mark on the horizontal
ruler.
4. Close the form and save it as Sales.
5. Open the New Payment Form form in Design view. Display the
ruler and the toolbox, if necessary.
6. Using the Combo Box tool, create a combo box for the trainers’
initials at the 3.8cm (1 1/2") mark the horizontal ruler, below the
Payment Date text box.
7. Indicate that the combo box should look up values in a table as the
source for the values in the list. Select Table: Trainer as the table
and include the Initials field in the combo box. Accept the default
column width. Store the values entered in the combo box in the
Trainer Initials field and label the combo box Trainer Initials.
8. Using the List Box tool, create a list box for the credit rating at the
3.8cm (1 1/2”) mark on the horizontal ruler, below the Trainer
Initials combo box.
9. Indicate that you want to type in the values for the list box. Use one
column and type the values A, B, and C as separate entries. Store the
values entered in the list box in the Credit Rating field and label the
list box Credit Rating.
10. Reduce the height of the list box so that it displays only one line of
text. Move the controls under, and left-aligned with the Trainer
Initials controls.
11. Select the Project ID, Payment Date, Trainer Initials, and Credit
Rating bound controls (text boxes) and size them to the narrowest
size. Then, vertically space them equally.
12. Using the Option Group tool, create an option group at the 2.5cm
(1”) mark on the vertical ruler, below the Total Sale text box.
13. Type Yes and No as the label names and select Yes as the default
choice. Change the default value of the Yes label to -1 and the No
label to 0. Store the value entered in the option group in the
Recorded field. Use Option buttons as controls and select the
Raised style. Enter Recorded? as the label.
14. Open the Tab Order dialog box and set the tab order automatically.
15. Switch to Form view and press [Tab] as necessary to view the tab
order. Return to Design view.
16. Create a custom tab order. Move the Payment Date above the
Amount Paid and close the Tab Order dialog box.
17. Display the form header in Design view and create a label with the
text Payment Form in the left side of the form header.
18. Switch to Form view and create the following new record.
Field Value
Project ID: 23
Payment Date: 10/3/01
Amount Paid: 600
Trainer Initials: EK
Credit Rating: B
Recorded: No
19. Close the form and save it.
20. Close the database file.
Discussion
You can create or customize a report in Design view. A report has three basic sections:
Detail, Report Header/Footer, and Page Header/Footer.
The Detail section contains the information from the table or query. You create controls
in the Detail section that display information. You can display either one record per
page or multiple records per page.
The Report Header and Report Footer sections display at the top and bottom of the
report in Design view. When you print the report, these sections appear at the beginning
and the end of the report only. The header can be used for report titles, while the footer
can be used for report totals or other summaries.
The Page Header and Page Footer sections display at the top and bottom of the report
in Design view. When the report is printed, these sections appear at the top and bottom
of every page. Page headers and footers can contain images, lines, text, or any other
controls you want printed on every page.
When you enable the display of either header and footer section, both the header and the
footer appear. You can drag the header and footer sections to size them.
Procedures
1. Open the desired report in Design view.
2. Select the View menu.
Discussion
You can add a calculated control to a form or report. A calculated control is not bound
to a field. It contains an expression that uses information from fields to calculate a
result. The result is not stored in a table. It is calculated when the report or form is run.
You can type the expression that calculates the result directly into the control or open
the property sheet and type the expression into the Control Source property box on the
Data page.
Procedures
1. Open the desired report in Design view.
2. Display the toolbox.
Discussion
You can group data in reports that have a common field. It is often easier to read a
report when data is grouped, since you can then easily find the pertinent data. For
example, you can group a sales report by region so that regional personnel can easily
locate the data for their region.
A grouped report automatically sorts the table by the data in the grouped field. You can
nest groups inside one another, up to ten levels. For example, in the regional report, you
may want to group by state within each region.
When you group data, you can display a group header and footer that can be used to
display information at the top or bottom of each group. For example, you can add a
calculated control in a group footer that calculates summary information, such as a total
or an average for each group. Additionally, you can control page breaks by specifying
how group heading and records should be kept together.
You can also use the Sorting and Grouping dialog box to
specify multiple fields on which to sort. You do not have to
display group headers or footers for all sort fields. For
example, you can group an order form by order number and
sort within the group by order date.
Procedures
1. Open the desired report in Design view.
Discussion
You can create a header and footer for each group that appears in a grouped report.
The header displays at the top of each group. Often, the group header contains the
control for the grouped field, meaning that the common value on which the grouping is
based, such as the region, appears only once at the top of each group.
A group footer is often used to display summary information about the group, such as
total or average sales. You create a group summary by inserting a calculated control
into the group footer and create an expression using an aggregate function such as Sum
to display group totals or Avg to display group averages. Group aggregate functions can
also be placed in a group header.
Procedures
1. Open the desired report in Design view.
2. Select the control you want to insert into the group header.
3. Drag the control to the corresponding group header section.
4. To create a group summary, click the Text Box tool in the toolbox.
5. Click in the location for the control.
6. Type the desired summary expression for the calculated control.
7. Press [Enter].
8. Select the label box paired with the control.
9. Double-click the text in the label box.
10. Type the desired label text.
11. Press [Enter].
Discussion
In a grouped report, you can create a running summary of the items in the group. A
running summary provides a cumulative total for all the groups above.
Often, the running summary is positioned in the group footer, which appears at the
bottom of every group. For example, in a sales report grouped by region, you can create
a calculated field that displays information in a running summary. After each group, a
cumulative total for all the groups above appears.
Procedures
1. Open the desired report in Design view.
2. Create the group summary calculated control expression.
3. Select the calculated control.
Discussion
You can insert controls that display the current date and/or time in a report. Each
control updates automatically every time the report is previewed or printed. By default,
a date/time control is inserted into the Report Header section. However, you can easily
move it to another section. For example, you could place the date in the Report Footer
section so that it would be readily visible on the last page of the report.
The Date and Time dialog box inserts a control that uses the
=Date() function to display the current date.
Procedures
1. Open the desired report in Design view.
2. Select the Insert menu.
3. Select the Date and Time command.
4. Select or deselect options as desired.
5. Select OK.
6. Drag the date control to the desired position in the report.
Discussion
When you print a report, Access automatically starts a new page when necessary. You
can control the pagination by inserting a page break. You can insert a page break in the
Group Footer section to place each group on its own page, or you can insert a page
break in the Report Header section to create a separate title page for a report.
Procedures
1. Open the desired report in Design view.
2. Display the toolbox.
Discussion
By default, the margins for a report are one inch on all sides. You can control the
margin settings to fit more or less data on a page as necessary. The margins you set for
a report are saved and applied each time you print the report.
Procedures
1. Open the desired report in Design view.
2. Select the File menu.
Discussion
You can create a report from scratch in Design view. For example, if a report does not
currently exist for a particular table or query, you can create one using the fields in the
selected table or query. You can then determine the design of the report by adding
fields, control, and options.
Procedures
1. Display the Reports object list.
EXERCISE
USING ADVANCED REPORT DESIGN
Task
Use advanced report design.
1. Open Train18x.
2. Create a new report in Design view based on the Project table.
3. Add the Client ID field to the 2.5cm (1") mark on the horizontal
ruler in the Detail section. Below the Client ID field, add the
Course Name, Trainer Initials, and Students fields to the report at
the 7.5cm (3") mark on the horizontal ruler in the Detail section.
4. Display the report header and footer. Using the toolbox, add a label
to the left side of the report header. Enter the text Client
Information.
5. Preview the report. Then, close the report and save it as Client Info.
6. Open the Project Information Report report in Design view.
Display the toolbox, if necessary.
7. Add a calculated control below the Trainer Initials text box to
calculate the profit margin of each project. The calculation should
use the following formula: =[Total Sale]*.08. Format the calculation
as currency. Position the calculated control under the Trainer
Initials text box. Change the text in the label to Profit Margin. If
necessary, resize the label to view all the text, and then, position it
under the Trainer Initials label.
8. Preview the report. Notice the profit margin calculation. Then,
switch back to Design view.
9. Sort the report by the Trainer Initials field in an Ascending order
and a secondary sort by Project ID in Ascending order. (Hint: Use
the first and second rows of the Sorting and Grouping dialog box.)
For the Trainer Initials field, include a group header and group
footer, group on each value, and keep the whole group together.
10. Move both Trainer Initials controls to the Trainer Initials Header
section. Move the Profit Margin controls up directly below the
Total Sale controls.
11. Use the Toolbox toolbar to create a horizontal line above the Project
ID controls from 0cm (0”) to 10cm (4”) on the horizontal ruler.
Then, reduce the size of the Details section by moving the bottom
border just under the Profit Margin controls.
12. Preview the report and scroll through the pages. Notice that the
trainer initials now appear as a header and the records for each
trainer are kept together on a page. Switch back to Design view.
13. Create a new calculated control at the 7.5cm (3”) mark on the
horizontal ruler in the Trainer Initials Footer section that sums the
profit margin for projects by each trainer. The calculation should use
the following formula: =Sum([Total Sale]*.08). Format the
calculated control as currency. Change the text in the label control to
Total Profit.
14. Create another horizontal line in the Trainer Initials Footer section,
above the Total Profit controls, and from 0cm (0”) to 10cm (4”) on
the horizontal ruler. Then, preview the report.
15. Switch back to Design view and change the Total Profit calculated
control to a running summary for each group.
16. Preview the pages of the report. Notice that the total profit
calculation is now cumulative for each trainer.
17. Switch back to Design view. Display the Report Header/Footer
section.
18. Insert the date only using the default date format Move the date
control to the Page Footer section.
19. Adjust the top and bottom page margins to 2cm (.75").
20. Preview the report to see the new margins. Notice that the date
appears on each page of the report. Close the report, saving the
changes.
21. Use the Label Wizard to create labels based on the Trainer table.
Use the Avery L7161 labels and the default font and color settings.
Include the First Name and Last Name fields, separated by a space
on the same line. Sort the labels by the Last Name and First Name
fields. Use Labels Trainer as the name of the report.
22. Close the labels report after viewing it.
23. Close the database file.
Create a subform/subreport
Discussion
You can display a form/ report within a form/ report. The main form/ report includes
information from one table and the subform/ subreport includes information from a
second, related table.
You can show a form or report within a form/ report to more effectively show the
linked data from tables with one-to-many relationships. The main form/ report and the
subform/ subreport are linked by a common field between the tables. The main form/
report represents the one side of the one-to-many relationship and the subform/
subreport represents the many side. When viewing a record in the main form/ report
(one side relationship), the subform/ subreport displays the related records from another
table (many side relationship). For example, you have a Customer table and an Orders
table. Each customer has several orders. In the Customer form (bound to the Customer
table), you can include an Orders subform (bound to the Orders table). The tables
would probably be linked by a Customer ID field; a field present in both tables. As you
view a customer’s record displayed in the main form, the order records of that customer
appear in the subform. When you move to the next customer record in the main form,
the order records in the subform are updated to display that customer’s orders. Just as
you can manipulate table data in a form, you can also manipulate the related table data
using the subform. Using the same example, you can edit the customer records or the
order records.
Subform data can be displayed in either Form view (one record at a time) or Datasheet
view (many records displayed at once), while subreport data can only be displayed in
Print Preview. You can also create and display subform data in a PivotTable or
PivotChart.
You can add any number of subforms/ subreports to a form/ report as well as add a
subform/ subreport within another subform/ subreport. You should keep in mind that
the purpose of a form/ report is to make viewing and entering data easier. You can
avoid cluttering the form/ report (which can cause confusion) by positioning the
subform(s) or subreport(s) carefully, assigning a different background color to each, and
removing any unnecessary items, such as scroll bars. Viewing the properties of the
subform/ subreport is helpful when considering these options.
The SubForm/ SubReport Wizards provide the easiest method for creating a subform
subreport. If you choose not to use the SubForm/ SubReport Wizards, you will need to
design a form/ report and then insert it into another form/ report. You may not want to
use the wizard if you are designing a subform/ subreport that is very different in
appearance from the form report the wizard produces.
CREATING A SUBFORM/SUBREPORT
Discussion
When you add a subform/ subreport to an existing form, it is best to start by creating the
main form/ report before you create the subform/ subreport. The form/ report can then
be edited so that it contains only the information you need, as well as the desired layout.
This form can be added to the design of the main form where it will take on the
properties of a subform or subreport.
You can create a subform that will appear in Form view, Datasheet view, or both
views. When the form is created using the SubForm Wizard, a subform is created that
can be viewed in both Form and Datasheet views. You can customize the subform in
Design view by adding headers, footers, color, fonts, totals, etc.
Procedures
1. Open the desired database.
2. Open the desired form or report in Design view.
3. Display the toolbox.
Discussion
In order to improve the efficiency or appearance of a subform/ subreport, you can
change its layout the same way you would change the layout of a form/ report. In
Design view for the main form/ report, the subform/ subreport is a control that you can
move, resize, align, add, and delete as you would any other control. Since the subform/
subreport control contains a form/ report, you can open it in Design view and make any
editing changes to its controls. Any changes to the layout of the subform/ subreport are
performed in Design view.
Procedures
1. Open the desired database.
2. Open the main form in Design view.
3. Double-click the subform control you want to edit.
4. Double-click the subform control text to select it.
5. Make the desired editing changes.
Discussion
You can display a subform in Datasheet view. This option allows you to view many
subform records at once, rather than viewing them one at a time in Form view. Since
the benefit of using subforms is to display the “many” side of a one-to-many
relationship, Datasheet view is generally preferred.
You can add a record to both the main form and the subform
by selecting the Insert menu and then selecting the New
Record command.
Procedures
1. Open the desired database.
2. Open the main form in Form view.
3. Select a field in the subform.
4. Select the View menu.
5. Point to the Subform command.
6. Select the Datasheet command.
Discussion
Forms and reports often include totals of the information they contain. These totals are
easily created by adding a calculated control to the form or report that contains an
expression to find the desired total. Expressions are used to obtain information you
cannot obtain directly from the tables in your database. For example, if you have a table
that contains the quantity and cost of various items, you could use an expression to
multiply the quantity and the cost to obtain the current inventory value. Every time you
use a form/report, Access calculates any expressions contained in the form/report,
helping you keep your information as accurate as possible.
The expression in the main form/report control that refers to the subform/subreport
control defines the name of the subform/subreport and the name of the
subform/subreport control being used in the following format:
You can also display a subreport total in the main report using
the same methods that you use to display a subform total.
You can also display the property sheet by selecting the View
menu and then selecting the Properties command or by right-
clicking a form or report in Design view and then selecting the
Properties command.
Procedures
1. Open the desired database.
2. Open the form or report in Design view.
3. Display the toolbox.
EXERCISE
USING SUBFORMS/SUBREPORTS
Task
Use a subform.
1. Open Train28x.
2. Open the Invoice Form form in Design view.
3. Use the SubForm Wizard to create a subform in the bottom center of
the form.
4. Insert the existing Project Form form as a subform.
5. Select the appropriate option from the list box to link the main form
and subform by the Project ID field. Name the subform Project
Info.
6. Delete the subform’s label box.
7. Size and position the subform control so that all the fields appear, if
necessary.
8. Switch to Form view to see the subform.
Discussion
You can design one or more command buttons to appear on a form. These command
buttons can then be used to access commonly used functions. For example, if you
frequently use the Calculator, you can create a command button that can simply be
clicked to instantly access the Calculator.
Command buttons are particularly useful because they do not require the database user
to know the Microsoft Access menu structure. For example, instead of making the user
select the Print command from the File menu to print a displayed form, you could add
the Print function to a command button on the form.
Access provides different actions for you to use, which are available in the following
categories: Record Navigation, Record Operations, Form Operations, Report
Operations, Application, and Miscellaneous.
Procedures
1. Open the desired database.
2. Open the desired form in Design view.
Discussion
If you have an existing form you print often, you can save the form as a report. It is
possible to print a form directly, but reports are more suitable for presenting
information on paper, especially if you need to include group totals. Once a form is
saved as a report, its structure can be modified in Report Design view to suit your
needs.
You can also open the Save As dialog box by selecting the
desired form in the Database window, selecting the File menu,
and then selecting the Save As command.
Procedures
1. Open the desired database.
2. Display the Forms object list.
3. Right-click the form you want to save as a report.
4. Select the Save As command.
5. Type a name for the report.
6. Select the As list.
7. Select the desired Report or Form item.
8. Select OK.
Discussion
You can view any database form in PivotTable or PivotChart view using the View
list. In PivotTable view, you can summarize and analyze large amounts of data.
PivotChart view allows you to display data in a graphical environment. You design a
PivotTable or PivotChart view by dragging fields from the Field List to preset drop
areas in the PivotTable or PivotChart view workspace. As an alternative to dragging
fields, you can also select the desired field in the Field List, select the desired drop area
from the bottom of the Field List, and then use the Add to button to add the field to
that field.
In the Field List, fields are listed below a corresponding fieldset. When you expand the
fieldset, the individual fields are displayed. Field names become bolded when they are
added to the view workspace.
Once the table or chart is designed, fields can be moved, added, or deleted as desired. In
addition, you can apply formatting to the items in PivotTable or PivotChart to enhance
its appearance. You can use options in the property sheet or buttons on the Formatting
(PivotTable/PivotChart) toolbar to apply formatting.
When you create a PivotTable view, Access automatically creates a PivotChart view,
and vice versa. The PivotTable layout is slightly different than the PivotChart layout,
however, and may require slight modification. Specifically, when you drag a field into
the Drop Totals or Detail Fields Here area in a PivotTable, that field is added as a
detail field which displays the detail but not a summary of the detail. Because of the
nature of this field, the information will not display on the chart in the data field area. In
this instance, you will need to add that same field to the data area in PivotChart view.
The addition is also reflected in the PivotTable. Any formatting applied to items in each
view, however, is independent of the other view.
PivotTable and PivotChart views are automatically saved and updated as part of the
layout of the form when you close the form.
Procedures
1. Open the desired database.
2. Open the desired form.
3. Select the View list on the Form Design toolbar.
4. Select PivotTable View or PivotChart View.
5. Click the Field List button on the PivotTable toolbar.
6. To add a row or category, expand the fieldset on the Field List
containing the field you want to drag to the Drop Row Fields Here
or Drop Category Fields Here area on the view workspace.
7. Drag the desired field button from the Field List to the Drop Row
Fields Here or Drop Category Fields Here area.
8. To add a column or series, expand the fieldset on the Field List
containing the field you want to drag to the Drop Column Fields
Here or Drop Series Fields Here area on the view workspace.
9. Drag the desired field button from the Field List to the Drop
Column Fields Here or Drop Series Fields Here area.
10. To add a totals or a data detail field, expand the fieldset on the Field
List containing the field you want to drag to the Drop Totals or
Detail Fields Here or Drop Data Fields Here area on the view
workspace.
11. Drag the desired field button from the Field List to the Drop Totals
or Detail Fields Here or Drop Data Fields Here area.
12. To add a filter field, expand the fieldset on the Field List containing
the field you want to drag to the Drop Filter Fields Here area on the
view workspace.
13. Drag the desired field button from the Field List to the Drop Filter
Fields Here area.
EXERCISE
USING OTHER FORM TECHNIQUES
Task
Use other form techniques.
1 Open Train29x.
2. Display the Forms object list. Open Payment Form in Design view.
Use the Command Button Wizard to add a command button to run
the Calculator from calc.exe. (Hint: Select the Application category
in the wizard.) Have the text Calc appear on the command button
and name the button mycalc. Position the command button on the
form, as desired.
3. Switch to Form view and click the Calc command button to open
the Calculator. Close the Calculator. Close the form and save the
changes.
Discussion
By using the Form Control Wizards a command button can be set to open a form by
clicking on it. The form can be opened showing all the records or just a set of relevant
records. For example a command button can be set up on a form displaying invoice
information that when activated will display a form showing information about the
customer specific to the invoice currently displayed.
Procedures
1. Open the database.
2. Open the form in Design view.
Discussion
By using the Report Control Wizards a command button can be set to open a Report by
clicking on it. The Report can opened in Print Preview or printed directly. Thus a
Report can be previewed or printed directly from a Form by clicking on a command
button without having to return to the database window.
Procedures
1. Open the database.
2. Open the form in Design view.
Discussion
The Command Button Wizards can be used to control record navigation within a Form.
So a Command Button can be used to move forward or backwards through records in a
form or to create a new record. This can be useful when setting up forms for users who
are not so familiar with Access.
Procedures
1. Open the database.
2. Open the form in Design view.
Discussion
When using the Command Button Wizard to create a Command Button Access writes
VBA code to actually perform the operation the button is design for. The VBA code
(called an Event Procedure) is assigned to the On Click Property. Thus when the button
is clicked the VBA code is run and the operation is performed.
Once Access has written the VBA for the button it can be edited to alter the operation
the button performs. By Selecting the Event Procedure assigned to the On Click
property for the Command Button and then clicking on the build option the VBA
module window is opened. Now the VBA Code can be edited.
Procedures
1. Open the database.
2. Open the form in Design view.
3. Move the mouse the required Command Button
4. Double Click on the Button to activate the Property Sheet.
5. Select the Event Properties Tab
6. Select the On Click Property
7. Click on the Build Icon to the right of the Event Procedure
8. Edit the VBA code as necessary
9. Close the Module Window
EXERCISE
CONTROL W IZARDS
Task
Create a command button to open a form and then edit the Event Procedure created to
open the form in Data Entry Mode.
1. Open Train13a.
2. Open the Project Form in Design view.
3. Create a command button using the Command Button Wizard to
open the Payment Form displaying the specific payments for that
Project. Label and Name the Button Project Payments.
4. Test the Button.
5. Return to the Project Form.
6. Open the Event Procedure for the On Click Event Property of the
Project Payments Button.
7. Add the acFormAdd command to the open form command.
8. Close the module window.
9. Edit the Button Label to New Payment.
10. Test the button.
11. Close the Payment Form.
12. Close the Project Form saving the changes.
13. Close the Database
Discussion
In addition to the standard controls, such as option groups, combo boxes, and list boxes,
you can add ActiveX controls to a form or report. ActiveX controls are small
applications that can improve the appearance or functionality of a form or report. A
commonly used ActiveX control is the calendar control. This control appears as a
calendar in a form or report. The calendar control can be bound to a Date field in the
form. Instead of having to type in the dates, you can just click the desired date on the
calendar.
Discussion
Before you can use an ActiveX control, it must first be registered with Access. Once it
is registered, the name of the control appears in the ActiveX Controls dialog box.
Access then knows that the control exists and where it is located on the computer or
network.
Procedures
1. Open the desired database.
2. Select the Tools menu.
3. Select the ActiveX Controls command.
4. Select Register.
5. Select the Look in list.
6. Select the drive where the control is located.
7. Select the folder where the control is located.
8. Select the file containing the desired ActiveX control.
9. Select OK.
10. Select Close.
Discussion
After you register an ActiveX control with Access, you can add it to a form or report.
Once it is added, the ActiveX control can be used like any other control. You can move
and size it, as necessary, to fit on the form or report. You can also display and change
the properties of an ActiveX control.
Procedures
1. Open the desired database.
2. Select the Insert menu.
3. Select the ActiveX Control command.
4. Select the desired ActiveX control.
5. Select OK.
Discussion
Depending on the ActiveX control and its function, you can attach it to an existing table
in Access. For example, you can attach the calendar control from Microsoft Windows
95 to a Date field in Access. The calendar will then display the date on a calendar page
for the appropriate month and year.
Procedures
1. Open the desired database.
2. Open the desired form or report in Design view.
3. Select the ActiveX control.
EXERCISE
USING ACTIVEX CONTROLS
Task
Use ActiveX controls.
1. Open Train30x.
2. Open the Project Form form in Design view.
3. Insert the ActiveX calendar control onto the form.
4. Open the property sheet for the calendar control. Set the data source
in the Control Source property box to the Start Date field. Close
the property sheet.
5. Size the calendar control until it is approximately 3'' wide and 2''
high and position it below the existing controls, if necessary. Add a
label called Start Date and centre it above the calendar control.
6. Switch to Form view and move through the records. Notice that the
calendar changes to reflect the start dates.
7. Close the form without saving the changes.
8. Close the database file.
Delete an index
VIEWING INDEXES
Discussion
You can use indexes to help Access perform quicker sorts and searches. You should
index the fields you use regularly to sort or search for data.
Indexes have important properties that are listed in the following table:
Property Description
Primary Designates whether or not the index is the primary key
for the table. In other words, this property designates
whether or not the data in the indexed field will be
used to uniquely identify each record. If this property
is set to Yes, the Unique property must be set to Yes.
Unique Designates whether or not the values in the indexed
field must be unique for each record. You can set this
property to Yes without setting the Primary property
to Yes.
Ignore Nulls Determines whether or not records with null values in
the indexed field are included in the index. The default
setting is No, which means that null values are
included.
You can also display the Indexes dialog box by selecting the
View menu and then selecting the Indexes command when a
table is open in Design view.
Procedures
1. Open the desired database.
2. Open the table in Design view.
Discussion
You should index at least one field for each table to maximize performance. You should
select a field you are likely to use in searches and sorts.
When you change the Indexed property of a field to Yes, you can choose whether or
not to allow duplicates. If you choose the No Duplicates option, Access will not allow
duplicate values to be entered into the field.
Procedures
1. Open the desired database.
2. Open the desired table in Design view.
3. Select the field you want to index.
4. Select the Indexed property.
5. Select the Indexed list.
6. Select the desired indexing option.
Discussion
If you often search on a combination of fields, you can create an index on multiple
fields to speed up the searches and sorts. For example, if you want to sort customers in
order by region and alphabetically within each region, you can create an index on the
Region and Customer fields.
You must create a multiple field index in the Indexes window. All the fields you want
to include in the index should be listed under the same index name. You can include up
to ten fields in an index.
Procedures
1. Open the desired database.
2. Open the table in Design view.
DELETING AN INDEX
Discussion
Indexes take up disk space and can slow down the process of adding, editing, and
deleting records. In fact, if there are a limited number of different values in a field, the
sort or search speed is not significantly increased by indexing the field. Therefore, you
can delete any unwanted indexes to increase efficiency.
Procedures
1. Open the desired database.
2. Open the table in Design view.
Discussion
There are times when it is not possible to uniquely identify fields with the values in a
single field. Therefore, Access allows you to create a primary key using multiple fields.
When you set a primary key using multiple fields, the combination of the information in
the fields must be unique. For example, you have a table that contains line items for
customer orders. The order number is entered for each customer. Because you will most
likely have multiple customers with multiple orders, the order number associated with
each customer may not be unique. Also, a particular item number may appear in
multiple orders. Therefore, the item numbers may not be unique. Thus, you cannot
create a primary index on either of these fields by themselves. The solution is to create a
primary key index on both fields, which allows each item to appear only once on each
order.
Procedures
1. Open the desired database.
2. Open the table in Design view.
3. Point to the row selector to the left of the row containing the first
field for the primary key.
4. Click the row selector to the left of the row containing the first field
for the primary key.
5. Hold the [Ctrl] key and point to the row selector for the second
primary key field.
6. Click the row selector for the second primary key field and release
the [Ctrl] key.
EXERCISE
W ORKING WITH INDEXES
Task
Work with indexes.
1. Open Train31x.
2. Open the Invoice table in Design view.
3. Index the Client ID field, allowing duplicates.
4. Open the Indexes window.
5. Create a multiple field index called Client/Project. The first field in
the index should be Client ID and the second field should be Project
ID. Use the Ascending sort order for both.
6. Close the Indexes window. Then, close the Invoice table without
saving the changes.
7. Open the Project table in Design view.
8. Open the Indexes window and delete the existing indexes. Close the
Indexes window.
9. Create a multiple field primary key that includes the Project ID and
Client ID fields.
10. Open the Indexes window to view the primary key fields. Then,
close the Indexes window.
11. Close the Project table without saving the changes.
12. Close the database file.
Create a macro
Save a macro
Run a macro
Discussion
A macro performs a set of commands in sequence. While macros in word processors
and spreadsheets are used mainly to duplicate keystrokes or mouse movements, macros
in Access often automate an action or a series of actions. Such actions include opening
tables, printing forms, finding records, or applying filters. Macros can even be used to
add command buttons, create menus and toolbars, and build complete applications.
Macro commands in Access consist of an action and its arguments. The action is the
task to be performed, such as opening a form. The arguments determine the specifics for
the action, such as which form to open.
You create a macro in Access from the Macro Design window. This window has two
panes. The upper pane, called the Action pane, contains a design grid. The design grid
can contain up to four columns. The Action and Comment columns are always
displayed. The Action column contains one of the many available macro commands. In
the Comment column, you can type a description of the action. Comments are helpful
when you are editing macros that contain many actions. You can also display the
Macro Name and Condition columns. The Macro Name column contains a name for
a macro that can be referred to during events, such as clicking a command button. You
can execute a macro conditionally by adding a statement to the Condition column. The
lower pane, called the Action Arguments pane, contains the arguments. The arguments
listed change, depending on what action is selected.
Discussion
The design grid in the Action pane of the Macro Design window contains at least two
columns: Action and Comment. In the Action column, you enter the actions you want
the macro to perform. You can either type the name of the action or select one from the
list. In the Comment column, you describe the purpose of the action. Adding a
comment may not seem important when a macro is first created, but it can prove helpful
if you need to edit the macro at a later time.
The Action Arguments pane appears at the bottom of the window and varies according
to the action selected in the Action pane. Most actions require one or more arguments.
In the Action Arguments pane, the arguments pertaining to an action appear. The
arguments detail exactly what function the action performs.
Procedures
1. Open the desired database.
2. Display the Macros object list.
CREATING A MACRO
Discussion
When you select a field in the Action column, a list of actions appears. Most of the
actions are self-explanatory and have equivalent menu commands. For instance, the
OpenQuery action opens a query in Datasheet or Design view, depending on how the
arguments are set.
A macro can include up to 999 actions. You place each action in a separate row in the
design grid in the order in which they are to be performed. For example, a Maximize
command maximizes the window opened in the step immediately preceding it.
You use the Comment column to enter a description of the action to be performed. This
field can contain up to 255 characters. While comments are optional, it is beneficial to
enter a description of the action. This field is helpful if you want to modify the macro at
a later time.
Action Description
AddMenu Adds a drop-down menu item to a custom
menu bar.
ApplyFilter Applies a filter or query to restrict or sort
records.
Beep Sounds a tone through the computer's speaker.
CancelEvent Cancels the action that initiated the macro.
Close Closes a specified window.
CopyObject Copies the specified object to a different
database or the same database under a new
name.
DeleteObject Deletes the specified object.
Echo Specifies if the screen is to be updated while
the macro is running.
FindNext Locates the next record that meets criteria
specified by a find.
FindRecord Locates the first record following the current
record that meets criteria specified in the
arguments.
GoToControl Activates the specified field or control.
GoToPage Activates the first control on a specified page.
GoToRecord Makes the specified record the current record.
Hourglass Changes the mouse pointer to an hourglass
while the macro is running.
Maximize Enlarges the active window to fill the screen.
Minimize Reduces the active window to a button on the
taskbar.
MoveSize Moves and/or resizes the active window.
MsgBox Opens a message box containing a warning or
informative text.
OpenDataAccessPage Opens a data access page in the selected view.
OpenDiagram Opens a project diagram.
OpenForm Opens a form in the selected view.
OpenModule Opens a module at the selected procedure.
OpenQuery Opens a query in the selected view.
OpenReport Opens a report in the selected view.
OpenStoredProcedure Opens a project stored procedure in the
selected view.
OpenTable Opens a table in the selected view.
OpenView Opens a view in the current project.
OutputTo Outputs data in the specified object to Excel
text (.XLS), rich-text (.RTF), or MS-DOS text
(.TXT).
Action Description
PrintOut Prints the specified datasheet, form, report, or
module.
Quit Quits Access.
Rename Renames the specified database.
RepaintObject Completes any pending screen updates for the
active or specified object.
Requery Updates the data in a specified control of an
active object or updates itself if no control is
specified.
Restore Restores a maximized or minimized window to
its previous size.
RunApp Runs an application from within Access.
RunCode Runs a Microsoft Access Basic Function
procedure.
RunCommand Performs a menu command.
RunMacro Runs a macro.
RunSQL Runs an action query using the corresponding
SQL statement.
Save Saves the specified object. If an object is not
specified, the active object is saved.
SelectObject Selects an object.
SendKeys Sends keystrokes directly to Access or to an
active Windows application.
SendObject Includes a specified object in an electronic mail
message to be viewed and forwarded.
SetMenuItem Sets the appearance of a command that appears
in a custom menu.
SetValue Sets the value of a field, control, or property on
a form or report.
SetWarnings Turns system messages on or off.
ShowAllRecords Removes any applied filter from the applicable
active object and displays all records.
ShowToolbar Displays or hides a toolbar.
StopAllMacros Stops all currently running macros.
StopMacro Stops the currently running macro.
TransferDatabase Imports or exports data between an Access
database and another database.
TransferSpreadsheet Imports or exports data between the active
database and a spreadsheet file.
TransferText Imports or exports text between the active
database and a text file.
You can use the [Tab] key and the [Shift+Tab] key
combination to navigate between the Action and Comment
columns.
Procedures
1. Open the desired database.
2. Open the Macro Design window.
3. Select the first blank field in the Action column.
4. Select the Action list.
5. Select the desired action.
6. Select the corresponding field in the Comment column next to the
action.
7. Type a description for the action.
Discussion
Most action arguments have a default list of available arguments. For example, the
View argument field for the OpenReport action contains a list with the Print, Design,
and Print Preview arguments. For action arguments without a list, you can type the
argument into the argument field. You can enter up to 255 characters into the argument
field.
Some arguments are required. For example, you must select the Form Name argument
for the OpenForm action. Other arguments, such as Filter Name, are not required for
the OpenForm action. If a required argument is missing, the macro stops when the
action containing the missing argument is encountered.
In some cases, a default argument is used. For example, the View argument defaults to
Form for the OpenForm action. Other arguments are ignored if they are not selected.
For example, the Filter Name argument allows you to select a query to apply to the
form as a filter. If you do not enter a query name, all the records appear.
With forms, you can also specify a Where Condition argument. This argument acts as
a filter, without using an actual query. For example, the argument [Credit Limit] =
1000 limits records to those with a credit limit of $1000. You can type the condition
directly into the argument box or click the Build button in the argument box to open the
Expression Builder dialog box.
Access displays a helpful message explaining the selected argument to the right of the
argument boxes. If you press the [F1] key while the insertion point is in the Action
Arguments pane of the Macro Design window, a help window for the argument opens
with additional information.
The available macro actions and their associated arguments are listed in the following
table. When the text (req.) appears next to an item in the Arguments column, either an
argument or a selection from a list is required for the macro to run properly:
Action Arguments
AddMenu Menu Name (req.), Menu Macro Name (req.),
Status Bar Text
ApplyFilter Filter Name, Where Condition (one or both req.)
Beep None
CancelEvent None
Close Object Type, Object Name, Save (req.)
CopyObject Designation Database, New Name, Source
Object Type, Source Object Name
DeleteObject Object Type, Object Name
Echo Echo On (req.), Status Bar Text
FindNext None
FindRecord Find What (req.), Match (req.), Match Case
(req.), Search (req.), Search As Formatted (req.),
Only Current Field (req.), Find First (req.)
GoToControl Control Name (req.)
GoToPage Page Number (req.), Right, Down (if a Right is
specified, a Down must be specified and vice
versa)
GoToRecord Object Type, Object Name, Record (req.), Offset
Hourglass Hourglass On (req.)
Action Arguments
Maximize None
Minimize None
MoveSize Right, Down, Width, Height
MsgBox Message, Beep (req.), Type (req.), Title
OpenForm Form Name (req.), View (req.), Filter Name,
Where Condition, Data Mode (req.), Window
Mode (req.)
OpenModule Module Name, Procedure Name
OpenQuery Query Name (req.), View (req.), Data Mode
(req.)
OpenReport Report Name (req.), View (req.), Filter Name,
Where Condition
OpenTable Table Name (req.), View (req.), Data Mode
(req.)
OutputTo Object Type (req.), Object Name, Output
Format, Output File, Auto Start, Template File
PrintOut Print Range (req.), Page From (req.), Page To
(req.), Print Quality (req.), Copies (req.), Collate
Copies (req.)
Quit Options (req.)
Rename New Name (req.), Object Type, Old Name
RepaintObject Object Type, Object Name
Requery Control Name
Restore None
RunApp Command Line (req.)
RunCode Function Name (req.)
RunCommand Command (req.)
RunMacro Macro Name (req.), Repeat Count, Repeat
Expression
RunSQL SQL Statement (req.), Use Transaction (req.)
Save Object Type, Object Name
SelectObject Object Type (req.), Object Name (req.), In
Database Window (req.)
SendKeys Keystrokes (req.), Wait (req.)
SendObject Object Type, Object Name, Output Format
(req.), To (req.), Cc, Bcc, Subject, Message
Text, Edit Message (req.), Template File
SetMenuItem Menu Index (req.), Command Index (req.),
Subcommand Index, Flag (req.)
SetValue Item (req.), Expression (req.)
SetWarnings Warnings On (req.)
ShowAllRecords None
Action Arguments
ShowToolbar Toolbar Name (req.), Show (req.)
StopAllMacros None
StopMacro None
TransferDatabase Transfer Type (req.), Database Type (req.),
Database Name (req.), Object Type (req.),
Source (req.), Destination (req.), Structure Only
(req.)
TransferSpreadsheet Transfer Type (req.), Spreadsheet Type (req.),
Table Name (req.), File Name (req.), Has Field
Names (req.), Range
TransferText Transfer Type (req.), Specification Name (req.),
Table Name (req.), File Name (req.), Has Field
Names (req.), HTML Table Name
You can press the [F6] key to toggle between the Action pane
and the Action Arguments pane. You can use the [Tab] key
and the [Shift+Tab] key combination to navigate through the
argument fields.
Procedures
1. Open the desired database.
2. Open the Macro Design window.
3. Select the action in the Action column to which you want to assign
an argument.
SAVING A MACRO
Discussion
After creating a macro, you must save it before you can test or run it. When you attempt
to save a macro or close the Macro window without saving, a Save As dialog box opens
with the default name of Macro# (numbered consecutively). It is best to use a short
name that clearly indicates the function of the macro. The name Macro1, for example,
does not mean much to other users who may be working with the macro.
The name that you give the macro appears in the Macros object list in the Database
window. All the macros associated with the database being used appear in the Database
window.
You can also save a macro by selecting the File menu and
then selecting the Save command.
Procedures
1. Open the desired database.
2. Create the desired macro.
Discussion
Access runs macros so quickly that you may not be able to see each action as it is
performed. If you wish to confirm that the actions are being performed correctly, you
can step through the macro. Single step mode is particularly useful when a macro
contains numerous actions or arguments, or when a macro does not seem to perform as
planned.
When you step through a macro, Access pauses before each action, allowing you to
view each step. The Macro Single Step dialog box opens, displaying the macro name,
condition, action name, and selected arguments. The Macro Single Step dialog box has
three buttons: Step, Halt, and Continue. You select the Step button to perform the
action in the dialog box. If there are no errors, the next action appears in the dialog box.
If you want to stop running the macro in this mode, you select the Halt button. The
macro stops running and the dialog box closes. When you want to stop stepping through
the macro and run the remaining steps, you select the Continue button. The remaining
macro actions are then completed.
If an error does occur, you can make the changes in the Macro Design window. After
you make the changes to a macro, you should retest it.
You should only use single step mode when working in the
Macro Design window. When you enable single step mode, it
remains activated throughout the current Access session. All
macros will run in single step mode until the mode is disabled.
Procedures
1. Open the desired database.
2. Open the desired macro in the Macro Design window.
6. Select the Halt button to stop running the macro and close the dialog
box.
7. Select the Continue button to run the remaining steps.
RUNNING A MACRO
Discussion
You can run a macro from the Database window by selecting the Macros tab and
double-clicking the desired macro name or by selecting the desired macro name and
selecting the Run button on the Database window toolbar.
Procedures
1. Open the desired database.
2. Select the Macros object list.
3. Select the macro you want to run.
Discussion
After you have created a macro, you may decide to add or delete existing actions or
change actions or action arguments. In the Macro Design window, you can cut, copy,
and paste to edit a macro. You can also insert and delete rows. After you make the
desired changes, you must save the macro to save the changes. It is a good idea to test
the edited macro using single step mode. You must remember to disable single step
mode after testing a macro.
Procedures
1. Open the desired database.
2. Select the Macros object list.
3. Select the macro you want to edit.
Discussion
You can run a macro using the Tools menu. This option allows you to execute a macro
from almost anywhere. When the Run Macro dialog box opens, you can either type the
name of the macro in the text box or select the macro name from a list.
Procedures
1. Open the desired database.
2. Display the Macros object list.
3. Select the Tools menu.
4. Point to the Macro command.
5. Select the Run Macro command.
6. Select the Macro Name list.
7. Select the macro you want to run.
8. Select OK.
Discussion
You can create a macro using the Macro Builder. The Macro Builder is used when you
want to associate a macro with an existing object or control. The steps for creating a
macro using this method are similar to creating a macro using the New button on the
Database window toolbar.
Creating a macro using this method requires that you associate the macro with an event,
such as On Click or On Close. When you select an Event property, the Build button
appears. The Build button gives you access to the Macro Builder.
Procedures
1. Open the desired database.
2. Open the desired form or report in Design view.
3. Select the desired object or control to associate the macro.
EXERCISE
CREATING MACROS
Task
Create, test, and edit a macro.
1. Open Train34x.
2. Create a new macro. Enter the following actions and comments:
Action Comment
OpenForm Opens the Invoice Form
MoveSize Sizes the Invoice Form and positions it at
the top of the window
OpenForm Opens the Payment Form in Datasheet view
MoveSize Sizes the Payment Form and positions it
below the Invoice Form
Action Arguments
OpenForm Form Name: Invoice Form
Data Mode: Read Only
MoveSize Right: 0cm (0”)
Down: 0cm (0”)
Width: 15.5cm (6”)
Height: 7.5cm (3”)
OpenForm Form Name: Payment Form
View: Datasheet
Data Mode: Read Only
MoveSize Right: 0cm (0”)
Down: 7.5cm (3”)
Width: 15cm (6”)
Height: 5cm (2”)
8. Save the macro and disable single step mode. Close the Macro
Design window.
9. Run the Open Invoice/Payment Forms macro using the Tools
menu.
USING PROPERTIES
Discussion
Properties allow you to specify the appearance and behavior of objects in a database.
Objects include tables, queries, forms, and reports, as well as controls within reports or
forms.
Property sheets display the properties of a selected object. They have several tabs
including Format, Data, Event, and Other that list the properties by group. The groups
are the same for every property, but the items in the group change depending on the
type of object selected. The All page displays all the properties in a single list.
The Format properties allow you to control the appearance of an object, such as color,
font, size, and borders. These properties change automatically when you make changes
to an object. The Data properties allow you to specify the source of the data and control
items, such as default values. The Event properties allow you to control when an action
occurs. The Other properties contain items that do not fit into the other three
categories, such as the name of a control when used in a macro or text that appears in
the status bar.
Discussion
You can associate a macro with a control on a form or report using the Event properties
of the control. An event is an action, such as a mouse click or a change in value that can
initiate a response. The macro runs automatically when the specified event involving
that control occurs.
Many events involve the control having the focus. Focus means that the control can
receive data from mouse clicks or keyboard actions. For example, field boxes, toggle
buttons, and radio buttons can have the focus, since they can respond to data entry from
the keyboard or mouse. Only one control can have the focus at a time. The Event
properties of a text box control are listed in the following table:
By linking a command button or a control with a macro, you can make commonly used
functions easier. Initiating macros this way is particularly useful because it does not
require the user to know or use the Access menu structure. For example, you could
associate a macro with a command button on a form to print a report. The user could
then print the report by clicking the command button, without having to open the report
or know the correct menu commands.
You can also open the property sheet for a control by double-
clicking the control, selecting the View menu and then
selecting the Properties command, or by right-clicking the
control and then selecting the Properties command.
Procedures
1. Open the desired database.
2. Open the desired form in Design view.
3. Select the desired control.
Discussion
Command buttons are controls to which you can assign actions. They are often used to
run macros in a form or report. You can place descriptive text or a picture on a
command button so that the user can easily identify the purpose of the button.
You create a command button in Design view using the Command Button tool in the
toolbox. After you create the command button on the form, you set the properties, such
as the event property to initiate the action and the text or picture to appear on the button.
Procedures
1. Open the desired database.
2. Open the desired form or report in Design view.
3. Display the toolbox.
Discussion
You can add a condition argument to a macro. An argument acts very much like a filter.
Just as a filter displays only the records that meet the condition, the argument only
performs the macro when the condition is met.
Before you can add a condition to a macro, you must display the Condition column in
the Macro Design window. The Condition column appears to the left of the Action
column in the upper pane of the Macro Design window. You can type a condition or use
the Expression Builder dialog box to create the expression.
If you type an expression, there are certain rules you must follow when referring to
controls in tables, queries, forms, and reports. All references must be separated with an
exclamation point. Additional rules for the database objects and controls are listed in
the following table:
Controls Rules
Controls in tables Enclose the name of the table and the name of the
control in square brackets and separate them with
an exclamation point. For example,
[Orders]![Customer ID] refers to the Customer
ID field in the Orders table.
Controls in queries Enclose the name of the query and the name of
the control in square brackets and separate them
with an exclamation point. For example, [Order
Items]![Item Number] refers to the Item
Number field in the Order Items query.
Controls in forms Enclose the name of the form and the name of the
control in square brackets and separate them with
an exclamation point. Indicate that you are
referring to a form by beginning the statement
with the word Forms. For example,
Forms![Customers]![Customer ID] refers to the
Customer ID field in the Customers form.
Controls in reports Enclose the name of the report and the name of
the control in square brackets and separate them
with an exclamation point. Indicate that you are
referring to a report by beginning the statement
with the word Reports. For example,
Reports![Customer Sales]![Contact Name]
refers to the Contact Name field in the
Customer Sales report.
Since you enter the condition in the Condition column in the Macro Design window,
you do not need to include the word IF in the statement. Access assumes the statement
is a condition. If the condition is true, Access performs the corresponding action in that
row. If the condition is false, Access does not perform the action.
Procedures
1. Open the desired database.
2. Open the desired macro in the Macro Design window.
Discussion
You can place multiple macros on the same macro sheet. This option, called grouping
macros, has several advantages. The most obvious advantage is that it reduces the
number of macros that appear in the window. More importantly, it allows you to
organize your macros by grouping related macros together onto a single macro sheet.
For example, if you created several macros that are related to one form, you can group
all of them together on one macro sheet.
Before you can create a group macro, you need to display the Macro Name column in
the Macro Design window. The Macro Name column appears to the left of the Action
or Condition column, if it is displayed. You can type the macro name directly into the
appropriate field in the Macro Name column.
Like any other macro, a group macro must be saved with a name. You should make
sure that the group macro name is descriptive enough to indicate its contents. This helps
other users know what macros are contained in the group macro. For example, if all the
macros relate to the Orders form, you could name the group macro Order Form
Macros.
When macros are grouped, you can still refer to individual macros. To refer to an
individual macro in a group, you can use its group and macro name in the format
Groupname.Macroname.
If you have already created macros, you can cut and paste
them into a new group macro sheet or edit an existing macro
sheet.
Procedures
1. Open the desired database.
2. Display the Macros object list.
3. Open the Macro Design window.
Discussion
While you can select a command to run a macro, you can also have a macro that runs
automatically when a database is opened. This type of macro is called an Autoexec
macro because it is automatically executed when the database is opened.
You can create an Autoexec macro to automate or simplify the database for other users.
For example, assume that you want someone in your office to add customer orders on a
specific form. To ensure that they use the correct form, you could create an Autoexec
macro that opens the form for them.
You can create an Autoexec macro in two ways. You can rename an existing macro
Autoexec, or you can create a new macro and save it with the name Autoexec. Since
the Autoexec macro is stored with the database, each database can have its own
Autoexec macro. However, you can only have one Autoexec macro per database.
Procedures
1. Open the desired database.
2. Display the Macros object list.
3. Right-click the macro name you want to rename.
4. Select the Rename command.
5. Type Autoexec.
6. Press [Enter].
EXERCISE
USING MACROS
Task
Use macros.
1. Open Train35x.
2. Rename the Open Payment/Invoice macro to Autoexec. Make sure
that you press [Enter] after you rename it. Close the database and
reopen it to test the macro. Notice that the two form windows open.
Close the form windows.
3. The Balance macro opens a message box warning that there is a
balance due for the project. Attach the Balance macro to the
Balance Due text box control on the Payment Form form. Use the
On Got Focus event. Close and save the form.
4. Open the Payment Form form in Form view. Click the Balance
Due text box. Notice that a message box opens. Close the message
box. Move through the next several records and notice that the
message box opens whether or not there is a balance due. Close the
form window.
5. Add a condition to the Balance macro so that the macro only runs
when the balance due is greater than 0. Enter the following condition
for the macro: Forms![Payment Form]![Balance Due] > 0.
6. Close the Macro Design window and save the changes to the macro.
7. Open the Payment Form form in Form view. Click the Balance
Due text box. Notice that a message box opens for the first record
because there is a balance due (a balance greater that 0). Move
through the next several records and notice that the message box
only opens when a balance is due. Close the form window.
8. Create a command button on the Project Form form without using
the wizard. Place it in the lower left corner of the form. Attach the
View Report macro to the command button so that it runs when the
mouse button is clicked. Enter the text Print Project Report in the
Caption property box. Resize the button to display all the text, if
necessary.
9. Close and save the Project Form form. Open the Project Form
form in Form view and test the Print Project Report command
button. Notice that the form prints. Close the form.
10. Create a group macro. Enter the following names, actions, and
arguments in the Macro Design window:
11. Save the macro as Client Macros. Close the Macro Design window.
Discussion
Each control, section and entire object on a form or report has properties. It is the event
properties for each of these that can be used to attach either modules or macros. Thus
enabling automation, data validation or various other procedures to be started when
certain events occur.
When a macro/module attached to a event property will actually run will depend on the
event property itself. The table below lists the different event properties and when then
take affect.
Discussion
By using a conditional macro a field can be tested to see if it contains a correct value.
Although this can be done using Validation Rules and the required properties by using a
macro the response to a incorrect value can be customised to not only come up with and
error message, but also return the user to the appropriate field.
Using the MsgBox action can create a custom message box and the GoTo Control
action can be used to return the user to the appropriate field.
Finding the appropriate event to attach a macro is a important factor to take into
account. If the macro to check the value entered was attached to the OnExit property of
the field, it would not check the fields contents if the fields was skipped over by the
user. Instead if the macro was attached to the before update property of the form it will
always check the contents of the field before the record is saved.
Procedures
1. Open the database.
2. Select the Forms tab.
3. Open the Form in design view
4. View the Forms Properties
6. Select the Before update Property
7. Click on the build option and select the macro builder
8. Name the macro and add conditions
9 Set the test to check the contents of the Field
10. Set the Actions to perform the appropriate commands
11. Assign the appropriate arguments to the actions
12. Close the Macro Builder window and save the changes
13. Close the property sheet
Discussion
By using a conditional macro fields can be automatically filled on a form depending
upon the value of another field. The check on the contents of the field can be carried
out after the data ahs been entered into the field and the user presses tab or enter to
move onto the next field. Thus by assigning a conditional macro to the OnExit property
to the field another field can be conditionally filled depending upon the value of the
first field.
By using the SetValue action in a macro a control or a controls properties can be set .
Then using the Goto control action the filled control can be bypassed.
Procedures
1. Open the database.
2. Select the Forms tab.
3. Open the Form in design view
4. View the Fields Properties
6. Select the OnExit Property
7. Click on the build option and select the macro builder
8. Name the macro add conditions
9 Set the test to check the contents of the Field
10. Set the Actions to perform the appropriate commands
11. Assign the appropriate arguments to the actions
12. Close the Macro Builder window and save the changes
13. Close the property sheet
EXERCISE
EVENT PROPERTIES
Task
Create a macro to check the contents of a field
1. Open Train10a.
2. Open the New Payments form in Design view.
3. Attach a macro to the Forms Before update property, calling it check
4. Create the macro to require a number >0 is entered into the amount
paid field
5. Set the macro to stop the update, produce a relevant message box and
return the user to the appropriate field.
6. Close and save the macro.
7. Switch to the Form View
Discussion
In Access, a switchboard is a form that allows users of a database to get from one place
to another or perform several commands from a central location. If a database has a
switchboard, it is usually the first item the user sees when the database is opened. While
a simple database may have one switchboard, a database with many forms and reports
may have several switchboards.
Creating a switchboard should be one of the last things you do when creating a
database. You may want to consult with the people who use the database, or let them
use it without a switchboard for a while, so that you can get a better idea of what needs
to be automated. There are several ways to create a switchboard. You can use the
Database Wizard, the Switchboard Manager, or start with a blank form. When you use
the Database Wizard to create a database, the wizard automatically creates a
switchboard. You can make changes to this switchboard by editing it as you would any
other form.
You can also create a switchboard in Design view using a blank form. When you create
a form to be used as a switchboard, it should not be bound to a table or query. To ensure
that the switchboard does not look or work like a form, you need to set certain
properties, such as not displaying navigation buttons and scroll bars. Creating a
switchboard using a blank form requires that you add your own command buttons,
controls, and graphics, as well as set the desired form properties.
A switchboard
Procedures
1. Open the desired database.
2. Display the Forms object list.
3. Double-click the switchboard form to open it.
4. Select an option on the switchboard.
Discussion
Before creating the switchboard form, you should have an idea what needs to be
included. If you are going to use macros to initiate certain actions, you should create
them before you start creating the switchboard.
Because you do not want the switchboard to look like a typical form, you should set the
properties listed in the following table:
Property Setting
Default View Single Form
Record Selector No
Navigation Buttons No
Auto Center Yes
Scroll Bars Neither
Auto Resize Yes
You may also want to size the switchboard form so that it covers the entire screen. To
further enhance the switchboard form, you can change the background color and add
text and graphics.
Procedures
1. Open the desired database.
2. Display the Forms object list.
Discussion
Once you have created the switchboard form, you add controls, such as command
buttons, to it. As your database changes, you can modify the switchboard, as necessary.
To improve the appearance of your switchboard, you can add labels and graphics,
change object colors and fonts, and modify other form properties.
If a control performs a single function, such as opening a form or printing a report, and
the form or report already exists, you can add the control using the Control Wizards. If
the form or report has not been created, you can create the control without using the
Control Wizards. Then, after the form or report is created, you can assign an action to
the control and change any other properties, as desired.
When a control performs two or more functions, you should assign the control’s action
to a macro. As with single function controls, you can use the Control Wizard. This
method of assigning control actions to macros is the most common because many
switchboard controls perform two actions, such as opening a form and closing the
switchboard.
Procedures
1. Open the desired database.
2 Open the desired switchboard form in Design view.
3. Display the toolbox.
Discussion
You can set startup options for a database. Startup options control what appears when
the database opens. For example, you can choose to hide the Database window and the
status bar. You may also select a default form to appear automatically when the
Database window opens.
Switchboard forms are often specified in the startup options as the default form. This
option allows you to create a form with all the options a user needs and have it appear
automatically when the user opens the database.
Procedures
1. Open the desired database.
2. Close all open forms.
3. Select the Tools menu.
4. Select the Startup command.
5. Select the Display Form/Page list.
6. Select the switchboard form.
7. Select OK.
EXERCISE
USING SWITCHBOARDS
Task
Use switchboards.
1. Open Train36x.
2. Open the Training Switchboard form in Design view.
3. Change the Format properties of the form as shown in the following
table:
Property Setting
Default View Single Form
Scroll Bars Neither
Record Selectors No
Navigation No
Buttons
Auto Resize Yes
Auto Center Yes
17. Test the buttons on the switchboard. Close any open windows, as
necessary.
18. Close the database file.
Discussion
When you create a custom application, you might also want to create custom menus.
Custom menus allow you to limit the actions a user can perform. For example, you can
remove certain commands from the File menu, such as New and Rename to prevent
users from modifying the application database. You can also add a custom command
that initiates a macro.
Menus and command buttons reside on toolbars. Usually a toolbar contains only menus
or only buttons. However, you can display both on the same toolbar.
Once you have created a custom toolbar, you can link it to a form or a report, meaning
that it will automatically appear when you open or run the form or report.
Procedures
1. Open the desired database.
2. Select the View menu.
3. Point to the Toolbars command.
4. Select the Customize command.
5. Select the Toolbars tab.
6. Select the New button.
7. Type a descriptive name for the new toolbar.
8. Select OK.
9. Select Close.
Discussion
When the Customize dialog box opens, any toolbar can be displayed and edited. Menu
items are listed by category, each of which contains a group of related menu commands.
For instance, the Edit category, when selected, displays editing commands such as
Copy and Paste. You can quickly add or remove entire menu items or individual menu
commands to and from existing toolbars in Access. For example, you may wish to
remove the File menu to prevent users from performing any file operations. The
Customize dialog box includes built-in menus you can add to a toolbar. These built-in
menu items already include a group of commands.
Procedures
1. Open the desired database.
2. Display the desired toolbar.
3. Select the View menu.
4. Point to the Toolbars command.
5. Select the Customize command.
6. Select the Toolbars tab.
7. Click the option to the left of the toolbar you want to edit.
8. Select the Commands tab.
9. Select Built-in Menus from the Categories list box.
10. Select the desired built-in menu from the Commands list box.
11. Drag the built-in menu to the desired toolbar.
12. Close the Customize dialog box.
Discussion
A quick way to develop a custom toolbar is by adding built-in menus. Built-in menus
are menu items that already contain a group of commands. However, you may want to
create your own menu item to which you can assign a group of commands. Access
allows you to create a new menu item to which you can assign a name and add
commands that appear in a list when the menu is selected.
Procedures
1. Open the desired database.
2. Open the Customize dialog box.
3. Select the Commands tab.
4. Select New Menu from the Categories list box.
5. Select New Menu from the Commands list box.
6. Drag the New Menu menu to the desired toolbar.
7. Select the Modify Selection button in the Customize dialog box.
8. Drag to select the text in the Name box.
9. Type a descriptive name for the new menu item.
10. Press [Enter].
11. Close the Customize dialog box.
Discussion
You can add commands to a menu item when the Customize dialog box is open.
Related commands are grouped in categories. For instance, the File category contains
file handling commands, such as Open Database, Save, and Print. You may want to
add commonly used commands to a menu item if they are not already there. When you
add a command, a vertical or horizontal bar appears, indicating where the command
will be added.
Procedures
1. Open the desired database.
2. Open the Customize dialog box.
3. Select the Commands tab.
4. Select the desired category from the Categories list box.
5. Select the desired command from the Commands list box.
6. Drag the command to the menu name on the desired toolbar and then
place it in the desired location.
7. Close the Customize dialog box.
Discussion
Most of the commands available in the Customize dialog box already have an action
associated with them. For example, the Print command, when selected, performs the
action of printing the active object, such as a form or report. However, the Custom
command, which is included in the selection of available commands, has no action
associated with it when added to a menu item. You can assign a macro to this command
so that when it is selected, it performs the actions of that macro. You can also rename
the Custom command to provide a description of the actions that the command
performs.
Procedures
1. Open the desired database.
2. Open the Customize dialog box.
3. Select the Commands tab.
4. Select File from the Categories list box.
5. Select Custom from the Commands list box.
6. Drag the Custom command to the menu name on the desired toolbar
and then place it in the desired location.
7. Select the Modify Selection button in the Customize dialog box.
8. Drag to select the text in the Name box on the Modify Selection
menu.
9. Type a descriptive name for the command.
10. Select the Properties command on the Modify Selection menu.
11. Select the On Action list.
12. Select the macro you want to assign to the command.
13. Close the Customize dialog box.
Discussion
When you create a custom toolbar, it appears as a floating toolbar by default, meaning
that it appears as a small window that can be easily moved and closed. Toolbars can be
docked horizontally along the top or bottom of the Access window, or vertically along
either side of the window. This flexibility allow you to place the toolbar in the location
you prefer.
Procedures
1. Open the desired database.
2. Display the floating toolbar.
3. Drag the toolbar to the desired edge of the Access window.
Discussion
After you have created a custom toolbar, you can link it to a form or report. When the
form or report opens, the custom toolbar appears along with any default toolbars.
Procedures
1. Open the desired database.
2. Display the Forms or Reports object list.
3. Select the desired form or report.
Discussion
You can create separator bars on menus to group related commands. For example, the
File menu in Access has several separator bars that distinguish groups of file
operations, such as opening, closing, saving, and printing. You can add separator bars to
menus you have created to group related commands.
Procedures
1. Open the desired database.
2. Display the toolbar to which you want to add a separator bar.
3. Open the Customize dialog box.
4. Select the Commands tab.
5. Display the menu on the toolbar to which you want to add a
separator bar.
6. Select the command before which you want to insert a separator bar.
7. Select Modify Selection in the Customize dialog box.
8. Select the Begin a Group command.
Discussion
Shortcut menus appear when you right-click in an application. You can use shortcut
menus to select commonly used commands rather than having to locate the commands
in a menu. You can link a shortcut menu to a form or report, or you can have it appear
globally.
Procedures
1. Open the desired database.
2. Open the Customize dialog box.
3. Select the Toolbars tab.
4. Select the New button.
5. Type a descriptive name for the shortcut menu.
6. Select OK.
7. Select the Properties button.
8. Select the Type list.
9. Select Popup.
10. Select OK.
11. Select Close.
12. Double-click Shortcut Menus in the Toolbars list box.
13. Select the Custom menu on the Shortcut Menus toolbar.
14. Select the shortcut menu to which you want to add commands.
Discussion
After you have created a custom shortcut menu, you can link it to a form or report. If
the form is open in Form view or the report is open in Print Preview, the shortcut
menu appears when you right-click in the form or report.
Procedures
1. Open the desired database.
2. Display the Forms or Reports object list.
3. Select the desired form or report.
Discussion
You can add command buttons to a custom toolbar. Command buttons, when clicked,
perform an action, such as saving a file or opening a database object. Generally, the
action is depicted in a graphic on the button. For example, the Save button has a graphic
of a floppy disk on it. The Customize dialog box allows you to select command buttons
from several categories. You can create a toolbar that contains only command buttons,
or you can mix menu items with command buttons. The Commands list in the
Customize dialog box displays the text for the commands as well as the corresponding
buttons.
Procedures
1. Open the desired database.
2. Open the Customize dialog box.
3. Display the desired toolbar.
4. Select the Commands tab.
Discussion
When you add a button to a custom toolbar, Access displays the default button. When
you add an object to a custom toolbar, Access displays the default button for that type
of object. You can change the face of any button on any toolbar. Access includes a
button editor so that you can modify an existing button image or create your own.
If you do not want to use the available button images, you can
create your own graphic by selecting the Modify Selection
menu and then selecting the Edit Button Image command.
Procedures
1. Open the desired database.
2. Display the desired toolbar.
3. Open the Customize dialog box.
4. Select the command button you want to change.
5. Select Modify Selection in the Customize dialog box.
6. Point to the Change Button Image command.
7. Select the desired button image.
8. Close the Customize dialog box.
Discussion
You can delete a custom toolbar when you no longer need it. Deleting toolbars is a good
way to keep your desktop and the Customize dialog box free of clutter.
Procedures
1. Open the desired database.
2. Open the Customize dialog box.
3. Select the Toolbars tab.
4. Select the toolbar you want to delete in the Toolbars list box.
5. Select Delete.
6. Select OK.
7. Close the Customize dialog box.
EXERCISE
CREATING CUSTOM TOOLBARS
Task
Create a custom toolbar.
1. Open Train37x.
2. Close the switchboard.
3. Create a new toolbar named Form Operations.
4. Add the File built-in menu item to the toolbar.
5. Add a custom menu item to the right of the File menu on the toolbar.
Rename the menu Navigation. (Hint: Remember to select the New
Menu category.)
6. Add the following commands from the Records category to the
Navigation menu item: First, Previous, Next, Last, New Record,
and Delete Record.
7. Add a custom command to the Navigation menu item below the
previously created commands. Name the command Exit and assign
the Save/Close Payment Form macro in the On Action property
box to it.
8. Add a separator bar above the Exit command.
9. Add the View Report command button from the All Macros
category to the right of the Navigation menu. Change the button
image to an image of an eye (last row, fourth column).
10. Link the Form Operations toolbar to the Payment Form form.
Close and save the form.
11. Create a custom popup shortcut menu named Sorting. Add the Sort
Ascending and Sort Descending commands from the Records
category to the menu.
12. Link the Sorting shortcut menu to the Payment Form form. Close
and save the form.
13. Open the Payment Form form in Form view. Dock the Form
Operations toolbar below the already existing menu commands.
Test the new toolbar and shortcut menu.
Analyzing Tables
Access Security
Replicating Databases
Analyze a table
ANALYZING A TABLE
Discussion
When you create or analyze a table, you should look at its structure to determine the
efficiency of its design. If the same information appears in multiple records, the table
can probably be split into two related tables. Splitting a table is more efficient because
the tables are then smaller and, as a result, easier to manage. In addition, information
will only need to be entered one time. Smaller tables also reduce the chance of making
data entry errors.
If you feel that a table may need to be split, you can use the Table Analyzer Wizard to
analyze it for you and suggest which fields should be in each table. The Table Analyzer
Wizard can also create the correct table relationships.
Discussion
When the Table Analyzer Wizard splits a table, it creates the necessary relationships in
the resulting tables. These relationships allow data from all the tables to be used in
queries, forms, and reports.
Access provides two basic types of relationships: one-to-one and one-to-many. When a
table is split, a one-to-many relationship is usually created. This relationship allows one
record in the first table to be related to many records in the other related tables,
eliminating data duplication.
Discussion
The Table Analyzer Wizard looks at a table to determine if it contains duplicated
information. If the Table Analyzer Wizard determines that a table has a lot of duplicated
data, it splits the table, creating new tables and leaving the original table intact.
The Table Analyzer Wizard has seven pages. The first two pages are informational,
with the first page describing the problem of duplicate data in the table and the second
describing the solution. You can choose not to display these pages.
You then select the table you want to analyze. On subsequent pages, you indicate
whether you want the wizard to decide how to split the table or whether you want to do
it yourself. If you allow the wizard to split the table, the recommended tables and the
relationships between them appear. You can then move fields between tables or even
drag fields to create new tables. Each piece of information should be stored in only one
location, and each table should contain only data that refers to a single subject.
Once the fields have been put into the correct tables, you can set the primary keys. In
order to be related properly, each table must have a primary key, and the primary key
must be a field that uniquely identifies each record. Therefore, a primary key field
cannot contain duplicate data. Access will generate unique fields, if necessary.
On the last page, you can allow the Table Analyzer Wizard to create a query. The query
will be given the same name as the old table and the old table will be renamed. As a
result, any reports, forms, or queries that refer to the old table can still be used.
Procedures
1. Click the arrow on the Analyze button on the Database
toolbar.
2. Select the Analyze Table command.
3. Select Next >.
17. Click the Set Unique Identifier button at the top of the Table
Analyzer Wizard window.
18. Select Next >.
19. Select whether or not you want the Table Analyzer Wizard to create
a query for you.
20. Select Finish.
21. Close the Microsoft Access Help window, if necessary.
Discussion
The Performance Analyzer analyzes the efficiency of your database in order to optimize
its performance.
The Performance Analyzer window contains a page for each available object type in
Access, as well as a Current Database page and an All Object Types page. The
Current Database page allows you to analyze features that are not objects, such as
relationships. You can analyze a single object or multiple objects on different pages. If
you are analyzing different types of objects, the All Object Types page allows you to
view all database objects in one location.
The results of the performance analysis appear in the Analysis Results box. The results
are categorized as a Recommendation, Suggestion, or Idea. The Analysis Notes box
provides additional information about the selected result. You can use the Optimize
button to have Access perform the action suggested in a Recommendation or
Suggestion; you must manually perform the action for an Idea.
You can use the Select All button to select all the results in the
Analysis Results box.
Procedures
1. Click the arrow on the Analyze button on the Database
toolbar.
2. Select the Analyze Performance command.
3. Select the tab containing the objects you want to analyze.
4. Select the objects you want to optimize.
5. Select OK.
6. To view an explanation, click any result in the Analysis Results box.
7. Select Close.
EXERCISE
ANALYZING TABLES
Task
Use the Table Analyzer Wizard to analyze tables.
1. Open Train11x.
2. Open the Table Analyzer Wizard. Select Next as needed and then
select the Project List table. Select Next.
3. Allow the wizard to decide how to split the table.
4. Rename Table1 to Project and Table2 to Client.
5. Drag the State field from the Project field list below the City field
in the Client field list.
6. Set the Client ID field as the primary key in the Client table.
7. Do not have the Table Analyzer Wizard create a query.
8. Select Finish.
9. Close the Microsoft Access Help window. View the tables and then
close them and restore the Database window.
10. Analyze the performance of the Client and Payment tables. (Notice
that the analysis result does not fit the data; changing the Zip field to
a long integer field would not allow for zip codes with leading
zeroes, such as 08054.)
11. Close the Performance Analyzer.
12. Close the database file.
Import data
Export data
Convert files
Compact a database
Back up a database
Appendix II - Using Advanced Database Features Access 2003: Advanced
IMPORTING DATA
Discussion
You can import data from one or more external data sources. The external data source
can be another Access database, a database created in a different program (such as
dBASE or Excel), ASCII text, or an HTML data table.
When you import data from a spreadsheet, another type of database, or ASCII text, a
wizard opens to step you through the process. The format of the data in the external data
source does not change. You can use Access to add, edit, or delete the data.
If the external data source is an Access database, you can also import database objects
such as queries, reports, and forms. This option allows you to copy a query from one
database to another and modify it as necessary, rather than creating a new one. In
addition, you can easily copy standard reports and forms between databases.
If the table you import has a lookup field, you should also
import the source of the information for the lookup field.
Procedures
1. Select the File menu.
2. Point to the Get External Data command.
3. Select the Import command.
4. Select the Files of type list.
5. Select the desired file type.
6. Select the Look in list.
7. Select the drive where the source data is stored.
8. Open the folder where the source data is stored.
9. Select the file containing the source data.
10. Select Import.
11. Select the appropriate data format.
12. Select Next.
13. Select the appropriate delimiter.
14. Select the First Row Contains Field Names option, if applicable.
15. Select Next.
16. Indicate whether the data is to be stored in a new or existing table,
select any additional options, and select Next.
17. Modify field options as desired, and select Next.
18. Select the desired primary key option.
19. Select additional options as desired, and select Next.
20. Enter the desired table name.
21. Select Finish.
22. Select OK.
Discussion
You can link to an external data source, such as another Access database or a database
created in a different program (e.g., dBASE or Excel). You can also link to HTML data
tables on a network server or on the Internet.
When you link to an external data source, the format of the data in the data source does
not change, although you can use Access to add, edit, or delete the data.
A linked table displays a special icon in the Database window. A table linked to another
Access database has an arrow to the left of the icon. A table linked to a source created
in a different program displays an arrow and the initials of the source program (e.g., Px
for Paradox).
Linking tables is useful when you want to share data on a network. If you link to a table
on a network, the link ensures that the data you are viewing is always the latest
available.
When you delete a linked table, you are deleting the icon and
the link to the source table, not the source table itself.
You can also open the Link dialog box by right-clicking in the
Database window and selecting the Link Tables command.
Procedures
1. Select the File menu.
2. Point to the Get External Data command.
3. Select the Link Tables command.
4. Select the Look in list.
5. Select the drive where the source data is stored.
6. Open the folder where the source data is stored.
7. Select the file containing the source data.
8. Select Link.
9. Select the table containing the source data.
10. Select OK.
Discussion
You can use the Linked Table Manager to view, refresh, or correct the file name and/or
path of a linked table. If the structure of a linked table changes, for example, you can
use the Linked Table Manager to refresh the link. In addition, if a linked table is moved
to a different location, you can use the Linked Table Manager to correct the path and
reestablish the link.
If you change the name of a table after it has been linked, the
Linked Table Manager will not be able to refresh the links. In
this case, you must delete the link and create a new one.
Procedures
1. Select the Tools menu.
2. Point to the Database Utilities command.
3. Select the Linked Table Manager command.
4. Select the linked table you want to update.
5. Select OK.
6. Select the Look in list.
7. Select the drive where the file is stored.
8. Open the folder where the file is stored.
9. Select the name of the file containing the linked table.
10. Select Open.
11. Select OK.
12. Select Close.
EXPORTING DATA
Discussion
You can export data and database objects to a variety of supported databases, programs,
and file formats. For example, you can export data to another program (such as dBASE
or Excel), to ASCII text, or to an HTML data table. You can also export most database
objects from a Microsoft Access database to another Access database. The process of
exporting data and database objects is very similar in functionality to copying and
pasting.
The following table lists some of the data formats to which you can export:
Procedures
1. Select the database object you want to export.
2. Select the File menu.
3. Select the Export command.
4. Select the Look in list.
5. Select the drive where the file to which you want to export is stored.
6. Open the folder where the desired file is stored.
7. Select the desired file.
8. Select Export.
9. Enter the desired name for the database object.
10. Select OK.
CONVERTING FILES
Discussion
Access 2003 uses the Access 2000 file format as its default. As a result, you can work
with and modify Access 2000 files in Access 2003 without having to convert them. In
addition, all databases created in Access 2003 will automatically have the Access 2000
file format. It is not necessary to convert Access 2000 files to the 2003 format, unless
you plan on using any of Access 2003’s more complex design features, such as saving
your database as an MDE file (used for databases containing Microsoft Visual Basic
code).
If you decide to convert your Access 2000 files to the 2003 format, it is important to
remember that, once a file has been converted to the Access 2003 file format, you can
no longer open it in Access 2000. This is important if you are working in an
environment where not everyone has upgraded to Access 2003.
If you are working with a Microsoft Access database created in Access 2.0 or later, you
can convert it to the Access 2000 or Access 2003 file format as desired. Whenever you
open a database created in an earlier version of Access, you are given an opportunity to
convert the database.
You should always make a copy of your Microsoft Access database before you convert
it. This will ensure that your original file is still intact, should you encounter a problem
during the conversion process.
Access 2003 includes a Conversion Error Logging feature. If an error occurs when
converting a database from Access 97, 2000 or 2002 to Access 2003, the Conversion
Error Logging feature creates a table that lists information about each error.
Procedures
1. Click the Open button on the Standard toolbar.
2. Select the Look in list.
3. Select the drive where the file you want to convert is located.
4. Open the folder in which the desired file is located.
Discussion
It is a good idea to document your database structure and relationships. The
Documenter feature in Access allows you to view, print, and save the design
characteristics of database objects. You can view and print such information as the
properties associated with tables, queries, forms, and reports. This type of information
is very useful for deciding what changes you want to make or when you have to
maintain a database that was developed by someone else.
Although the Relationship window is a good way to view table relationships, as well as
join lines and types, you cannot print from it. The Documenter feature allows you to
print the relationships between tables in your database. The relationship report that the
Documenter feature produces provides information on related tables, their attributes,
and the type of relationship, which in turn, provides you with all the information you
need to analyze your database table relationships.
You can also open the Documenter dialog box by selecting the
arrow on the Analyze button on the Database toolbar and the
Documenter command.
Procedures
1. Select the Tools menu.
2. Point to the Analyze command.
3. Select the Documenter command.
COMPACTING A DATABASE
Discussion
When you delete tables and other objects in a database, the database size on the disk
does not necessarily decrease. Access provides a utility that compacts (defragments) the
database, thereby releasing storage space.
You can create a copy of the original database by saving the compacted database with a
different name or to a different location. Although you can compact the current database
while it is open, the database must be closed in order to make a copy.
Procedures
1. Open the database you want to compact.
2. Select the Tools menu.
3. Point to the Database Utilities command.
4. Select the Compact and Repair Database command.
Discussion
The Name AutoCorrect feature automatically fixes inconsistencies that can occur
when you rename tables, forms, reports, queries, fields, or other controls in an Access
database.
The Name AutoCorrect options must be enabled, however. The Track name
AutoCorrect info option saves information about changes, but does not automatically
repair the inconsistencies. When the Perform name AutoCorrect option is enabled,
Access automatically corrects any differences between related objects. Furthermore, if
you enable both options, you can also enable the Log name AutoCorrect changes
option, which creates a table named Name AutoCorrect Log that documents changes.
Name AutoCorrect is enabled by default for new Access 2002 and 2003 databases.
However, if you are working in a converted database, you must manually enable it.
Procedures
1. Select the Tools menu.
2. Select the Options command.
3. Select the General tab.
4. Select the Track name AutoCorrect info option.
5. Select additional options under Name AutoCorrect as desired.
6. Select OK.
BACKING UP A DATABASE
Discussion
It is important to backup your database on a regular basis. Most companies have a
backup process to ensure that all data is saved at least once a day; consequently, all
databases shared on a company network server are backed up daily as well.
Your database may be saved to the hard drive of a personal computer, however, most
databases are too large to fit on a floppy disk. In this case, you should back up your
hard drive regularly by saving it to another drive or to removable media (a tape or CD,
for example). Backing up your hard drive ensures that all data, queries, forms, and
reports in your database are saved. As a result, you can recover your database if
something were to happen to it.
If neither of the above options are available, you can export individual components
(such as tables, queries, forms, etc.) to a floppy disk. In addition, you can save data as
ASCII text or as Excel tables; you cannot, however, save queries, forms, or reports in
this manner.
EXERCISE
USING ADVANCED DATABASE FEATURES
Task
Use advanced database features.
Discussion
You can export database records from a database file in Access to a workbook in Excel.
The Access data source can be a table, query, form, report, view, or macro. When you
export data from a database, Access creates a workbook file in Excel with the data from
the database. Any field names from the data source appear in the first row of the
workbook.
When you export to Excel, you can choose to export to an existing workbook, or you
can indicate that you want to export to a new workbook by providing a new name in the
File name text box in the Export dialog box. You can also choose to save the fonts,
field widths, and data displayed from Lookup fields in your Access datasheet by
selecting the Save formatted option before exporting.
Exporting data to Excel is a useful way to display and work with data using the
capabilities of Excel. For example, you could transfer a table containing investment
portfolio information to Excel in order to perform calculations on investment
performance.
Procedures
1. Open the desired database.
2. Display the desired object list.
3. Select the data source you want to export.
4. Select the File menu.
5. Select the Export command.
6. Select the Save as type list.
Discussion
You can drag and drop data from Access into Excel. For example, you can drag and
drop tables and queries from Access and place them in a workbook in Excel. The drag
and drop method is very useful when you are building information in an Excel
workbook and want to use data from an Access database file in the workbook. When
you drag and drop data from Access to Excel, it is best to display the two program
windows side by side on the desktop.
When you drag and drop data to Excel, any formatting that has been applied to the data
in Access will be lost in Excel. However, the field headings in Access are preserved in
Excel.
You can also drag and drop into Excel by dragging the data
from Access to the program button on the taskbar until the
Excel window appears and then dragging the data into the
desired workbook.
Procedures
1. Open Microsoft Excel.
2. Open the desired workbook.
3. Open the desired database in Access.
4. Display the desired object list.
5. Select the Access data source you want to drag into Excel.
6. Drag the data source to the desired location in the Excel workbook.
Discussion
You can use the Office Links feature to export a database data source from an Access
database to an Excel workbook. The Access data source can be a table, query, form, or
report. When you export data from a database, Access creates a workbook file in Excel
with the data from the database. Any field names from the data source appear in the first
row of the workbook.
When you export to Excel using the Office Links feature, a new workbook is created.
The workbook is automatically named the same as the data source. Exporting data using
this method is a quick way to create a workbook that you can share with others who
may not have Access installed on their computers.
You can also use the Tools menu to access the commands on
the Office Links submenu.
Procedures
1. Open the desired database.
2. Display the desired object list.
3. Select the data source you want to export.
Discussion
You can use the Office Links feature to export a database data source from an Access
database to create a Word document. The Access data source can be a table, query,
form, or report. When you export data from a database, Access creates a document in
Word with the data from the database. When a table, query, or form is exported to
Word, the data is inserted into a table. Any field names from the data source appear in
the first row of the table and are shaded. Reports appear in Word as standard documents
with tabs used to separate the data.
When you export to Word using the Office Links feature, a new document is created in
the .rtf (rich text format) file format. The document is automatically named the same as
the data source. Exporting data using this method is a quick way to create a document
that you can share with others who may not have Access installed on their computers.
In addition, it enables you to use the formatting features found in Word.
You can also use the Tools menu to access the commands on
the Office Links submenu.
Procedures
1. Open the desired database.
2. Display the desired object list.
3. Select the data source you want to export.
EXERCISE
EXPORTING DATA TO EXCEL AND W ORD
Task
Export Access data into Excel and Word.
1. Open Train38x.
2. Export the Invoice table as an Excel workbook named Invoice.
3. Open Excel and the Invoice workbook that was just created.
4. Insert a new worksheet into the workbook and name it Payment.
5. Tile the Access and Excel windows.
6. Drag the Payment table in Access to cell A1 of the Payment
worksheet in Excel.
7. Save and close the workbook and Excel.
8. Create a new Excel workbook using the Office Links feature and the
data in the New Payment Form form.
9. Close the workbook and Excel.
10. Create a new Word document using the Office Links feature and the
data in the Projects by Client report.
11. Save the report as a Word document and close Word.
12. Close the database file.
Discussion
Crosstab queries are used to group and summarize information in a spreadsheet format.
Crosstab queries make it easier to read and analyze selected data. The Crosstab Query
Wizard provides a step by step process to help you quickly create a crosstab query,
allowing you to enter information about the tables and fields you want to add to your
query.
You must have three fields in a crosstab query. The values in the first field appear as
row headings in the resultant spreadsheet, the values in the second field appear as
column headings, and the calculation is performed on the values in the third field.
A crosstab query can display, for example, products sold (row headings) by sales
representative (column headings); the number of products sold by each sales
representative would appear at the intersection of the corresponding row and column.
You should select the field with the fewest values for the
column headings; your resultant spreadsheet will have a less
cluttered appearance.
Procedures
1. Display the Queries object list.
Discussion
You can use a Find Duplicates Query Wizard to find duplicate records in a table. For
instance, there may be identical records stored in a table, when only one record is
necessary. The Find Duplicates Query Wizard will find the duplicate records so that
you can delete them from the table.
Procedures
1. Display the Queries object list.
Discussion
The Find Unmatched Query Wizard helps you manage data in related tables. This
wizard finds records that are “orphans,” meaning that they have no corresponding
records in the related table. Suppose, for example, that you have deleted the records of
inactive customers from a Customers table. Two years later, one of those customers
places an order, which is entered into the Orders table. Because the Customers and
Orders tables are related, however, having an order without the corresponding
customer data will cause problems. You can use the Find Unmatched Query Wizard to
correct the problem by updating the Customers table.
Procedures
1. Display the Queries object list.
EXERCISE
USING ADVANCED QUERY W IZARDS
Task
Use advanced query wizards.
1. Open Train17x.
2. Create a crosstab query from the existing Sales by Rep query. Use
the Client ID field for the row headings and the Sales Rep field for
the column headings. Have the calculated value be the sum of the
Total Sales field.
3. Name the query Total Sales by Sales Rep, and select the option to
view the query. After you have viewed the recordset, close the query.
Create a chart
CREATING A CHART
Discussion
With Access, you can enhance forms and reports by adding graphs, pictures, and other
objects.
The Chart Wizard assists you in creating charts quickly. Charts allow you to represent
information in a database graphically. Charts can be either two or three dimensional,
depending on the type and amount of data you need to represent. The message a chart
conveys should be clear, and you should avoid providing too much information.
Access includes a number of charts from which you can choose. The Chart Wizard
provides a description of each chart type to assist you in selecting the appropriate type
for the data you are using. For example, a bar chart best represents comparisons of like
data, such as quarterly profits, and a pie chart best represents parts of a whole, such as
each salesperson’s contribution to overall sales. Many of the available charts are similar
in the way they represent data, but differ aesthetically. For instance, you can replace the
bars in a bar chart with cylinders or cones to provide a more dramatic effect.
Depending on the type of chart selected, you may have a series field, data field, and an
axis field associated with the chart. After selecting the chart type and advancing the
wizard, Access will automatically insert fields into the series, data, and axis boxes from
those available. You may change the contents of any of these boxes by dragging the
field buttons in and out of the boxes.
A pie chart
Procedures
1. Open the desired database.
2. Display the Forms or Reports object list in the Database window.
Discussion
Access considers a chart to be an unbound object, meaning that you can manipulate the
chart as you would any other object. For example, a chart can be added to a form or
report to improve its usefulness and appearance.
You can also paste the chart object from the Clipboard task
pane.
Procedures
1. Open the desired database.
2. Open the desired form or report in Design view.
3. Select the chart object.
4. Right-click the chart object.
5. Select the Copy command.
6. Close the form or report.
7. Select the Forms or Reports object list.
8. Select the desired form or report.
11. Click the Paste button on the Form Design or Report Design
toolbar.
Discussion
You may want to make changes to a chart to improve its appearance or emphasize
aspects of the chart. You can change the chart type; the text of the chart, such as the title
and the data labels; the colors used in the chart; and the actual data the chart displays.
When editing a chart, Access displays an editing toolbar to allow you to quickly make
any changes.
You use Microsoft Graph to modify charts in Access. The Microsoft Graph window
consists of two elements. The first element is the Datasheet window. The datasheet is a
worksheet of the data that is used to create the chart. Any changes to the data
comprising the chart are made in the datasheet. The second element is the Chart
window, which displays the graphical representation of the data. You can make a chart
easier to read by revising its appearance, such as modifying the layout or formatting the
title.
The Datasheet window consists of rows and columns in which you can enter labels and
numbers. The rows are identified with numbers and the columns are identified with
letters. The intersection of a row and column identifies the cell with a cell address, such
as A1, CA10, DE100, etc. When you make a change in the Datasheet window, the
changes are reflected in the Chart window.
The major parts of the Datasheet window are listed in the following table:
Part Description
Row headings The identifiers to the left of the first column in the
datasheet.
Column headings The identifiers above the top row of the datasheet.
Cell The intersection of a column and row.
Data point A single cell value.
Data series A row or column of data.
Series names Names used to identify each row or column of
data that appear in the legend of the Chart
window.
The major parts of the Chart window are listed in the following table:
Part Description
Chart The area inside the Chart window.
Data marker An item in a chart that marks a single data point
or value, such as a bar, a shape, or a symbol.
Part Description
Data series A group of data points. A chart can have one or
more data series.
Attached text Describes the data or items in a chart and is linked
to a chart item, such as a data marker. Attached
text moves with the item to which it is linked, and
cannot be moved independently.
Unattached text Describes the data or items in a chart. Because it
is not linked, you can move unattached text
anywhere on a chart.
Gridlines Optional lines that make it easier to view the data
values.
Axes Lines that serve as a major reference point for
plotting data in charts. Usually, categories of data
are plotted along the horizontal (x) axis and data
values are plotted along the vertical (y) axis.
Procedures
1. Open the database.
2. Open the desired form or report in Design view.
3. Select the chart object you want to edit.
Discussion
After creating a chart, you may decide to display the data more effectively with another
type of chart. You can change the chart type in the Microsoft Graph window. Access
includes a number of chart types from which you can choose.
You can also choose from a number of available chart sub-types. An example of a chart
sub-type is a pie chart that is “exploded,” meaning the wedges of the pie are pulled out
from the center.
You can also open the Chart Type dialog box by right-clicking
a chart and then selecting the Chart Type command.
Procedures
1. Open the desired database.
2. Open the desired form or report in Design view.
3. Open the Microsoft Graph window.
4. Select the Chart menu.
5. Select the Chart Type command.
6. Select the Standard Types tab.
7. Select the desired chart type from the Chart type list box.
8. Select the desired chart sub-type.
9. Click and hold the Press and Hold to View Sample button.
10. Release the mouse button.
11. Select OK.
Discussion
You can change the title of a chart in the Microsoft Graph window. If the data in the
chart has changed, you can revise the title to provide a better description of the chart’s
contents.
Procedures
1. Open the desired database.
2. Open the desired form or report in Design view.
3. Open the Microsoft Graph window.
4. Select the chart title.
5. Select the chart title text.
6. Type the new title for the chart.
7. Click in a blank area of the chart to deselect the chart title.
Discussion
You can format the chart title in the Microsoft Graph window. You can change the
pattern, font, and alignment of the chart title. The pattern of the chart title controls the
type of border around the title, if any, and the background color of the title. The font
controls the appearance of the chart title text, such as font type, style, and size. The
alignment of the chart title controls where the title text appears relative to the chart, as
well as the orientation of the title text.
You can also open the Format Chart Title dialog box by right-
clicking the chart title and then selecting the Format Chart
Title command.
Procedures
1. Open the desired database.
2. Open the desired form or report in Design view.
3. Open the Microsoft Graph window
4. Select the chart title.
5. Select the Format menu.
6. Select the Selected Chart Title command.
7. Select the tab for the desired type of formatting changes.
8. Select the desired format.
9. Select OK.
Discussion
You can add data labels to a chart in the Microsoft Graph window. These labels identify
the data displayed in the chart. They differ from the legend in that they are placed on the
pieces of the chart, rather than in a key beside it. Data labels can display amounts and
percentages from the chart data. You can use data labels to present a more detailed and
effective chart.
You can also open the Chart Options dialog box by right-
clicking the chart and then selecting the Chart Options
command.
Procedures
1. Open the desired database.
2. Open the desired form or report in Design view.
3. Open the Microsoft Graph window.
4. Select the chart plot area.
5. Select the Chart menu.
6. Select the Chart Options command.
7. Select the Data Labels tab.
8. Select the desired data labels option.
9. Select OK.
EXERCISE
USING CHARTS
Task
Use a chart.
1. Open Train27x.
2. Display the Reports object list in the Database window.
3. Using the Chart Wizard, select the Sales table, and include the Cost
and Sales Rep fields to create a Bar Chart (second row, first
column). Accept the default layout and title for the chart and select
not to display a legend. Select to open the report with the chart
displayed on it.
4. Switch to Design view. View the Sales chart in the Microsoft Graph
window. (Hint: When you display the chart in the Microsoft Graph
window, the data that appears is sample data. It is not representative
of the actual data that will appear in the final chart.)
5. Change the chart type to Column. Select the Clustered Column
sub-type, if necessary.
6. Change the chart title to Sales Reps.
7. Apply the Bold Italic style and a 12 point font size to the chart title.
8. Add data labels that show the actual values represented by the chart.
9. Size and position the chart as necessary to view the values.
10. Preview the report.
Encrypt a database
Discussion
Access 2003 supports the use of hypertext within the application. Hypertext, or
hyperlinks, are strings of text that declare an address or a path to a document. Hypertext
is active in that, if you click it, your PC and/or modem lead you to the document.
Hyperlinks provide an electronic path to documents in much the same way as your
home address provides a path for the mail you receive. For example, by reading the
address, the postal service knows to first go to Pennsylvania, then to Pittsburgh, then to
Forbes Avenue, and then to house number 2250.
Hyperlinks can be a URL address or a UNC address. The URL (Uniform Resource
Locator) is the address of a resource, or file, available on the Internet or your intranet.
The URL contains the protocol of the resource (e.g. http:// or ftp://), the domain name
for the resource, and the hierarchical name for the file (address). For example, a page on
the internet may be at the URL http://www.globalknowlege.com/terms/url.shtml. The
beginning part, http:// provides the protocol, the next part www.globalknowledge.com
is the domain, the main domain is globalknowledge, while www is a pointer to a
computer or a resource. The rest, /terms/url.shtml is the pointer to the specific file on
that server. Domain extensions identify the source; .com for companies, .org for
organizations, .gov for government, and .edu for educational institutions.
Discussion
You can add hyperlinks to tables in Design view by adding a field name and identifying
it as a hyperlink data type. You can then add hyperlinks to the appropriate column in
Datasheet view, allowing you to jump to objects in the same database, in another
database, in other Microsoft office documents, on the internet, or on an intranet.
Procedures
1. Open the desired database.
2. Open the desired table in Design view.
3. Select the first blank row in the Field Name column.
4. Type the desired field name.
5. Press [Tab].
6. Select the Data Type list.
7. Select the Hyperlink data type.
Discussion
You can insert a hyperlink into a field in a table or form. However, the field data type
must be designated as Hyperlink. The default settings display a new hyperlink in blue
underlined text and a followed hyperlink (one that has been used) in purple underlined
text. When you click the label, the hyperlink path is followed to the specified location.
The document at the end of the path can be a web page for company headquarters in
Los Angeles, another form or report in the current database, or anywhere in between.
For example, in the header of an Annual Sales Report, you can insert hyperlink labels
that, when activated, open related reports, such as a Quarterly Sales Report for that year.
Another example is to create a hyperlink label for a Product field on a form that jumps
to a listing of products on your supplier’s web page.
Hyperlink labels in forms or reports must contain a viable path, but the path itself does
not need to be displayed on the label. As with hyperlink fields, you can display a label
with descriptive text rather than the actual path.
When you point to a hyperlink, the mouse pointer changes into a hand pointing upward,
signifying that one mouse click activates the hyperlink.
You can type hyperlink text directly into a field. You can also
type it directly into the Insert Hyperlink dialog box, which is
opened by selecting the Insert menu and then selecting the
Hyperlink command when the insertion point is located in a
hyperlink column.
Procedures
1. Open the desired database.
2. Open the desired table in Datasheet view.
3. Select the desired row in the hyperlink column.
Discussion
You may occasionally have to edit your hyperlinks. Changes in web addresses are
common, and any file location changes on your PC or server need to be reflected with
an updated hyperlink. You can edit the hyperlink text or replace it with a new location.
When you edit most text in Access, you simply click or double-click the text and then
make the necessary changes. By design, hyperlinks are activated when clicked and,
therefore, must be edited differently.
Procedures
1. Open the desired database.
2. Open the desired table or form in Datasheet view.
3. Point to the hyperlink you want to edit.
4. Right-click the hyperlink you want to edit.
5. Point to the Hyperlink command.
6. Select the Edit Hyperlink command.
7. Double-click the desired object type.
8. Select the new object to which you want to link.
9. Select OK.
Discussion
If a hyperlink becomes invalid, or is no longer of any use, it can be deleted. As with
editing a hyperlink, you cannot simply double-click a hyperlink to select it.
Procedures
1. Open the desired database.
2. Open the desired table or form in Datasheet view.
3. Point to the hyperlink you want to delete.
4. Right-click the hyperlink you want to delete.
5. Point to the Hyperlink command.
6. Select the Edit Hyperlink command.
7. Select the Remove Link button.
Discussion
Among the available toolbars in Access is the Web toolbar. The Web toolbar
automatically appears when you activate a hyperlink. This toolbar is very similar to
toolbars used with web browsers. The Web toolbar enables you to easily navigate
through documents, whether on your hard drive or on the Internet. The features on the
Web toolbar include a display of the current address, forward and back buttons, and a
Favorites list that can include commonly used hyperlink addresses. The same
procedure is used to both display and hide the Web toolbar.
Procedures
1. Open the desired database.
2. Open the desired table or form in Datasheet view.
3. Select the View menu.
4. Point to the Toolbars command.
5. Select the Web command.
Discussion
Data access pages are web pages that appear in a browser which may be used to add,
edit, view, or analyze data in an existing Access or Microsoft SQL Server database.
These pages are connected directly to the database. Each page is a separate file that is
stored outside Access; however, Access automatically adds a shortcut to the file in the
Database window.
Creating data access pages is similar to creating forms and reports in that you use the
field list, toolbox, controls, etc. when creating and editing a page. In addition, you can
create data access pages from scratch in Design view or by using a wizard. However,
there are some differences that you need to keep in mind.
When you create data access pages in Design view, you can either drag individual fields
from the Field List task pane to the page, or add all fields from a specific table or
query. If you choose to add all fields from a table or query, you can choose a layout,
such as Columnar, Tabular, PivotTable, PivotChart, or Office Spreadsheet. When
you select Columnar, Tabular, or Office Spreadsheet, the fields are automatically
added to the data access page in accordance with the selected layout. With the
PivotTable layout, the data is displayed in Datasheet view where each column can be
filtered, if desired. PivotChart layout requires you to add the desired fields to the chart.
When creating a page for entering and editing data, you should use individual toolbox
controls such as text boxes, option buttons, etc. Controls should be placed in the body
or in a section. You can only group on one record source. You should also ensure that
the Data Page Size property in the Sorting and Grouping window is set to 1. You can
use the Office Spreadsheet tool in the toolbox if you want to perform calculations on
fields in a record.
If you want to analyze data, you should use the Office PivotTable tool in the toolbox,
since it allows you to reorganize data in different ways. When using the Office
PivotTable tool, you place the PivotTable in either the body or a section of the page.
When using the PivotTable tool on a grouped data access page, you place the
PivotTable and bound controls in a section and make sure that the PivotTable is in the
lowest group level. If the PivotTable is the only control in a section, you can delete or
hide the navigation section from the group level in which the PivotTable is located. You
should also ensure that the Data Page Size property in the Sorting and Grouping
window is set to 1.
When a user views the data access page in a browser, he or she is viewing his or her
own copy of the page. Therefore, any filtering, sorting, and other changes that are made
which affect what appears only affect that user’s copy of the data access page.
However, since the pages are connected directly to the database, any changes that the
user makes to the data will affect the data in the database.
If you created a Data Access Page using a local Access database and want to share it
with other users, you will need to move or copy the database to a network location and
then change the connection path location on the Connection page of the Data Link
Properties dialog box. The Data Link Properties dialog box is accessed by selecting the
Page connection properties button on the task pane.
Procedures
1. Open the desired database.
2. Display the Pages objects list.
8. Select the desired table or query from the Field List task pane.
Discussion
You can group records on data access pages. Grouping records on a data access page is
similar to grouping records in a report. Grouping records allows you to create a
structure that groups records from general categories to specific details. Grouped data
access pages are bound to the database so that they always display the current database
data. These pages also allow you to filter and sort data.
You can create a group data access page from scratch very much the same way you
would create a group report using the Sorting and Grouping window. Another way is to
use the Page Wizard. As you step through the wizard, it will prompt you for grouping
levels and sort orders.
Procedures
1. Open the desired database.
2. Display the Pages objects list.
5. Select the Choose the table or query where the object’s data
comes from list.
6. Select the desired table or query.
7. Select OK.
8. Select the fields you want to appear on your page from the Available
Fields list box.
9. Select Next.
10. Select the field(s) for the desired grouping level(s).
11. Select Add.
12. Select Next.
13. Select the 1 sort field list.
14. Select the desired field.
15. Select Next.
16. Enter the title for the page.
17. Select Finish.
Discussion
Office PivotTables allow you to summarize large amounts of data quickly. The Office
PivotTable tool in the toolbox, provides control and flexibility in creating PivotTables.
When using the Office PivotTable tool, you place the PivotTable in either the body or
a section of the page. Each drop area of the PivotTable workspace displays help text,
such as Drop Row Fields Here. When you first create a PivotTable, the Drop Totals
or Detail Fields Here area displays the text No Details. As you begin adding fields to
the PivotTable, the Drop Totals or Detail Fields Here help text is displayed.
The fields of a PivotTable can be laid out directly in the PivotTable workspace. The
Field List task pane displays the fields available in the source data (table or query)
previously selected. You lay out the PivotTable by dragging the fields directly into the
PivotTable workspace in the desired drop area.
If you would like to arrange the data by displaying the shipping date at the beginning of
each row you would drag the Shipping Date field to the Drop Row Fields Here area
of the workspace. Likewise, if you want to display the shipping method at the top of
each column, you would drag the Shipping Method button to the Drop Column Fields
Here area of the workspace.
The data field area contains the fields that are calculated. Therefore, they are usually,
but not limited to, numerical fields. For the Shipping Date by Shipping Method
PivotTable, you may want to summarize the data in the Shipping Cost field; in other
words, report the total shipping cost per shipping method by shipping date.
Filter fields are often used with large databases to filter information. They can break a
large portion of information down into smaller, more manageable sections. For
example, you may want to view shipping information for a particular sales
representative. You would accomplish this by adding the Sales Rep field to the Drop
Filter Fields Here area.
Once the appropriate fields have been added to the drop areas, you can move or delete
fields as desired.
Procedures
1. Open the desired database.
2. Display the Pages objects list.
12. To add a row field, drag the desired field from the Field List task
pane to the Drop Row Fields Here area.
13. To add a column field, drag the desired field from the Field List task
pane to the Drop Column Fields Here area.
14. To add a data field, drag the desired field from the Field List task
pane to the Drop Totals or Detail Fields Here area.
15. To add a filter field, drag the desired field from the Field List task
pane to the Drop Filter Fields Here area.
ENCRYPTING A DATABASE
Discussion
You can encrypt an Access database to protect it from unauthorized use. Ideally, it is
better practice to encrypt a secured database, as any user can open and work with
objects in a database where no security measures or permissions have been defined.
When you encrypt a database, Access compresses it, and it becomes unreadable by
utility programs or word processors. Decrypting a database removes the encryption.
In order to encrypt or decrypt a database, you must be the owner of the database. If you
are encrypting or decrypting a secured database, you must be part of the system
administrators group and be granted appropriate permissions for the database. If you
attempt to encrypt or decrypt a database that you did not create or do not have adequate
permission to, an error message box appears.
Procedures
1. Open the desired database.
2. Select the Tools menu.
3. Point to the Security command.
4. Select the Encrypt/Decrypt Database command.
5. Type a name for the encrypted database.
6. Select the Save in list.
7. Select the drive where you want to store the file.
8. Select the folder where you want to store the file.
9. Select Save.
Discussion
You can assign a password to a database so that only those users who know the
password can open or make changes to the database. Assigning a password protects the
database, not the database objects from unauthorized users. Database objects are
protected when user-level security is established.
Passwords are case-sensitive and can be up to 20 characters. They can contain any
combination of letters, numbers, symbols, and spaces, excluding the characters " \ [ ] : |
< > + = ; , . ? * , leading spaces, and ASCII 10-31 control characters.
A database must be open for exclusive use in order to assign or remove a password.
After a password has been assigned, you are prompted for the password each time you
open the database.
Procedures
1. Click the Open button on the Database toolbar.
2. Select the Look in list.
3. Select the drive where the database you want to open is located.
4. Open the folder in which the database you want to open is located.
5. Select the name of the database you want to open.
6. Select the Open list.
7. Select the Open Exclusive command.
Discussion
If a password is no longer necessary, you can remove it from the database. You can then
open the database at any time without a password.
Procedures
1. Select the Tools menu.
2. Point to the Security command.
3. Select the Unset Database Password command.
4. Type the desired password.
5. Select OK.
EXERCISE
USING ACCESS AND THE INTERNET
Task
Use Access and the Internet.
1. Open Train33x.
2. Create a field called Linked to with a Hyperlink data type in the
Sales table.
3. Insert a hyperlink in the Sales table to the Payment Form form.
4. Click the hyperlink text to display the Payment Form form. Close
the form.
5. Edit the hyperlink so that it opens the Client Information Form
form. Expand the Linked to column as necessary.
11. Create a grouped data access page using the Page Wizard based on
the Invoice table. Add all the fields, group by Client ID, and sort by
Due Date. Add the title Grouped by Due Date and open the page in
Design view.
12. Switch to Page view. Use the navigation buttons to view the data
grouped by Client ID. Click the plus sign (+) to expand the group.
13. Save the new data access page as Grouped Invoice Information,
click OK to close the connection message box, and then close the
page.
14. Create a PivotTable in a new data access page in Design view based
on the Project table. Resize the PivotTable as desired.
15. Drag the following fields to the designated drop area:
16. Use the Filter list to display information for the Abbott and Gains
clients. Then, select All from the Filter list to display all client
information.
17. Save the page as Course PivotTable, select OK to close the
connection message box, and then close the page.
18. Encrypt the Train33x database, naming it Trainenc. Close the
database.
19. Decrypt the Trainenc database, naming it Traindec.
20. Open Train33x exclusively (Hint: Use the Open Exclusive option
from the Open dialog box.).
21. Assign the password class to the database. Close Train33x.
22. Open Train33x exclusively. Notice that you must enter the
password. Remove the password.
23. Close the database file.
APPENDIX VIII -
REPLICATING DATABASES
Replicate a database
REPLICATING A DATABASE
Discussion
Replicating a database allows you to share a database. It is useful to share a database
across a network or create copies for remote users, such as a mobile sales force. While
you could copy the file, there is an advantage to replication. Any changes to data made
in a replica can be updated in the original database and other replicas through
synchronization. Additionally, any design changes to the original database are
distributed among the replicas.
You can create a single replica or multiple replicas. You may want to create a single
replica if you want to place the database on a remote computer, such as a laptop, or if
you want to create a backup of the database. You can create multiple replicas to
distribute the database among members of a department or a workgroup. The databases
can then be stored on the hard drives of the machines, which decreases activity on a
network. All the replicas made from a single Design Master make up a replica set.
When you replicate a database, the original database becomes the Design Master. The
Design Master and each of the replicas function as standalone databases. Each user can
add, edit, or delete data in their replica. These changes in the replicas can then be
synchronized with the Design Master and other replicas in the replica set. Each user can
add, edit, or delete objects in the database, such as tables, queries, reports, or forms.
However, these changes are not copied to the Design Master during synchronization.
Only the structural changes made in the Design Master are distributed to the replica set.
When a database becomes a Design Master, Access adds hidden fields and tables to the
database to facilitate synchronization. These hidden fields increase the size of the
database. Certain properties are also added to the property sheets of database objects as
well. The two visible properties are Replicable and KeepLocal. The Replicable
property applies to a database or an object and indicates whether the database or object
can be replicated. The KeepLocal property applies to database objects. You can keep
an object in the Design Master from being replicated by setting this property to True.
This option can be useful if there are tables in the Design Master that you do not want
to include in the replicas, such as those containing sensitive information, or information
that would be of no use to the replica user and would only take up disk space. In this
case, you would be creating a partial replica.
When you create a replica for the first time, the current database is converted to a
Design Master. After the first time, you simply create another replica.
Procedures
1. Open the desired database.
2. Select the Tools menu.
Discussion
When changes have been made to replicated files or the Design Master, they can then
be synchronized. You can synchronize a replica with the Design Master or another
replica in the replica set.
Synchronization is bi-directional, meaning that all changes are exchanged between the
files in both directions.
Procedures
1. Open the Design Master database window.
2. Select the Tools menu.
3. Point to the Replication command.
4. Select the Synchronize Now command.
5. Select the Directly with Replica list.
6. Select the desired replica file.
7. Select OK to begin the synchronization process.
8. Select Yes to complete the synchronization process.
9. Select OK.
Discussion
When replicas are synchronized with one another, replication conflicts can occur.
Conflicts are usually generated when the same data in multiple files has been changed
in different ways. If a table has replication conflicts, Access opens a message box when
the file is opened. You can choose to resolve the conflicts at this point or resolve them
later using the Resolve Conflicts feature.
Access stores replication conflicts in a conflicts table in the database. This table holds
all records with conflicts. When you resolve conflicts, Access displays the existing
record and the conflicting record next to each other. If you choose to keep the existing
record, Access overwrites the conflicting record. If you choose to keep the conflicting
record, Access overwrites the existing record. Either way, you cannot undo the change.
Procedures
1. Open the Design Master database window.
2. Select the Tools menu.
3. Point to the Replication command.
4. Select the Resolve Conflicts command.
5. Select Resolve Conflicts.
6. Select Keep Existing Record or Overwrite with Conflict Record.
7. Select Yes or No to confirm.
8. Repeat steps 5-7 until all conflicts are resolved.
9. Select OK.
10. Select Close to close the Resolve Replication Conflicts dialog box.
EXERCISE
REPLICATING DATABASES
Task
Replicate a database.
1. Open Train32x.
2. Create a replica called Train32_Rep and save it to the student data
folder.
3. Open the Trainer table in Train32 in Datasheet view and change
the Address field in the first record to 123 Main St.. Close the table.
4. Synchronize the database with Train32_Rep.
5. Close Train32.
6. Open Train32_Rep. Open the Trainer table in Datasheet view and
verify that the address information for the first record has changed.
7. Close the table.
8. Close the database file.
APPENDIX IX -
INTRODUCTION TO VBA MODULES
Add Comments
Use Keywords
Discussion
The Module window is used in Access for creating and editing Visual basic for
Applications(VBA) code.
Depending on the type of Module (either Private or Global) the Module window can be
opened via the module page of the database window or via an event property. Private
Modules are object based and run from event properties. Global modules are not object
based and can be accessed via the database window.
Database objects can have VBA modules attached to them via the various event
properties for each of their controls. For example one form could have a VBA module
attached to each of its event properties for each of its controls.
Once in the Module window the different code associated with the current Object can be
selected from the drop down lists on the toolbar. The left hand list shows all the controls
on the object and the right hand list shows all the event properties for each of the
controls. For example you could select a command button from a form on the left hand
list and the On Click property on the right hand list to see what coding is attached to the
button when it is clicked.
Global Modules are created via the database window and are used when VBA coding is
required to be accessed from anywhere in the database.
Access uses different colours for the text in a Module to represent what that text stands
for:
Black - General Text
Green - Comments
Blue - Key Words
Red - Code that contains Errors or bugs
This colour coding helps when deciphering large amounts of code and also when
debugging.
SUB PROCEDURES
Discussion
When Creating VBA code attached to an event property a Sub Procedure is created
within the Module for that object. To define the Sub Procedure and separate it from the
rest of the code the Sub……End Sub keywords are used. The correct syntax for these
is as follows
End Sub
The Private Sub Keyword must be the first line of the procedure. It defines the
beginning of the procedure and the procedure name. The procedure name cannot
contain spaces. When Access creates private sub procedures (via command button
wizards) it automatically names the sub procedure by the associated control and event
property for the procedure.
The End Sub keyword has to be the last line of the procedure and declares the end of the
sub procedure.
ADDING COMMENTS
Discussion
When creating VBA code even in small quantities, adding comments to keep track of
what you are doing is recommended.
To add a comment to the end of a line of code or on a line of its own just start off the
comment with a single quote '.For example:
‘This is a comment
Comments appear in the Modules window as Green Text to separate them from the rest
of the code.
KEYWORDS
Discussion
Keywords are the main commands of VBA, there are over 500 keywords in VBA each
with its own specific function. Keywords appear as blue text in the module window to
distinguish them from the rest of the code.
Examples include the Private Sub and End Sub Keywords that have already been
discussed. As more complex coding is used the more key words will occur as part of the
modules.
To see all the keywords available and their functions type in keywords into the index
section Access Help and display the results. They are all split into various categories of
associated keywords. From these different categories the different keywords can be
selected and their functions and syntax displayed.
creating ................................................. 32
A
Crosstab Query Wizard ............................. 32
ActiveX controls using ..................................................... 32
adding ............................................. 85, 86 Custom commands
attaching ............................................... 86 adding ................................................. 152
registering ....................................... 84, 85
D
using ..................................................... 84
Advanced Query Wizards ......................... 31 Data
Analyzing Tables ........................................ 3 exporting ......................................... 16, 17
importing ........................................ 12, 13
B
linking to a table .............................. 13, 14
Backing Up a Database ............................. 22 Data Access Page ...................................... 57
Built-in menu items Data access pages
adding to a toolbar .............................. 149 creating ........................................... 57, 58
creating a PivotTable ....................... 60, 61
C
grouping ................................................ 59
Calculated controls sorting ............................................. 59, 60
creating ........................................... 47, 48 Data formats.............................................. 16
Charts ....................................................... 39 Database objects
activating Microsoft Graph.............. 43, 44 exporting ......................................... 16, 17
adding data labels............................ 47, 48 importing ........................................ 12, 13
adding to a form .................................... 42 Databases
adding to a report .................................. 42 backing up ............................................. 22
changing the title................................... 46 compacting ............................................ 20
changing the type ............................ 45, 46 converting ....................................... 17, 18
Chart Wizard .................................. 40, 41 decrypting ............................................. 64
creating ........................................... 40, 41 encrypting ............................................. 64
formatting the title ................................ 47 replicating ....................................... 74, 75
Combo boxes resolving replication conflicts ................ 77
creating ........................................... 33, 34 synchronizing .................................. 74, 76
Command buttons synchronizing replicas ........................... 76
adding ............................ 70, 78, 79, 80, 81 Date control
adding to switchboard .................. 140, 141 inserting ................................................ 52
creating ........................................ 118, 119 Documenter
Commands using ..................................................... 19
adding to a menu item ......................... 151
Compacting a Database............................. 20 E
Concatenation Encrypting a Database ............................... 64
using in a query..................................... 17 Event Properties ...................................... 127
Controls Excel
ActiveX controls ................................... 84 creating workbooks using Office Links .. 28
adding logic .................................... 38, 39 dragging and dropping data into............. 27
creating calculated .......................... 47, 48 exporting data to.................................... 26
using the Combo Box tool ............... 33, 34 Exporting to Excel ................................. 25
using the List Box tool .......................... 35 Exporting
using the Option Group tool .................. 37 data ................................................. 16, 17
Conversion Error Logging feature ............. 18 Exporting to Excel and Word................. 25
Converting Exporting Data .......................................... 16
database files .................................. 17, 18
F
Converting Files ....................................... 17
Crosstab queries Fields