Ms Access 2003 Tutorial
Ms Access 2003 Tutorial
Access 2003
Student Edition
Complete
CustomGuide
Computer Courseware
Error! Reference source not found. 19
Don’t worry if you find some of these objects confusing at first—they will make more sense
after you’ve actually used them.
One more important note about the Access program screen: We have been examining the
Database window in this lesson, but it is by no means the only screen that you will encounter
in Microsoft Access. Just as there are several different types of database objects in Microsoft
Access, there are also dozens of different program screens—something that makes Access
quite different from its Microsoft Office cousins Word and Excel. You will see some of these
screens as we continue this chapter’s tour of Microsoft Access.
Lesson 2-13: Creating Mailing Labels with the Label Wizard ............................................90
Lesson 2-14: Database Object Management........................................................................92
Lesson 2-15: File Management............................................................................................94
Lesson 2-16: Compacting and Repairing a Database...........................................................96
Lesson 2-17: Converting an Access Database......................................................................97
Chapter Two Review............................................................................................................98
Chapter Three: Finding, Filtering, and Formatting Data......................................... 105
Lesson 3-1: Finding and Replacing Information................................................................106
Lesson 3-2: Sorting Records ..............................................................................................108
Lesson 3-3: Filtering by Selection .....................................................................................110
Lesson 3-4: Filtering by Form ...........................................................................................112
Lesson 3-5: Creating an Advanced Filter...........................................................................114
Lesson 3-6: Adjusting Row Height and Column Width.....................................................116
Lesson 3-7: Rearranging Columns.....................................................................................118
Lesson 3-8: Changing Gridline and Cell Effects ...............................................................119
Lesson 3-9: Freezing a Field..............................................................................................120
Lesson 3-10: Hiding a Column ..........................................................................................121
Lesson 3-11: Changing the Datasheet Font........................................................................122
Chapter Three Review .......................................................................................................124
Chapter Four: Working with Tables and Fields ......................................................... 129
Lesson 4-1: Understanding Field Properties ......................................................................130
Lesson 4-2: Indexing a Field..............................................................................................132
Lesson 4-3: Adding a Primary Key to a Table ...................................................................134
Lesson 4-4: Inserting, Deleting, and Reordering Fields.....................................................136
Lesson 4-5: Changing a Field’s Data Type ........................................................................138
Lesson 4-6: Using Field Descriptions ................................................................................140
Lesson 4-7: Adding a Caption............................................................................................141
Lesson 4-8: Changing the Field Size .................................................................................142
Lesson 4-9: Formatting Number, Currency, and Date/Time Fields ...................................144
Lesson 4-10: Formatting Number, Currency, and Date/Time Fields by Hand...................146
Lesson 4-11: Formatting Text Fields..................................................................................148
Lesson 4-12: Setting a Default Value.................................................................................150
Lesson 4-13: Requiring Data Entry ...................................................................................151
Lesson 4-14: Validating Data .............................................................................................152
Lesson 4-15: Creating an Input Mask ................................................................................154
Lesson 4-16: Creating a Lookup Field...............................................................................156
Lesson 4-17: Creating a Value List ....................................................................................158
Lesson 4-18: Modifying a Lookup List .............................................................................160
Chapter Four Review .........................................................................................................162
Chapter Five: Creating Relational Databases ............................................................. 167
Lesson 5-1: Understanding Table Relationships ................................................................168
Lesson 5-2: Creating Relationships Between Tables .........................................................170
Lesson 5-3: Enforcing Referential Integrity.......................................................................172
Lesson 5-4: Testing Referential Integrity and Printing and Deleting Table Relationships.174
Lesson 5-5: Understanding Relationship Types.................................................................176
Chapter Five Review..........................................................................................................178
Chapter Six: Working with Queries ..............................................................................181
Lesson 6-1: A Quick Review .............................................................................................182
Lesson 6-2: Understanding the Different Types of Queries ...............................................183
Lesson 6-3: Creating a Multiple Table Query ....................................................................184
Lesson 6-4: Creating a Calculated Field ............................................................................186
Lesson 6-5: Working with Expressions and the Expression Builder..................................188
Lesson 6-6: Using an IIF Function ....................................................................................190
Chapters
Each manual is divided into several chapters. Aren’t sure if you’re ready for a chapter? Look
at the prerequisites that appear at the beginning of each chapter. They will tell you what you
should know before you start the chapter.
Lessons
Each chapter contains several lessons on related topics. Each lesson explains a new skill or
topic and contains a step-by-step exercise to give you hands-on-experience.
Chapter Reviews
A review is included at the end of each chapter to help you absorb and retain all that you have
learned. This review contains a brief recap of everything covered in the chapter’s lessons, a
quiz to assess how much you’ve learned (and which lessons you might want to look over
again), and a homework assignment where you can put your new skills into practice. If you’re
having problems with a homework exercise, you can always refer back to the lessons in the
chapter to get help.
8 Microsoft Access 2003
In this lesson, you will learn how to apply number formats. Applying number formatting changes
You can also format howIn values are displayed—it
this lesson, you will learn doesn’t
how tochange
apply the actual
number information
formats. in any
Applying way. Excel
number is often
formatting changes
Tips and traps appear in the values
You by
canusing
Formatting
the
also format
values by toolbar
using the
smart
howenough
sign
values to
to indicate
smart
areapply
enoughcurrency
some number
displayed—it
to apply (such
some as
formatting
doesn’t
$548.67),
number
automatically.
change the
Excel will
formatting
For example,
actual information
automatically
automatically.
in anyifway.
Forapply
you Excel
use a dollar
the currency
example,
is often
if you usenumber
a dollar
margin. or Formatting
by selectingtoolbar
Format
or by → Cells
selecting
format
sign for you. currency (such as $548.67), Excel will automatically apply the currency number
to indicate
format for you.
The Formatting toolbar has five buttons (Currency, Percent, Comma, Increase Decimal, and
from the menu
Format and
→ Cells The Formatting
Decrease Decimal)toolbar
you canhas usefive buttons apply
to quickly (Currency,
commonPercent, Comma,
number Increase
formats. If noneDecimal,
of these and
buttons
clicking
from the menu and
Number tab. hasDecrease Decimal)
what you’re looking you can
for, useneed
you to quickly apply
to use the common
Format Cellsnumber formats.
dialog box If none of
by selecting these →
Format buttons
clicking the
Icons and pictures appear in the Number tab. hasfrom
Cells
dialog
whatthe
from
Cellsbox
menulooking
you’re
theasmenu
isn’t
and clicking
and
fast as
for, youtheneed
clicking
using
Number
to usetab.
the Number
the toolbar,
theFormatting
Format Cells
but ittab. Formatting
gives
numbers
dialog with
you more numbers
box by
precisionwith
theselecting
and the
Format →
Format Cells
Format options.
formatting Cells
margin, showing you what to dialog
We’ll usebox
bothisn’t as fastinasthis
methods using the toolbar, but it gives you more precision and formatting options.
lesson.
We’ll use both methods in this lesson.
click or look for. 1. Select the cell range D5:D17 and click the Comma Style button on
Comma Style 1.theSelect the celltoolbar.
Formatting range D5:D17 and click the Comma Style button on
Comma
button Style theadds
Excel Formatting toolbar.(the comma) and two decimal places to the selected cell
a hundreds separator
button range.
Excel adds a hundreds separator (the comma) and two decimal places to the selected cell
Clear step-by-step instructions range.
• When you see a keyboard instruction like “press <Ctrl> + <B>,” you should press and
hold the first key (<Ctrl> in this example) while you press the second key (<B> in this
example). Then, after you’ve pressed both keys, you can release them.
• There is usually more than one way to do something in Access. The exercise explains the
most common method of doing something, while the alternate methods appear in the
margin. Use whatever approach feels most comfortable for you.
• Important terms appear in italics the first time they’re presented.
• Whenever something is especially difficult or can easily go wrong, you’ll see a:
NOTE:
immediately after the step, warning you of pitfalls that you could encounter if you’re not
careful.
• Our exclusive Quick Reference box appears at the end of every lesson. You can use it to
review the skills you’ve learned in the lesson and as a handy reference—when you need
to know how to do something fast and don’t need to step through the sample exercises.
Formatting a Worksheet 25
Formatting a Worksheet 25
Welcome to your first lesson on Microsoft Access! Microsoft Access is a powerful database
program you can use to store all kinds of information—from a simple list of recipes to an
inventory catalog with tens of thousands of products. Once information is stored in a
Microsoft Access database, it’s easy to find, analyze, and print.
Of all the programs in the Microsoft Office suite, Microsoft Access is the one that most
intimidates people. “Mastering Microsoft Excel or Word was hard enough,” they think. “How
can I ever understand a complicated program like Access?” While it’s true that Microsoft
Access has many advanced features (there are computer consultants whose only job is
programming Access databases), creating and working with a Microsoft Access database is
probably a whole lot easier than you think.
With that in mind, this chapter is your introduction to Microsoft Access and the world of
databases. In this chapter you will learn more about exactly what a database is, what it is used
for, and how to perform simple database tasks, such as adding and deleting records. This
chapter also takes you on a basic tour of various parts of a Microsoft Access database: Tables,
Forms, Reports, and Queries. If you have worked with one of the other Microsoft Office
applications, such as Microsoft Excel or Word, you will find that you already know a lot about
the concepts covered in this chapter.
And so, without further ado, turn the page and take your first step into the world of databases.
12 Microsoft Access 2003
Figure 1-1
Figure 1-2
In its simplest form, a database is a collection of information that is organized into a list.
Whenever you make a list of information, such as names, addresses, products, or invoices,
you are, in fact, creating a database. Technically speaking, you don’t even have to use a
database program to create a database. You can make a list of information in all kinds of
programs, such as Microsoft Excel, Word—even the meek and lowly Notepad program!
A database program, however, is much more powerful than a simple list you keep on paper or
in a Microsoft Word document. A database program lets you:
• Store Information
A database stores lists of information that are related to a particular subject or purpose. A
database stores personal information, such as a list of aunt Mildred’s home recipes, or
business information, such as a list of hundreds of thousands of customers. A database
also makes it easy to add, update, organize, and delete information.
• Find Information
You can easily and instantly locate information stored in a database. For example, you
can find all the customers with the last name “Johnson” or all the customers who live in
the 55417 zip code and are older than 65.
• Analyze and Print Information
You can perform calculations on information in a database. For example, you could
calculate what percent of your total sales comes from the state of Texas. You can also
present information in a professional-looking printed report.
• Manage Information
Databases make it easy to work with and manage huge amounts of information. For
example, with a few keystrokes you can change the area code for hundreds of customers
in the (612) area code to a new (817) area code.
• Share Information
Most database programs (including Microsoft Access) allow more than one user to view
and work with the same information at once. Such databases are called multi-user
databases.
Databases usually consist of several parts. A Microsoft Access database may contain up to
seven different database object types. The table on this page identifies the database objects
you can use when creating a Microsoft Access database. Some objects you will use all the
time (such as Tables), others you will hardly use (such as Modules).
Forms Forms are custom screens that provide an easy way to enter and view data in a
table or query.
Reports Reports present data from a table or query in a printed format.
A special type of Web page designed for viewing and working with Microsoft
Pages Access data from an intranet or over the Internet.
Macros help you perform routine tasks by automating them into a single
Macros command. For example, you could create a macro that automatically opens and
prints a report.
Like macros, modules automate tasks but by using a built-in programming
Modules language called Visual Basic or VB. Modules are much more powerful and
complex than macros.
If you’re upgrading from either Access 97 or Access 2000 to Access 2003, you’re in luck—in
most respects, Access 2003 looks and works almost the same as both Access 97 and Access
2000. Here’s what’s new in Access 2003 (and if you’re upgrading from Access 97, what’s new
in Access 2000).
Data Access Pages Data Access Pages are forms and reports designed for the Web. They enable
New in 2000 any user to easily open, view, and update live data from the Internet or an
intranet. These pages are stored as HTML files, outside the Access database
file, so that users who do not have Access installed can share them.
Create Web Pages Support for the Internet has been greatly improved in all Office XP programs.
New in 2000 You can easily save your Access databases as Web pages, and even create
interactive Web pages, which have basic datasheet functionality and allow
users to add, change, and review data.
Subdatasheets Allows you to see information from tables that are related to the table you are
New in 2000 currently viewing. With subdatasheets, you can browse hierarchical data in
Datasheet View.
Conditional Changes the format of a field based on the value of the data in a form or report.
Formatting For example, if the date in a “Due Date” field is equal to or less than the current
New in 2000 date, you might display the date in a large red font.
PivotTable and Microsoft Access 2003 introduces PivotTable and PivotChart Views to tables,
PivotChart Reports queries, and forms. PivotTables and PivotCharts summarize information into an
New in 2003 organized and meaningful format and are great for analyzing data.
Seamless Microsoft Access 2003 includes built-in Microsoft SQL Server™ integration that
Integration with brings the power of high-end database management to the familiar Access
SQL Server environment.
New in 2000
XML Support XML is quickly becoming the new standard for exchanging data between
New in 2003 different programs. Access 2003 can now import and export information to and
from XML file formats.
Figure 1-5
Displays files in special Currently selected
folders. folder or drive
Figure 1-6 File name Change the type of files that are
displayed in the Open dialog box.
You start Access 2003 the same as you would start any other Windows program—with the
Start button. Because every computer is set up differently (some people like to rearrange and
reorder their Program menu), the procedure for starting Access on your computer may be
slightly different from the one listed here.
1. Make sure that your computer is on and the Windows desktop appears
Start button on the screen.
2. Use your mouse to point to and click the Start button, located at the
bottom-left corner of the screen.
The Windows Start menu pops up.
3. Use the mouse to move the pointer over the word Programs.
A menu pops up to the right of Programs. The programs and menus you see listed
depend on the programs installed on your computer, so your menu will probably look
somewhat different from the illustration.
4. On the Programs menu, point to and click Microsoft Access.
Once you click the Microsoft Access program, your computer’s hard drive will whir
for a moment while it loads Access. The Access program appears and the task pane Open button
displays options for opening an existing database or creating a new database, as shown Other Ways to Open a
in Figure 1-5. File:
You really can’t do anything in Microsoft Access unless you open an existing database • Select File → Open
or create a new database. Most of the time you will open an existing database, and from the menu.
here’s how to accomplish this simple task. • Press <Ctrl> + <O>.
5. Click the Open button on the toolbar.
The Open dialog box appears, as shown in Figure 1-6. Now you have to tell Access
where the database you want to open is located.
6. Navigate to the folder where your practice files are located.
Ask your instructor if you don’t know where your practice folder is located.
7. Find and double-click the Lesson 1 file.
Access opens the Lesson 1 database and displays it in the database window.
Table 1-3: Special Folders in the Open and Save As Dialog Boxes
Heading Description
Displays a list of files that you’ve recently worked on.
My Recent Files
Displays all the files in the My Documents folder—the default location where
Microsoft Office programs save their files.
My Documents Quick Reference
Temporarily minimizes or hides all your programs so that you can see the To Start Microsoft Access:
Windows desktop. 1. Click the Windows Start
Desktop button.
2. Select Programs →
Displays a list of your “Favorite” folders, although these are often used to Microsoft Access.
organize your favorite Web pages.
To Open a Database:
My Computer
• Click the Open
Displays all the files in any Web Folders—special locations to save Web pages. button on the toolbar.
Or…
My Network Places • Select File → Open from
the menu.
Or…
• Press <Ctrl> + <O>.
Database
window
Objects
bar
You might find the Access 2003 program screen a bit confusing and overwhelming the first
time you see it. What are all those buttons, icons, menus, and arrows for? This lesson will
help you become familiar with the Access program screen. There are no step-by-step
instructions in this lesson—all you have to do is look at Figure 1-7 and then refer to Table
1-4: The Access Program Screen for details about each item. And, most of all, relax! This
lesson is only meant to help you get acquainted with the Access screen—you don’t have to
memorize anything.
Don’t worry if you find some of these objects confusing at first—they will make more sense
after you’ve actually used them.
One more important note about the Access program screen: We have been examining the
Database window in this lesson, but it is by no means the only screen that you will encounter
in Microsoft Access. Just as there are several different types of database objects in Microsoft
Access, there are also dozens of different program screens—something that makes Access
quite different from its Microsoft Office cousins Word and Excel. You will see some of these
screens as we continue this chapter’s tour of Microsoft Access.
Figure 1-8
Figure 1-9
This lesson explains one of the best ways to give commands to Access—by using the menus.
Menus for all Windows programs can be found at the top of a window, just beneath the
program’s title bar. In Figure 1-8 notice the words File, Edit, View, Insert, Tools, Window,
and Help. The next steps will show you why they’re there.
• By hiding the commands you don’t use as frequently (the more advanced
commands) from view.
• By displaying the hidden commands if you click the downward-pointing arrow
( ) at the bottom of the menu or keep the menu open for a few seconds.
6. Click the word Tools in the menu.
The most common menu commands appear in the Tools menu. Some people feel
intimidated when confronted with so many menu options, so the menus in Office XP
don’t display the more advanced commands at first. To display a menu’s advanced
commands either click the downward-pointing arrow ( ) at the bottom of the menu or
keep the menu open for a few seconds.
7. Click the downward-pointing arrow ( ) at the bottom of the Tools menu.
The more advanced commands appear shaded on the Tools menu.
The Tools menu with
NOTE: If there isn’t a downward-pointing arrow at the bottom of the Tools menu,
skip this step and move on to Step 8. less frequently used
commands displayed
If you’re accustomed to working with earlier versions of Microsoft Office, you may
after clicking the
find that hiding the more advanced commands is disconcerting. If so, you can easily
downward-pointing
change how the menus work. Here’s how:
arrow ( ) at the
8. Select View → Toolbars → Customize from the menu and click the bottom of the menu.
Options tab.
The Customize dialog box appears, as shown in Figure 1-9. This is where you can
change how Access’s menus work. There are two check boxes here that are important:
Quick Reference
• Always show full menus: Clear this check box if you want to hide the
advanced commands. To Open a Menu:
• Show full menus after a short delay: If this option is checked, Access • Click the menu name with
waits a few seconds before displaying the more advanced commands on a menu. the mouse.
9. Click Close. Or…
• Press <Alt> and then the
underlined letter in the
Table 1-5: Menus Found in Microsoft Access
menu.
Menu Item Description
To Display a Menu’s
File File-related commands to open, close, print, and create new files. Hidden Commands:
Edit Commands to copy, cut, paste, find, and replace text. • Click the downward-
pointing arrow ( ) at the
View Commands to change how the screen is displayed.
bottom of the menu.
Insert Items that you can insert into a database, such as graphics and charts. Or…
Format Commands to format fonts, cell alignment, and borders. • Open the menu and wait
a few seconds.
Records Commands to add, delete, sort, and filter information.
To Change How Menus
Tools Tools such as the spell checker and macros. You can also change the default Work:
options for Microsoft Access here.
1. Select View → Toolbars
Window Commands to display and arrange multiple windows (if you have more than one → Customize from the
file open). menu and click the
Options tab.
Help Provides help with using Microsoft Access.
2. Check or clear either the
Always show full menus
and/or Show full menus
after a short delay
options, then click Close.
Move a toolbar by
dragging its move handle.
Figure 1-11
Figure 1-12
In this lesson we move on to another very common way of giving commands to Access—
using toolbars. Toolbars are shortcuts—they contain buttons for the most commonly used
commands. Instead of wading through several menus to access a command, you can click a
single button on a toolbar. Access displays different toolbars, depending on what you are
working on. For example, when you view the Database window, Access displays the Database
toolbar, which contains database-related commands.
This lesson explains how to use toolbars and also how to hide, display, and move toolbars.
1. Position the mouse pointer over the New button on the toolbar (but
don’t click the mouse yet!).
A ScreenTip appears over the button, briefly identifying what the button is—in this
case, “New.” If you don’t know what a button on a toolbar does, simply move the
pointer over it, wait a second, and a ScreenTip will appear over the button, telling you
what it does.
ScreenTip 2. Click the New button on the toolbar.
The Task Pane toolbar appears.
Combo box
Text box
Options
Check box
Figure 1-13
Some commands are more complicated than others are. Opening a database is a simple
process—you only need to select File → Open from the menu or click the Open button on the
Database toolbar. Other commands are more complex, such as changing the default options
for Access. Whenever you want to do something relatively complicated, you must fill out a
dialog box. Filling out a dialog box is usually quite easy. If you have worked at all with
Windows, you have undoubtedly filled out hundreds of dialog boxes. Dialog boxes usually
contain several types of controls, including:
• Text boxes
Text box • List boxes
• Check boxes
• Combo boxes (also called drop-down lists)
It is important that you know the names of these controls, because this book will refer to them
Tables/Queries in many lessons throughout this guide. This lesson will give you a tour of a dialog box and
tab explain each of these controls to you, so that you will know what they are and know how to
use them.
Figure 1-15
Print Scroll
Esc F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 Screen Lock Pause Lock Lock Lock
{ } 7 8 9
0
2 3
PgDn
.
Enter
execute a keystroke
Ctrl Alt Alt Ctrl
Ins Delete
Figure 1-14
You are probably starting to realize that there are several ways to do the same thing in Access.
For example, to open a database, you can use the menu (select File → Open) or the toolbar
(click the Open button). This lesson introduces you to two more methods of executing
commands: Right mouse button shortcut menus and keystroke shortcuts.
You know that the left mouse button is the primary mouse button, used for clicking and
double-clicking, and it’s the mouse button that you will use over 95 percent of the time. So
what’s the right mouse button for? Whenever you right-click something, it brings up a
shortcut menu that lists everything you can do to the object. Whenever you’re unsure or
curious about what you can do with an object, right-click it. A shortcut menu will appear with
a list of commands related to the object or area you right-clicked.
Right mouse button shortcut menus are an especially effective way to give commands in
Access because you don’t have to wade through several levels of unfamiliar menus when you
want to do something. For this lesson, assume you want to modify the Employees table.
1. Position the pointer over the Employees table and click the right
mouse button.
Shortcut menu A shortcut menu appears where you clicked the mouse, as shown in Figure 1-14.
Notice one of the items listed on the shortcut menu is Print. This is the same Print
command that you can select from the menu by clicking File → Print. Using the right
mouse button shortcut method is slightly faster and usually easier to remember than
using the menus in Access. If you open a shortcut menu and then change your mind,
Right-click an object
you can close it without selecting anything. Here’s how:
to open a shortcut
menu that lists 2. Move the pointer anywhere outside the shortcut menu and click the left
everything you can do mouse button to close the shortcut menu.
to the object. Remember that the options listed in the shortcut menu will vary, depending on what or
where you right-clicked.
3. Position the pointer over the Database toolbar and click the right mouse
button.
A shortcut menu listing all the toolbars you can view appears.
4. Move the pointer anywhere outside the shortcut menu and click the left
mouse button to close the shortcut menu.
On to keystroke shortcuts. Without a doubt, keystroke shortcuts are the fastest way to
give commands to Access, even if they are a little hard to remember. They’re great time
savers for issuing frequently used commands. To issue a keystroke shortcut, press and
hold down the <Ctrl> key, press the shortcut key, and then release both buttons.
5. Press <Ctrl> + <O> (the “Ctrl” and “O” keys at the same time).
This is the keystroke shortcut to open a database and thus pressing <Ctrl> + <O>
causes the Open dialog box to appear. Since you already have a database open you can
close the dialog box without opening a new file. The Ctrl key
6. Click Cancel to close the Open dialog box.
The Open dialog box closes.
NOTE: Although we won’t discuss it in this lesson, you can change or remap the
default keystroke shortcuts for Access and assign them to execute other
commands.
Table 1-6: Common Keystroke Shortcuts lists the shortcut keystrokes you’re likely to use the
most in Access.
Figure 1-16
List Details
Objects are displayed as small icons in a list. This is Objects are displayed as small icons with additional
a great default view because it allows you to see as information, such as the description and the date
many objects as possible. the object was created or last modified.
Figure 1-17
Think of the Database window as the mission control center for an Access database. You use
the Database window to open, modify, and manage all the different types of objects in a
Forms icon database. The Database window contains buttons for each type of database object described in
Figure 1-17. To display a type of object, click the appropriate button.
One of the many benefits of working with Windows is that you can open and work with
several windows at once. Working with multiple windows is particularly important in Access
because each database object you open appears in its own window and you will often have to
switch between those windows. The Database window always remains open—closing the
Database window closes the current database.
This lesson explains how to open and work with more than one window. You will also learn
some tricks on changing the size of a window, moving a window, and arranging a window.
Tables icon
1. Click the Tables icon on the Objects bar to display the tables in the
current database.
Access displays all the tables in the current database.
2. Open the Employees table.
Remember that to open any database object, you can select the object and click the
Open button in the Database window or just double-click the database object.
Other Ways to Switch The Employees table appears in its own window. The Database window is still open
Between Windows: too, although you may not be able to see it because it’s behind the Employees table
• Select Window from window.
the menu bar and select One of the big changes in Access 2003 is that each open window appears as an icon on
the window you want to the Windows taskbar, as shown in Figure 1-18. To switch to a different document, click
view. its icon on the taskbar.
3. Click the Lesson 1: Database icon on the Windows taskbar.
The Database window appears. The Employees table window is still open, but you
can’t see all of it because it is located behind the Database window.
Sometimes it can be helpful to view two or more windows on your screen at the same
Maximize button time. When you want to do this, you use the Window menu to select a tile option.
Move on to the next step to try this for yourself.
Scroll Up
Total Number Click here to
of Records in scroll up. Scroll Box
First Current Last
the Table Indicates your
Record Record Record
current position
in the list (you
can also click
Scroll Down and drag the
Previous Next New Click here to
Record Record Record scroll box to
scroll down. scroll up or
Figure 1-21 Figure 1-22 down).
Tables are the heart and soul of any database. Tables are where a database stores all of its
information. All the other database objects—queries, forms, reports, pages, macros, and
modules—are merely tools to analyze and manipulate the information stored in a table. Any
Other Ways to Open a of these other database objects are optional—but without tables, a database wouldn’t be a
Table: database. Each table in a database stores related information. Most databases have more than
• Select the table and one table: Each table is used to store a different type of information. For example, one table
click Open. might contain a list of customers and their addresses, while another table might contain any
orders placed by the customers, while yet another table might contain a list of products.
Tables are made up of groups of fields. A field is a specific type of information, such as a
person’s last name, address, or phone number. Together, the related fields for each individual
person, place, or thing make up a single record. If your company has ten employees, your
Next Record
button employee table would have ten records—one for each employee.
Other Ways to Move to Here’s how to open and view a table:
the Next Record:
• Click anywhere in the 1. Click the Tables icon in the Database window Objects bar.
record if it is displayed Access lists all the tables in the current database.
on the screen.
• Press the down arrow
key <↓>.
2. Click the Employees table to select it and then click the Open button in
the Database window.
The Employees table opens in its own window, as shown in Figure 1-20. If you are
working on a table, you will usually want to maximize the window so that you can see Last Record
as much information as possible. button
3. Click the table window’s Maximize button. Other Ways to Move to
The table window expands to fill the entire screen. Table information is displayed, the Last Record:
entered, and modified in a datasheet. A datasheet is a grid that contains all the records • Press <Ctrl> + <End>
in a table. Records are stored in rows and field names are stored in columns, as shown (when not editing
in Figure 1-20. record).
Let’s take a closer look at the current table. First notice the that appears to the left
of the first record in the table. This is the record selector, and it shows the record that
you are currently working on.
Next, take a look at the record navigation buttons near the bottom of the screen, as
shown in Figure 1-21. The record navigation buttons display the number of records in Quick Reference
the current database and allow you to move between these records. To Open a Table:
4. Click the Next Record button on the Record Navigation bar. • Click the Tables icon in
Access moves to the next record in the table. Notice that the record selector moves the Objects bar and
to the next record and that the Record Navigation bar indicates that you are currently double-click the table or
viewing Record 2. select the table and click
5. Click the Last Record button on the Record Navigation bar. Open.
Tables will often contain too much information to display on the screen at once and To Move to the Next
you will have to use the vertical scroll bar (see Figure 1-22) to move up or down and/or Record:
the horizontal scroll bar to move left or right. Since the current database only contains • Click the Next
nine records, Access can display all of them on the screen at once. However you will Record navigation
still need to use the horizontal scroll bar in order to see all of the table’s fields. button, or press the <↓>
6. Click the Scroll Right button on the horizontal scroll bar at the bottom key, or click the record
of the screen to scroll to the right. you want to select.
The screen scrolls to the right, displaying previously hidden fields. To Move to the Previous
This ends the first half of our table tour. In the next lesson you’ll learn how to add, edit, and Record:
delete a table’s records. • Click the Previous
Record navigation
Table 1-8: Table Navigation button, or press the <↑>
key, or click the record
To Move To: Navigation Keyboard Mouse you want to select.
Buttons
To Move to the Last
The Next Record Click the Next Press the <↓> (down Click the record you
Record in a Table:
Record navigation arrow) key. want to select (if
button. displayed). • Click the Last
Record navigation
The Previous Click the Previous Press the <↑> (up Click the record you button or press <Ctrl> +
Record Record navigation arrow) key. want to select (if <End> (when not editing
button. displayed). record).
The Last Record in Click the Last Press <Ctrl> + <End> N/A To Move to the First
the Table Record navigation (when not editing Record in a Table:
button. record). • Click the First
The First Record in Press <Ctrl> + <Home> N/A Record navigation
Click the First button or press <Ctrl> +
the Table Record navigation (when not editing
record). <Home> (when not
button. editing record).
You can easily add, change, or delete the records in your table. For example, you might want
to add a record to store information about a new employee, change an existing record when an
New Record employee’s address changes, or delete a record for an employee who no longer works for the
button
company. This lesson explains how to do all three of these tasks.
Other Ways to Add a
New Record: First, here’s how to add a record to a table:
• Click the New
Record button on the 1. Click the New Record button on the Record Navigation bar.
datasheet toolbar. The record selector jumps to the blank row at the end of the table and the blinking
• Press <Ctrl> + <+>. insertion point () appears in the first LastName field.
2. Enter your last name in the LastName field.
If you make a mistake you can press the Backspace key to correct it.
Once you have finished entering data into a field you can press <Tab> or <Enter> to
move to the next field or <Shift> + <Tab> to move to the previous field.
3. Press <Tab> to move to the next field and enter your first name.
When you have Getting the hang of this data entry stuff? Move on to the next step and finish entering
finished adding or the new record.
editing a record, move
4. Complete the record by entering your own information into each
to any other record to
respective field (enter today’s date for the hire date). Remember to press
save your changes.
<Tab> to move to the next field.
Finish entering all that information? Super! When you enter data, you don’t have to
click a Save button to save the information—Access automatically saves the
information as you enter it. Neat, huh?
You can also make changes to the records in a table at any time. To edit a record,
simply click the field you want to edit and make the changes. Let’s try it!
5. Position the mouse over the left edge of the Title cell in your record
Select a cell by
(the pointer changes to a ) and then click to select the cell.
clicking the left edge
When a cell has been selected, anything you type will replace the original contents. of the cell.
6. Type Inside Sales Coordinator.
The text “Inside Sales Coordinator” replaces the original contents of the Title field in
your record. You might want to glance at Table 1-9: Helpful Editing Keys, which lists
several keys that are very important for editing and changing the contents of a field. Delete Record
7. When you have finished making the change, press <Tab>. button
You can permanently delete records that you no longer need from a table. Here’s how: Other Ways to Delete a
Record:
8. Place the insertion point anywhere in the record you just added and click • Right-click the row
the Delete Record button on the toolbar. selector of the record
The record disappears and a warning dialog box appears, asking you to confirm the you want to delete and
deletion. select Delete Rows
9. Click Yes to confirm the deletion and then close the table. from the shortcut menu.
Congratulations! While it may not seem like you have gone over very much, you have just • Click the row selector
learned the ins and outs of data entry with Access—the most important (and boring) database for the record you want
task of all! to delete and press
<Delete>.
Table 1-9: Helpful Editing Keys
Quick Reference
Key(s) Description
To Add a New Record:
Moves to the next field in the table. If you’re at the last field or cell in a
<Tab> or <Enter> table, pressing <Tab> or <Enter> will save your changes and move to the 1. Click the New
first field in the next record. Record navigation
button.
The <Esc> or Escape key is the “Wait, I’ve changed my mind” key. Press Or…
<Esc>
<Esc> to cancel any changes you’ve made to a record. Click the New Record
button on the toolbar.
Use the arrow keys to move between fields and records. If you are editing
Or…
<↑>, <↓>, <←>, or <→> a field, pressing the left and right arrow keys will move the insertion point
one character to the left or right. Press <Ctrl> + <+>.
2. Enter the record
Nothing surprising here. The <Delete> key deletes or erases whatever is information for the field,
<Delete> selected—text, cell contents, even entire records. If you’re working with pressing <Tab> to move
text, the <Delete> key erases characters to the right of the insertion point. to the next field and
<Shift> + <Tab> to move
Use the <Backspace> key to fix your typing mistakes—it erases to the previous field.
<Backspace>
characters to the left of the insertion point. To Edit a Record:
• Click the field you want to
edit and make the
changes.
To Delete a Record:
• Place the insertion point
anywhere in the record
and click the Delete
Record button on the
toolbar.
Total Number
First Current Last of Records in
Record Record Record the Table
Figure 1-26
Figure 1-28
Managers like paper. Don’t try explaining anything to them—they’ll want to see it in printed
hardcopy first. Fortunately, with a report, you can print database information from tables and
queries and satisfy the demands of even the most paper-hungry supervisor. Although you can
print table and query information directly from their datasheets, reports give you many more
formatting and display options. Reports can be a simple list of records in a table or a complex
presentation that includes calculations, graphics—even charts!
Reports are the most static of all the database objects. Unlike tables and forms, which allow
user interaction, reports just sit there, waiting to be printed.
This lesson is your report primer. You won’t get a chance to actually create a report in this
lesson, but you will get a chance to look at an existing report. Here’s how to open a report:
4. Move the pointer over any area of the report and click the mouse
button.
The report returns to the previous preview size.
If a report contains more than one page you can use the vertical scroll bar or the
<Page Up> and <Page Down> keys to scroll through the pages of the report.
Reports wouldn’t be very valuable if they couldn’t be printed. To print a report simply Print button
click the Print button on the toolbar. We’ll skip printing the report for now, unless you
want to see for yourself that the report will print when you click the Print button.
5. Click the Close button to close the report.
Quick Reference
To Open a Report:
• Click the Reports icon in
the Objects bar and
double-click the query or
select the query and click
Open.
To Zoom in Print Preview:
• Click the area you want to
zoom (either in or out)
with the pointer.
To Print a Report:
• Click the Print button
on the toolbar.
Or…
• Select File → Print from
the menu.
Or…
• Press <Ctrl> + <P>.
Figure 1-31
The Print dialog box.
Figure 1-30
Figure 1-31
Most database objects—tables, queries, forms, reports, and pages—and the information they
contain can be printed. Sometimes it’s a good idea to preview a database object on screen to
Tables icon see if something needs to be changed before sending it to the printer. You can preview a
database object by clicking the Print Preview button on the toolbar.
Figure 1-33
Often, before you can do anything in Access, you must select the data that you want to work
with. Many common tasks, such as editing, formatting, copying, cutting, and pasting all
require you to know how to select information in Access. The procedure for selecting text in
Access is no different than selecting text in any other Microsoft Office program, so hopefully
this lesson will be an easy review for you.
4. Click the record selector for the Janet Leverling record ( will You can also select
change to ) to select the record. text using the
keyboard by pressing
NOTE: When you are editing a record, the record selector changes to a pencil icon
and holding the <Shift>
and the pointer changes to an I-beam insertion point.
key while using the
To select multiple records, position the pointer to the left of the first record and then arrow keys to select
drag the mouse pointer down until you have highlighted all the records you want to the text you want.
select.
5. Position the pointer over the record selector for the Janet Leverling
record ( will change to ), then click and drag the pointer down to
the Andrew Fuller record selector.
You have highlighted the first few records in the table. To deselect text, click
anywhere in the
The procedure for selecting a field or column is almost the same as selecting a row—
datasheet.
just click the field name that you wish to select.
6. Position the mouse over the FirstName field name ( changes to )
and click to select the column.
The FirstName field is selected.
7. Click anywhere in the datasheet to deselect the text.
The FirstName field is no longer selected.
That’s all there is to selecting data in Access. It can’t be stressed enough how important it is
that you know how to select text and records. Knowing how to select text will make you more
proficient and skillful at editing and formatting data.
Table 1-11: Data Selection Shortcuts describes several shortcut techniques you can use to
select data in Microsoft Access.
Quick Reference
Table 1-11: Data Selection Shortcuts
To Select Text:
To select Do this Visual Reference
1. Move the insertion point
A word Double-click anywhere in the word. to the beginning or end of
the text you want to
select.
A cell Position the mouse over the left edge of the 2. Click and hold the left
mouse button and drag
cell you want to select ( changes to )
the insertion point across
and click to select the cell.
the text, then release the
A record or row Position the mouse over the record selector mouse button once the
text is selected.
( changes to ) and click to select the
record. To Replace Text:
A field or Position the mouse over the name of the • Replace text by first
column selecting it and then
field you want to select ( changes to )
typing the new text you
and click to select the field.
want.
The entire table Click the empty box ( ) to the left of the To Select Cells, Records,
field names. Fields, and Tables:
• Refer to Table 1-11: Data
Selection Shortcuts.
2. Click the
Copy button (to copy text)
or…
Cut button (to move text)
on the toolbar to cut or move the
selected text…
Figure 1-34
Copy button You already know how to select database data. Once you have selected some text, a cell, a
Other Ways to Copy: record—just about any database object—you can cut it, removing it from its original location,
and then paste it in another location. Copying is similar to cutting, except the information is
• Select Edit → Copy copied instead of removed. Whenever you cut or copy something, it is placed in a temporary
from the menu. storage area called the Clipboard. The Clipboard is available to any Windows program, so
• Press <Ctrl> + <C>. you can cut and paste between different programs.
In Microsoft Access you can cut, copy, and paste any of the following items:
• Text
Paste button • Records
Other Ways to Paste: • Database objects (such as tables, queries, forms, pages, and reports)
• Select Edit → Paste • Controls (such as text boxes and labels on forms and reports)
from the menu.
This lesson will give you some practice copying and pasting text and objects in Access.
• Press <Ctrl> + <V>.
Figure 1-35
You may not want to admit this, but you’re going to make mistakes when you use Access. You
might accidentally delete a record you didn’t mean to delete or paste something you didn’t
mean to paste. Fortunately, Access has a wonderful feature called Undo that does just that. It
undoes your mistakes and actions, making them as though they never happened. This lesson
explains how to undo both single and multiple mistakes and how to redo your actions in case
you change your mind.
It’s important to note that the Undo feature in Access isn’t nearly as powerful as it is in other
Microsoft Office programs. In Microsoft Access 2003, Undo will only reverse the last action
or command you made. If you make a mistake and don’t catch it right away, chances are you
won’t be able to use Undo to correct it. If that weren’t bad enough, Access can’t even undo
many actions! For example, if you delete a record and then decide you want to use Undo to
retrieve the record, you’re out of luck. (To its credit, Access does warn you whenever you
delete a record that you will not be able to use Undo to bring it back.) Hopefully Microsoft
will fix these problems in the next version of Access.
Here’s how to use Undo:
Quick Reference
To Undo Your Last Action:
• Click the Undo
button on the toolbar.
Or…
• Select Edit → Undo from
the menu.
Or…
• Press <Ctrl> + <Z>.
Figure 1-36
Figure 1-37
Quick Reference
To Check Your Spelling:
• Click the Spelling
button on the toolbar.
Or…
• Select Tools → Spelling
from the menu.
Or…
• Press <F7>.
Figure 1-40
When you don’t know how to do something in Windows or a Windows-based program, don’t
panic—ask the Office Assistant for help. The Office Assistant is a cute animated character (a
paperclip, by default) that can answer your questions, offer tips, and provide help for all of
Access’s features. Many Access users don’t use the Office Assistant because they think that
it’s nothing more than an amusing distraction—something to keep them entertained when they
pound out boring databases with Access. This is unfortunate, because the Office Assistant
knows more about Access than most Access books do!
Other Ways to Get Help:
• Type your question in Whenever you use Access, you can make the Office Assistant appear by pressing the <F1>
the Ask a Question key. Then, all you have to do is ask the Office Assistant your question in normal English. This
box on the menu bar lesson will show you how you can get help by asking the Office Assistant a question about an
and press <Enter>. Access feature in normal English.
Figure 1-42
If you find that Clippit’s (the cartoon paperclip) antics are getting old, you can choose a
different Office Assistant at any time. People have different tastes and personalities, and that’s
why Microsoft allows you to select from eight different Office Assistants (see Table 1-13:
Office Assistants1) to guide you through Access. Of course, if you really hate the Office
Assistant, you can always completely shut it off too.
The other topic covered in this lesson is how to use the “What’s This” button. During your
journey with Access you will undoubtedly come across a dialog box or two with a number of
To hide the Office
confusing controls and options. To help you find out what the various controls and options in
Assistant altogether,
right-click the Office a dialog box are there for, many dialog boxes contain a “What’s This” ( ) button that
Assistant and click
explains the purpose of each of the dialog box’s controls. This lesson will show you how to
use the “What’s This” button, but first, let’s start taming the Office Assistant.
Hide.
The Office Assistant must be somewhere on your computer’s screen in order to change it,
so…
1. If necessary, select Help → Show the Office Assistant from the menu.
The Office Assistant appears.
2. Right-click the Office Assistant and select Choose Assistant from the
shortcut menu.
The Office Assistant dialog box appears, on the Gallery tab.
3. Click the <Back or Next> button to see the available Office Assistants.
The Office Assistant you select is completely up to you. They all work the same—they
just look and act differently.
4. Click OK when you find an Office Assistant you like.
If you find the Office Assistant annoying (like a lot of people do) and want to get rid of
it altogether, you can close it the same way you did at the end of the last lesson.
5. Right-click the Office Assistant.
A shortcut menu appears.
6. Select Hide from the shortcut menu.
You can always bring the Office Assistant back whenever you require it’s help by
pressing the <F1> key. Now let’s move on to how to use the “What’s This” button to
discover the purpose of confusing dialog box controls.
7. Select Tools → Options from the menu and click the View tab.
The Options dialog box appears. Notice the “What’s This” button located in the dialog
box’s title bar just to the left of the dialog box’s Close button.
8. Click the “What’s This” button ( ).
The mouse pointer changes to a , indicating you can point to anything on the dialog
Quick Reference
box to find out what it does. The Windows in Taskbar check box is rather confusing, To Change Office
isn’t it? Move on to the next step and we’ll find out what it’s there for. Assistants:
9. Click the Windows in Taskbar check box with the pointer. 1. If necessary, select Help
A brief description of the Windows in Taskbar check box appears. → Show the Office
10. Close the Options dialog box.
Assistant from the menu.
2. Right-click the Office
Assistant and select
Table 1-13: Office Assistants1 Choose Assistant from
Office Assistant Description the menu.
Though nothing more than a thin metal wire, Clippit will help find what you 3. Click the Next> or <Back
Clippit need and keep it all together. Clippit is the default Office Assistant. buttons until you find an
Office Assistant you like,
The Dot Need a guide on the electronic frontier? Able to transform into any shape, the then click OK.
Dot will always point you in the right direction.
To Hide the Office
F1 F1 is the first of the 300/M series, built to serve. This robot is fully optimized Assistant:
for Office use. • Right-click the Office
The Office Logo gives you help accompanied by a simple spin of its colored Assistant and select
Office Logo pieces.. Hide from the shortcut
menu.
I am your wise and magical companion. When you need assistance, summon
Merlin me for a demonstration of my awesome, cyber-magical powers. To See What a Control in a
Dialog Box Does:
Mother Nature Transforming into images from nature, such as the dove, the volcano, and the 1. Click the dialog box’s
flower, Mother Nature provides gentle help and guidance. “What’s This”
If you’re on the prowl for answers in Office, Links can chase them down for button (located right next
Links to the Close button).
you.
2. Click the control you want
If you fall into a ravine, call Lassie. If you need help in Office, call Rocky. more information on with
Rocky
the pointer.
1. Microsoft Office XP Help files, © 2001, Microsoft Corporation.
Figure 1-44
When you are viewing and working with data, sometimes a column will not be wide enough
to display all the text in a cell or field. This is especially true for notes and memo fields,
which may contain several paragraphs of text. Don’t worry—you can summon the Zoom box Quick
to make the contents of any cell easier to view and edit.
To Zoom into
1. If it isn’t already open, open the Employees table. • Select the c
Most of the information in this table fits nicely into its designated column. Move on to zoom and p
the next step and take a look at the Notes field, however. + <F2>.
2. Scroll to the right using the horizontal scroll bar until you can see the
Notes field.
The Notes field is not wide or tall enough to display all its information. Move to the
next step to see how the Zoom box can display the contents of a Notes cell.
3. Click the Notes field for any record, then zoom into that cell by pressing
<Shift> + <F2>.
The Zoom box appears and displays the contents of the selected cell, as shown in
Figure 1-44. You can edit the cell information in the Zoom box. When you’re finished
viewing or editing the cell, simply click OK to close the Zoom box. The cell will
display any changes you made to the data.
4. Click OK to close the Zoom box and then close the Employees table
window.
Figure 1-46
Figure 1-45
Close button
Other Ways to Exit
Access
Because the tasks covered in this lesson are so simple—closing an open database and exiting • Select File → Exit from
the Access program—you’re at what is undoubtedly the easiest lesson in the guide. the menu.
Whenever you close the Database window, you close the current database.
Lesson Summary
Starting Access and Opening a Database
• To Start Microsoft Access: Click the Windows Start button and select Programs → Microsoft
Access.
• To Open a Database: Click the Open button on the toolbar, or select File → Open from the
menu, or press <Ctrl> + <O>.
Tour of a Table
• To Move to the Next Record: Click the Next Record navigation button, or press the <↓>
key, or click the record you want to select.
• To Move to the Previous Record: Click the Previous Record navigation button, or press
the <↑> key, or click the record you want to select.
• To Move to the Last Record in a Table: Click the Last Record navigation button or press
<Ctrl> + <End> (when not editing record).
• To Move to the First Record in a Table: Click the First Record navigation button or press
<Ctrl> + <Home> (when not editing record).
Tour of a Form
• To Move between Records: Use the record navigation buttons near the bottom of the screen.
• To Add a New Record: Do any of the following:
- Click the New Record navigation button
- Click the New Record button on the toolbar
- Press <Ctrl> + <+>
…then enter the record information for the field, pressing <Tab> to move to the next field and
<Shift> + <Tab> to move to the previous field.
• To Delete a Record: Place the insertion point anywhere in the record and click the Delete
Record button on the toolbar.
Tour of a Query
• To Display a Query in Design View: Open the query and click the View button on the
toolbar. You can also select the query and click Design.
Tour of a Report
• To Zoom in Print Preview: Click the area you want to zoom (either in or out) with the pointer.
• To Print a Report: Click the Print button on the toolbar, or select File → Print from the
menu, or press <Ctrl> + <P>.
Selecting Data
• To Select Text: Move the insertion point to the beginning or end of the text you want to select,
click and hold the left mouse button and drag the insertion point across the text, then release the
mouse button once the text is selected.
• To Replace Text: Replace text by first selecting it and then typing the new text you want.
• To Select a Word: Double-click anywhere in the word.
• To Select a Cell: Position the mouse over the left edge of the cell you want to select ( changes
to ) and click to select the cell.
• To Select a Record or Row: Position the mouse over the record selector ( changes to )
and click to select the record.
• To Select a Field or Column: Position the mouse over the name of the field you want to select (
changes to ) and click to select the field.
• To Select the Entire Table: Click the empty box ( ) to the left of the field names.
Using Undo
• To Undo Your Last Action: Click the Undo button on the toolbar, or select Edit → Undo
from the menu, or press <Ctrl> + <Z>.
Changing the Office Assistant and Using the “What’s This” Button
• To Change Office Assistants: If necessary, select Help → Show the Office Assistant from the
menu. Right-click the Office Assistant and select Choose Assistant from the menu, click the
Next> or <Back buttons until you find an Office Assistant you like, then click OK.
• To Hide the Office Assistant: Right-click the Office Assistant and select Hide from the shortcut
menu.
• To See What a Control in a Dialog Box Does: Click the dialog box’s “What’s This” button
(located right next to the Close button) and click the control you want more information on with the
pointer.
Quiz
1. What are the columns in a Microsoft Access table called?
A. Rows.
B. Records.
C. Fields.
D. Cells.
5. Which of the following database objects makes it easy to view, edit, and
enter database information?
A. Tables.
B. Queries.
C. Forms.
D. Reports.
6. Design View lets you view and modify the structure of any database object.
(True or False?)
7. You can display a database object in Design View by: (Select all that apply.)
A. Selecting the database object and press <Ctrl> + <V>.
B. Selecting the database object and clicking the Design button on the Database
window.
C. Opening the database object and selecting Tools → Design View.
D. Opening the database object and clicking the View button on the toolbar.
8. Click the Save button on the toolbar to save record. (True or False?)
10. Which of the following statements is NOT true? (Select all that apply.)
A. You can display any database field in a Zoom box by pressing <Shift> +<F2>.
B. Microsoft Access is a spelling genius and even recognizes the names of people,
places, and products.
C. In Microsoft Access, the <Tab> key moves to the next field and <Shift> + <Tab>
moves to the previous field.
D. You can add and edit information in tables, forms, and some queries.
Homework
1. Start Microsoft Access and open the Homework database.
2. Open the Science Test Answers table.
3. Without counting by hand, how many records are currently in the Science Test
Answers table?
4. Use the record navigation buttons to navigate between the records in the Science Test
Answers table.
5. Add a new record to the table: Click the New button on either the table
navigation button area or on the toolbar.
6. Enter the following information into the new record:
Grade Score Class Answer
5th C- Science Liter: A nest of young puppies.
7. Change the score of the previous record from a C- to a D+.
8. Select the previous record by clicking its record selector, then delete the record by
pressing the <Delete> key, and click Yes to confirm the deletion.
9. Close the Science Test Answers table and click No to the Save Changes message.
10. Click the Forms icon in the Objects bar and open the Test Answers form.
11. Enter the following information into a new record:
Grade Score Answer
8th D Germinate: To become a naturalized
German.
Quiz Answers
1. C. The columns in a Microsoft Access table are its fields.
2. B. Right-clicking an object displays a shortcut menu for the object.
Stop typing lists of information in Microsoft Word or Excel! In this chapter, you will learn
how to create databases that can store names, addresses, and any other type of information
that you can think of. You will be pleasantly surprised to find that creating a database isn’t all
that difficult. Microsoft Access even comes with a Database Wizard that takes you step by
step through the process of creating a database.
Because there are so many components that constitute a database, this chapter will cover a lot
of ground—but thankfully not in great detail. In this chapter, you will learn to create and
modify the major database objects: tables, forms, queries, and reports. You will even learn
some basic database management tasks, such as how to delete and rename database objects
and how to repair and compress a database.
If all you need is a simple, easy-to-use database, look no farther than this chapter—more than
likely, everything you need to know about creating databases is here.
68 Microsoft Access 2003
Customers Invoices
ID Company Phone ID Invoice Date Cost
5 ACME Widgets (800) 555-1818 5 1006 4/5/98 14,000
20 Green Tea Inc. (612) 555-7688 5 1201 3/1/99 5,000
5 1375 5/15/00 12,500
g
Here are some guidelines for creating a well-designed database:
• Determine the Purpose of the Database
in
The best way to do this is to write down a list of the reports and lists that you want to
come out of the database. This may seem a little backward at first, but if you think about
in
it, these reports are really the reason you’re creating the database. Make a list of the
reports and lists you want to see and then sketch some samples of these reports and
lists—be as detailed as possible. This will help determine the tables and fields to include
E tra
in your database.
• Determine the Fields You Need
This should be an easy step once you have determined the purpose of your database and
have sketched some sample reports and lists. Think about the data type for each type of
your fields—Will the field store text information? Numbers? Dates? Write down the data
UfSor
type next to each field.
• Determine the Tables You Need
Each table in the Database should be based on only one subject. By breaking each subject
into its own table you avoid redundant information and make the database more
organized. The second database in Figure 2-2 is broken down into two tables, Customers
Nd
and Invoices, so there isn’t any duplicated data. When you brainstorm, try to break down
LY IOse
your information as much as possible. If your tables contain fields like Item 1, Item 2,
Item 3, Item 3, and so on, you should probably break the information up into its own
table.
• Determine the Primary Key u
Each record in a table should have a primary key that uniquely identifies it. When you
think about a primary key field, think unique— each primary key value must be the only
T
ON Ae
one of its kind in a table. A customer ID or invoice number would be two good examples
of fields that could be used as a table’s primary key.
b
For example, in Figure 2-2, each record in the Customers table is related to one or more
records in the Invoices table.
N
Each field or column should contain This makes the table more meaningful, more organized,
the same type of information and easier to understand.
Try to break up information as much as This gives you more power to sort, filter, and manipulate
tFio
g
in
Lesson 2-2: Creating a Database
Using the Database Wizard
in
E tra
Figure 2-3
The New File task pane
appears each time you
start Access.
UfSor
Figure 2-4
The Databases tab of the
Templates dialog box.
To create a database based on a
Nd
template, select File → New from the
menu and click General Templates.
LY IOse
Figure 2-3
T u
ON Ae
U b
ALto
EVot
Figure 2-4
Other Ways to Use the If you’re just getting started with Microsoft Access, the easiest way to create a database is by
Database Wizard:
N
using one of the built-in database templates. A database template saves you time and effort,
• Click the New providing you with ready-to-use tables, forms, queries, and reports. There are templates
button on the toolbar, available for the most common types of databases, such as contact management, inventory,
click General and order taking. You can also modify a database created by the Database Wizard to better
OnR:
The Microsoft Access program appears with the New File task pane displayed, as
shown in Figure 2-3. The New File task pane gives you quick access to any database
you have worked on recently and allows you to create a new database.
al
2. Click General Templates in the task pane, and click the Databases tab.
The Templates dialog box appears, as shown in Figure 2-4. Here you need to select the
Ev
type of database you want to create. For this exercise we’ll create a Contact
Management database.
g
3. Double-click the Contact Management icon.
Access prompts you to type in a file name for your new database.
in
4. Type My Contacts and click Create.
The first screen of the Database Wizard appears and describes the database it will
in
create for you.
5. Click Next to continue.
E tra
The next screen of the Database Wizard appears. This dialog box displays the standard
tables and fields that the Database Wizard is building for you. Click a table on the left
side of the dialog box to view its fields on the right side. If you want, you can remove
the fields from the database by unchecking them. For this exercise we will leave the
standard fields as they are.
UfSor
6. Click Next to accept the Database Wizard’s standard tables and fields.
Next you have to decide what your new database should look like. Access provides you
with several aesthetic styles to choose from. Click a style to see a sample of what it
looks like.
7.
Nd
Browse the various styles by clicking each of them, then select the style
you like best and click Next.
LY IOse
Another screen and more aesthetic decisions to make. Here, you need to select the font
you want to use in your reports. You can preview each of the font styles by clicking
them.
8. u
Select the font style that you like best and click Next.
You’re just about done. The next step in the Database Wizard is entering the title of
T
your new database. This title will appear on the heading of all the reports in your
ON Ae
database. You can even add a graphic or logo to your reports by checking the “Yes, I’d
b
like to include a picture” box, clicking the Picture button, and selecting the picture or
graphic file.
U
That’s it—you’ve finished giving the Database Wizard all the information it needs to
create the database. Quick Reference
10. Click Finish to create the new database. To Create a Database
EVot
Access chugs along and creates the new database for you. When it’s finished, it will Using the Database
create a handy switchboard screen that makes it easy to access the database’s tables, Wizard:
forms, and reports. 1. Click the New button
N
11. Explore the tables, forms, and reports in the new database by clicking the on the toolbar.
various buttons on the switchboard form. Or…
OnR:
Move on to the next step when you have seen enough of the new database. Select File → New from
12. Close the new database by clicking Exit this database on the the menu.
switchboard form. 2. Click General Templates
tFio
create databases using the Database Wizard to serve as the foundation for a more customized
database. 4. Follow the onscreen
instructions and specify
what you what to appear
al
in your database.
Ev
g
in
Lesson 2-3: Creating a Blank
Database
in
E tra
Figure 2-5
The New File task pane.
Figure 2-6
UfSor
When you create a new
database, you must
specify its file name and
location.
Nd
LY IOse
Figure 2-5 T u Specify where you want to save the
database (in which drive and folder).
ON Ae
U b
ALto
EVot
N
OnR:
Can’t find a suitable database in the Database Wizard? Then you’ll have to create a blank
New button database and start from scratch. The advantage of creating a blank database is that it gives you
Other Ways to Create a the most flexibility and control over your database design. The disadvantage of creating a
blank database is that you have to create every table, form, report, and query yourself.
ua
New Database:
• Select File → New Here’s how to create a blank database.
from the menu.
1. Click the New button on the toolbar.
al
The File New Database dialog box appears. Before you can put anything into your new
database, you must first give it a file name and save it.
g
3. Navigate to the drive and folder where you want to save the new
database, then type My First Database in the File name box and click
in
Create.
Access creates a new database and saves it with the “My First Database” file name.
in
The Database window appears when it’s finished. If you click the various database
object tabs, you will notice that there aren’t any database objects in this database yet.
You will have to create all of the database yourself—something we will be doing in the
E tra
next several lessons.
UfSor
Nd
LY IOse
T u
ON Ae
U b
ALto
Quick Reference
To Create a New Blank
EVot
Database:
1. Click the New button
on the toolbar.
N
Or…
Select File → New from
the menu.
OnR:
Or…
Press <Ctrl> + <N>.
tFio
g
in
Lesson 2-4: Creating a Table
Using the Table Wizard
in
E tra
Figure 2-7
The Table Wizard lets you
create a table by adding These buttons add or
ready-made fields to it. remove the selected
UfSor
field to or from the
Check whether
table.
the table is for
business or
Each selected field
personal use.
appears here. To
remove a accidentally
Nd
Check the table
added field, double-
you want to
click the field. To
create.
LY IOse
remove all the fields at
once, click .
Figure 2-7 Displays fields for the table you
selected. Double-click each field you
T u want to add to the table. To add all the
fields at once, click .
ON Ae
If you’re new to Access, the easiest way to add a table to an existing database is with the
Table Wizard. The Table Wizard asks you a series of questions about which fields you want to
b
appear in your table and does the dirty work of creating a new table for you. The Table Wizard
can create a variety of different tables to store mailing lists, inventory, catalogs, and more.
U
ALto
clicking Create.
2. Click the Tables icon in the Objects bar if it is not already selected.
Access lists all the tables in the current database.
N
Tables icon
3. Double-click the Create table by using wizard icon.
The Table Wizard dialog box appears, as shown in Figure 2-7. This is definitely one of
OnR:
the more confusing dialog boxes in Access. The list in the far left of the dialog box
contains the sample tables from which you can choose.
You start the Table Wizard by selecting the sample table you want to use.
tFio
4. Click the Contacts sample table from the Sample Tables list.
The Table Wizard displays the ready-made fields that you can incorporate into your
table in the Sample Fields list. To add a field to your table, double-click the field or
ua
select the field and click the button. Click the button to add all the sample
fields to your table.
5. Double-click the ContactID field in the Sample Fields list.
al
The ContactID field appears in the Fields in my new table list. If you accidentally add
a field to the Fields in my new table list, you can remove it by double-clicking it or by
selecting it and clicking the button.
Ev
g
6. Add the following fields to your table by double-clicking them:
FirstName, LastName, Address, City, StateOrProvince, and
in
PostalCode.
You can easily change the field names in your new table if you don’t like the default
in
names given to them by the Table Wizard. Here’s how to rename a field:
7. Select the StateOrProvince field from the Fields in my new table list and
click Rename Field.
E tra
The Rename field dialog box appears. From here, renaming a field is pretty much self-
explanatory.
8. Replace the StateOrProvince text with State and click OK.
Once you have finished adding the fields to your table, you can move on to the next
UfSor
step in the Table Wizard.
9. Click Next.
The Table Wizard asks you to give your table a name and asks if you want to have
Access set a primary key for you. You will learn more about primary keys later on, so
Nd
for now let’s accept the Table Wizard’s default settings and create the table.
NOTE: If other tables exist in your database, another screen will appear, asking you
LY IOse
how this table relates to the other tables in your database.
10. Click Finish to create the new table.
The Table Wizard builds the table, using the fields you selected, and then opens the
u
new table—ready for your data input.
11. Close the Contacts table.
T
ON Ae
Table 2-2: Useful Sample Tables from the Table Wizard
b
Customers Stores all your customer or client information. To Create a New Table
Products Maintains a list of products that your company sells. Using the Table Wizard:
N
g
in
Lesson 2-5: Modifying a Table and
Understanding Data Types
in
E tra
Figure 2-8
A table in Design View.
UfSor
This area displays
the table’s field
names.
Nd
LY IOse
T u
ON Ae
Figure 2-8 This area displays the data type for Use this scroll bar
each field. Click the Data Type area for to browse through
b
list.
ALto
Once you have created a table, you can modify it later in Design View. Design View allows
you to change the structure of a table by adding, deleting, and modifying its fields.
Because there are so many different types of data, Access offers several different types of
EVot
fields. A field’s data type determines the type of information that can be stored in a field.
Table 2-3: Data Types lists the various data types available in Access. A field’s data type
restricts what type of information you can enter in a field. For example, you cannot enter text
N
name. To add a field in Design View, simply type a new field name in the first blank
Field Name box you find.
g
4. Type Birthday and press <Tab>.
New fields are text data-type fields by default. Here’s how to change a field’s data
in
type:
5. Click the Data Type area next to the Birthday field.
in
A down arrow appears on the right side of the Birthday’s Data Type box.
6. Click the Data Type arrow and select Date/Time from the list.
E tra
The new Birthday field will now only accept date and time information. The new Save button
Date/Time data type also makes your database more flexible and powerful because
Other Ways to Save a
now you can sort birthdays by date or use them in a calculation—for example, to Database Object:
determine a person’s age.
• Select File → Save
Once you have finished modifying a table you have to save your changes.
UfSor
from the menu.
7. Click the Save button on the toolbar to save your changes.
• Press <Ctrl> + <S>.
You’ve finished modifying the table, so…
8. Close the Contacts table.
Nd
Table 2-3: Data Types
LY IOse
Data Type Example Description
Text Legal Name: Stores text, numbers, or a combination of both, up to 255 Quick Reference
John Doe characters long. Text fields are the most common of all data To Display a Table in
Memo Notes:
T u
types.
Stores long text entries—up to 64,000 characters long (the
Design View:
• Open the table and click
ON Ae
Sally displays a equivalent of 18 pages of text!). Use memo fields to store the View button on
high amount of… notes or anything else that requires lots of space. the toolbar.
b
$84.95
To Change the Data Type
AutoNumber Invoice Number: Automatically fills in a unique number for each record. Many for a Field:
N
187001 tables often contain an AutoNumber field that is also used as 1. Display the table in
their primary key. Design View.
Yes/No Smoker?: Stores only one of two values, such as Yes or No, True or 2. Click the field’s Data
OnR:
Hyperlink Web Site: Stores clickable links to files on your computer, on the on the toolbar.
www.amazon.com network, or to Web pages on the Internet. Or…
Lookup Wizard Purpose of Trip: A wizard that helps you create a field whose values are • Select File → Save from
al
g
in
Lesson 2-6: Creating a New Table
from Scratch
in
E tra
Figure 2-9
Creating a table from
scratch in Design View.
UfSor
Enter the field
names for your
table here.
Nd
LY IOse
T u
ON Ae b
The Table Wizard is helpful if you’re new at building tables, but the more you start using
Access, the less you will probably want to use the Table Wizard. That’s because you will
know exactly what type of tables and fields your database needs and how to create them.
This lesson explains how to build your own tables from scratch. The most straight-forward
EVot
way to build a table is in Design View, where adding fields to a table and specifying their data
types is not much different than basic data entry.
N
1. Click the Tables icon in the Objects bar if it already isn’t selected, then
double-click the Create table in Design view icon.
OnR:
The new blank table appears in Design View. Now all you have to do is add the fields
you want included in the table. The table you will create in this exercise will track
telephone calls made to customers. Let’s add the first field.
2.
tFio
A down arrow appears on the right side of the Date Data Type box.
al
Ev
g
4. Click the Data Type arrow and select Date/Time from the list.
The Date field will now only accept date and time information. Let’s add the next field
in
to the table…
Save button
Other Ways to Save a
5. Press <Tab> two times and type Contact ID. Database Object:
in
In case you were wondering, the Description box you just tabbed past is used to • Select File → Save
provide users with online prompts and instructions. Anything you enter in a field’s from the menu.
Description box will appear in the Status bar whenever a user selects that field. We’ll
E tra
discuss the Description box in greater depth later on. • Press <Ctrl> + <S>.
The Contact ID field will indicate the contact that was called. Since the Contact ID
field will always be a number, you need to change its data type to numeric. A faster
way of changing a field’s data type is to type the first letter of the data type in the Data
UfSor
Type box. For example typing a ‘D’ would change the data type to Date. Table 2-4:
Data Type Shortcuts lists these keyboard shortcuts.
6. Press <Tab>.
The Data Type box should be selected. Try typing in the data type this time.
7.
Nd
Type N in the Data Type box.
“Number” appears in the Data Type box.
LY IOse
8. Complete the table by entering the following field names and data types:
Field Name Data Type
Phone
Comments
T u
Text
Memo
ON Ae
FollowUp Yes/No
Make sure that you press <Tab> after each field. If you make a mistake, you can either Quick Reference
b
click the field you want to edit or press <Shift> + <Tab> to move back to the previous
To Create a Table from
U
field.
Scratch:
ALto
Once you have finished modifying a table, you have to save your changes. Quick Reference
1. From the database
9. Click the Save button on the toolbar to save your changes.
Towindow,
Create aclick the from
Table Tables
Access asks you to give your new homemade table a name. icon in the Objects bar
Scratch:
10.
EVot
2. Type
and thena field name in the
double-click the
Field Name column.
Create table in
Design<Tab>,
3. Press View icon.
click the
OnR:
Text T AutoNumber A
4. Repeat
DataSteps
Type 2listand 3 as
arrow
Memo M Yes/No Y necessary
and select to add new
a data type for
fields
the to the table.
field.
Number N OLE Object O
ua
4. Repeatthe
5. Close table2window.
Steps and 3 as
Date/Time D Hyperlink H 6. necessary
Click Yes totosave add new
the
Currency C Lookup Wizard L fields
table, to the atable.
enter table name,
and then
5. Close theclick
tableOK.
window.
al
7.
6. Click No when Access
Yes to save the
asks ifenter
table, you want
a tableto create
name,
Ev
a primary
and key now.
then click OK.
g
in
Lesson 2-7: Creating a Query in
Design View
in
E tra
Figure 2-10
The Show Table dialog
box.
UfSor
Figure 2-11
The Query window in
Design View.
Nd
Figure 2-12
Figure 2-10
The design grid.
LY IOse
Field list Table name
Most of the time the fastest and easiest way to create a query is in Design View. Here’s how:
The Show Table dialog box appears, as shown in Figure 2-10. You have to select the
table or query you want to use.
Ev
g
3. Click the Employees table and click Add.
When you have finished adding the tables and/or queries to your new query, you can
in
close the Show Table dialog box. Run button
4. Click Close.
Other Ways to Run a
Query:
in
The Query window appears in Design View, as shown in Figure 2-11. Notice that the • Open the Query from
window is split. The top half contains a box labeled Employees, which displays all the the Database window.
fields in the Employees table. The bottom half of the screen contains a design grid,
E tra
which is where the information goes. • Click the
Datasheet View
You add the fields you want to appear in your query to the design grid in two ways:
button on the toolbar.
• By double-clicking the field on the field list.
• Select Query → Run
• By clicking and dragging the field down to the design grid yourself.
UfSor
from the menu.
5. Double-click the LastName field and FirstName field in the field list.
Access adds the LastName and FirstName fields to the design grid.
Often you will have to use the field list’s scroll bar to scroll up or down the list in order
to find a field.
Nd
6. Scroll down the Employees field list and double-click the City field.
Quick Reference
To Create a Query in
LY IOse
Next you need to specify any criteria for the query. You type the criteria in the design
grid’s Criteria row. For this exercise you want to see only the records whose City fields Design View:
contain “London”—move on to the next step to add this criteria to the query. 1. From the database
7. Click the City column’s Criteria row and type London.
u window, click the Queries
icon in the Objects bar
If you want to use a field in the query, but you don’t want it to be displayed in the
and then double-click the
T
query results, uncheck the Show box for that field.
Create query in
ON Ae
8. Uncheck the Show box for the City field. Design view icon.
b
The query will still use the criteria you specified for the City field, but it won’t display 2. Select the table you want
the City field in the query results. You’ve created a simple query. Here’s how to save it: to add to the query and
U
9. Click the Save button on the toolbar, type London Query and click OK. click Add.
ALto
query, it is not displayed because you unchecked its Show box back in Step 8.
4. Double-click each field
Here is a smattering of criteria operators and examples to get you started: you want to include from
N
BETWEEN BETWEEN 1/1/99 AND 12/31/99 Finds records between 1/1/99 AND 12/31/99. 8. Click Yes to save the
query, enter a query
Ev
LIKE LIKE "S*" Finds text beginning with the letter “S.” You can name, and then click OK.
use LIKE with wildcards such as *.
g
in
Lesson 2-8: Modifying a Query
in
Figure 2-13
E tra
To select a field in Query
Design View, position the
mouse over the name of
the field you want to select
( changes to ) and To select a field, position the mouse
UfSor
over the top of the field you want to
click to select the field.
select ( changes to ) and click to
select the field.
Figure 2-14
To move a field to a Figure 2-13
Nd
different position in a
query, select the field,
LY IOse
then click and drag it to
the new location.
Figure 2-14
ALto
Quick Reference As with any database object, you can modify any existing query. This lesson explains how to
add and remove a field from a query and how to rearrange the fields in a query.
To Add a Field to a Query:
1.
EVot
• Double-click each field Make sure you have the London Query you created in the previous
you want to include from lesson open in Design View.
the field list. First, here’s how to remove a field from a query:
N
Or…
2. Position the mouse over the top of the City field ( changes to ) and
• Drag the field from the click to select the field.
field list onto the design
OnR:
7. Click the Run button on the toolbar to view the results of the query.
Close the query without saving any changes.
g
in
Lesson 2-9: Sorting a Query Using
Multiple Fields
in
E tra
Selecting the asterisk (*) in a
query is the same as selecting Figure 2-15
all of a table’s fields. First sort field Second sort field
Creating a sort that sorts
by LastName, then by
FirstName.
UfSor
Nd
Figure 2-15
This column is used for These columns will not be
LY IOse
display purposes but not displayed but are still used
for sorting purposes. for sorting purposes.
Tables normally display records in the order they were entered. Instead of working with a
table’s jumbled record order, you can create a simple query that sorts the table information
u Design View
and presents it in an ordered, easy-to-read display. You can sort records alphabetically, button
numerically, or chronologically (by date) in ascending (A to Z) or descending (Z to A) order.
T
ON Ae
You can also sort by multiple fields—for example, you could sort by LastName and then by
FirstName. This lesson will show that you can use a query to sort information in a table.
b
1. From the Database window create a new query in Design View that uses
U
Notice that an asterisk (*) appears at the top of the Employees field list. Selecting a
table’s asterisk (*) in a query is the same as selecting all its fields. Quick Reference
2. Double-click the asterisk (*) in the Employees field list. To Sort a Query Using
EVot
Access adds the asterisk to the design grid. Next you have to add the fields you want to Multiple Fields:
use to sort the query. 1. Open/display the query in
3. Double-click the LastName field and the FirstName field to add them to Design View.
N
query, click the Sort row for the field you want to use to sort the query and select either
Ascending or Descending. grid.
4. Click the LastName field’s Sort Row and select Ascending. Do the 3. Click the Sort box
tFio
same for the FirstName field. list arrow for the first field
The LastName and FirstName fields will already be displayed with all the other fields you want to use to sort
in the table because you added the asterisk (*) to the design grid. Because you don’t the query and select a
want the LastName and FirstName fields to appear twice, you can uncheck the sort order.
ua
LastName and FirstName fields Show boxes. 4. Repeat Steps 2-3 for
5. Uncheck the Show box for the LastName field and FirstName field. each additional field you
want to use to sort the
The query will still use the LastName and FirstName fields for sorting purposes but it query, bearing in mind
al
won’t display these field names in the query results. that the fields will be
6. Save your query as AZ Query and then click the Run button on the sorted from left to right.
Ev
toolbar to view the results. Close the query when you’ve finished.
g
in
Lesson 2-10: Developing AND and
OR Operators
in
E tra
Figure 2-16 To create an AND
statement, list each criteria
To create an AND on the same line. This query
statement, simply list each will display records that
criteria on the same line. contain “Owner” in the
UfSor
ContactTitle field and
Figure 2-17 “France” in the Country
Figure 2-16 field.
To create an OR
statement, simply list each
Nd
criteria on its own line. To create an OR statement,
list each criteria on different
Figure 2-18 lines. This query will display
LY IOse
records that contain
The results of the AND “Mexico” or “France” in the
Country field.
query.
Figure 2-17 u
Figure 2-19
The results of the OR
T
ON Ae
query.
U b
ALto
EVot
The longer you work with Access, the more you will want to analyze your data. Before long
N
you will want to create queries that match two or more conditions, such as “Which people
have bought our cigarettes AND have contracted lung cancer?” You will also, at some time,
want to create a query that matches only one of several conditions, such as “Which people
OnR:
two:
• AND narrows your query, making it more restrictive. For example, you could filter for
employees who are from Washington AND who had been with the company for more
than five years. To create an AND query, enter the criteria for the fields on the same
ua
criteria for the fields on different Criteria rows of the design grid.
The terms AND and OR operators may sound like they belong to the frighteningly technical
Ev
world of programming, but if you already have a basic understanding of queries, they are
remarkably easy to use.
g
1. Open the Customers List query in Design View.
Remember: To open any database object in Design View, simply select the object and
in
click the Database window’s Design button.
The Customers List query appears in Design View. For this exercise you want to find
in
which of your customers are from France AND own their own business. You will need
to create an AND query because the ContactTitle field must equal “Owner” and the
Country field must equal “France.” To create an AND query, simply list each criteria
E tra
on the same line, as shown in Figure 2-16.
2. Click the ContactTitle column’s Criteria row and type Owner.
This will retrieve records whose ContactTitle equals “Owner.” Next you have to enter
the country criteria.
3.
UfSor
Click the Country column’s Criteria row and type France.
Because you entered the Country criteria in the same Criteria row as the ContactTitle
criteria, Access will treat it as an AND statement. (Which of my customers is an owner
AND is from France?)
Move on to the next step to view the results of your first AND query.
Nd
4. Click the View button on the toolbar.
LY IOse
Access displays the results of the query, as shown in Figure 2-18. Notice that the
results match your queries’ AND criteria—all the records have “Owner” in the
ContactTitle field and “France” in the Country field.
5.
u
Next we’ll modify the query and create an OR statement.
Switch to Design View by clicking the View button on the toolbar.
T
ON Ae
You’re back in Design View. First let’s remove the Owner criteria from the query.
6. Delete the “Owner” criteria from the ContactTitle column’s Criteria row.
b
This time you want to find which of your customers are from France OR are from
U
Mexico. You will need to create an OR query to find these records. To create an OR
ALto
query, simply list each criteria on its own line, as shown in Figure 2-17.
7. Click the second Criteria row for the Country column and type Mexico. Quick Reference
Because you entered each criteria in a different row, Access will treat it as an OR To Create AND/OR
statement. (Which customers are from France OR are from Mexico?) Criteria:
EVot
Move on to the next step to view the results of your OR query. 1. Open/display the query in
8. Click the View button on the toolbar. Design View.
N
Access displays the results of the query, as shown in Figure 2-19. Notice that the 2. Enter your criteria in the
results match your queries’ OR criteria—all the records have either “France” OR appropriate field’s first
“Mexico” in the Country field. Criteria box.
OnR:
9. Click the Save button on the toolbar to save your work and close the 3. Enter additional criteria as
follows:
query window.
AND: Enter additional
tFio
g
in
Lesson 2-11: Creating a Form with
the Form Wizard
in
E tra
Figure 2-20
Step One: Select the fields
you want to appear in your
form.
UfSor
Figure 2-21
Step Two: Select a layout
for the form.
Nd
Figure 2-22
LY IOse
Step Three: Select a style
Figure 2-20 Figure 2-21
for the form.
Figure 2-23
The completed form.
T u
ON Ae
U b
Figure 2-23
ALto
Figure 2-22
EVot
You will usually want to use the Form Wizard to create your forms. It’s almost always easier
to create and modify a form created by the Form Wizard than it is to create one from scratch.
N
This lesson will show you how to use the Form Wizard to create a form.
1. Click the Forms icon in the Objects bar if it isn’t already selected, then
double-click the Create form by using wizard icon.
OnR:
Forms icon The Form Wizard appears, as shown in Figure 2-20. Anytime you create a form, you
have to tell Access which table or query you want to use for your form.
2. Click the Tables/Queries list and select Table: Employees.
tFio
Now that you have specified the table, you tell the Wizard which fields you want to
display on the form. To add a field, double-click the field or select the field and click
the button. Click the button to add all the fields to your form.
ua
g
5. Click Next.
If you had selected fields from more than one table, the Form Wizard would ask how
in
you would like to organize the data on your form. The Form Wizard doesn’t ask us this
question, however, since we are creating a form based on a single table.
in
Next the Form Wizard asks how you want to display the data on the form, as shown in
Figure 2-21. You have six layout choices:
• Columnar: Displays one record at a time in an easy-to-read format.
E tra
• Tabular: Displays many records at a time.
• Datasheet: Displays many records at a time and looks exactly like a table in
Datasheet View.
• Justified: Displays one record at a time in a format similar to a tax return—
UfSor
interesting, but it usually creates complicated forms that are difficult to work
with.
• PivotTable: New in Access 2003, PivotTables dynamically summarize and
analyze information into an easy-to-understand report. PivotTables are
Nd
especially useful for seeing the bottom line in a large amount of information.
• PivotChart: Also new in Access 2003, PivotCharts also dynamically
LY IOse
summarize and analyze information, but by using a chart instead of a table.
The Form Wizard will select the layout option it thinks is best for your data. Keep in
mind—the Form Wizard isn’t very bright.
6. Click Next.
T u
For this exercise, we will use the default Columnar option.
ON Ae
Next the Form Wizard offers some interesting color styles you can use in your form, as
shown in Figure 2-22. Simply click a style to preview it.
b
NOTE: Some of the color styles can slow down the performance of your forms. Try to
U
7. Click and preview each of the styles. When you’re finished, click the
Standard style and click Next. To Create a Form Using
The final window of the Form Wizard appears—you have to give your form a name. the Form Wizard:
8.
EVot
Type Employees Form in the text box and click Finish. 1. From the database
window, click the Forms
After a few moments, your new form appears on screen, as shown in Figure 2-23. You
icon in the Objects bar
don’t have to worry about saving your new form—the Form Wizard does this for you
N
g
in
Lesson 2-12: Creating a Report
with the Report Wizard
in
E tra
Figure 2-24
Step One: Select the fields
you want to appear in your
report.
UfSor
Figure 2-25
Step Two: Select how you
want your fields to be
Nd
grouped.
Figure 2-26
LY IOse
Figure 2-24 Figure 2-25
Step Three: Select a
layout for your report.
Figure 2-27
u
The new report.
T
ON Ae
U b
ALto
Figure 2-27
Figure 2-26
EVot
Even more so than the Form Wizard, the fastest and easiest way to create a report is with the
N
Report Wizard. It’s almost always easier to create and modify a report created by the Report
Wizard than it is to create one from scratch.
1. Click the Reports icon in the Objects bar and double-click the Create
OnR:
the button. Click the button to add all the fields to your report.
3. Double-click the CompanyName field in the Available Fields list.
The CompanyName field appears in the Selected Fields list. If you accidentally add a
al
field to the Selected Fields list, you can remove it by double-clicking it or by selecting
it and clicking the button.
Ev
g
4. Add the following fields to your table by double-clicking them:
ContactName, Address, City, and Country.
in
Compare your Report Wizard dialog box to the one in Figure 2-24 when you’re
finished.
5.
in
Click Next.
The Report Wizard asks you if and how you want to group the data in your report, as
shown in Figure 2-25. For example, you can group all the customers from the same
E tra
country together in your report. Grouping can help organize and summarize the
information in your report. To use a specific field to group data, double-click the field
you want to use. For this exercise, we’ll group our report data using the Country field.
6. Double-click the Country field in the list.
UfSor
The Country field appears on top of the sample report to show how Access will group
the data in the report. If you change your mind, simply double-click the grouping field
at the top of the sample report to remove it.
7. Click Next.
Nd
Next the Report Wizard asks if you want to sort the records in your report. Simply
select the field you want to use to sort the records. You can click the button to the right
LY IOse
of each list to toggle between ascending and descending sort orders.
8. Select CompanyName from the list and click Next.
Next the Report Wizard asks how you want to display the data on the report. Click a
u
layout option to see it previewed on screen. You also specify the page orientation here.
NOTE: If you’re trying to get a lot of fields onto your report, consider using
T
Landscape orientation, which lays the page along its longest side. Quick Reference
ON Ae
9. Select the Align Left 1 option and click Next. To Create a Report Using
b
Next the Report Wizard offers some interesting styles you can use in your report. the Report Wizard:
Simply click a style to preview it on screen.
U
Select Corporate style and then click Next. window, click the Reports
You need to give your new report a name. icon in the Objects bar
11. Type Customers by Country in the text box and click Finish.
and then double-click the
Create reports by
EVot
After a few moments, your new report appears on screen, as shown in Figure 2-27. You using wizard icon.
don’t have to worry about saving your new report—the Report Wizard does this for
2. Select the table or query
you automatically as part of the report creation process.
you want to use to create
12.
N
g
in
Lesson 2-13: Creating Mailing
Labels with the Label Wizard
in
E tra
Figure 2-28
Step One: Select the table
or query to use for your
labels.
UfSor
Figure 2-29
Step Two: Select the
product number for your Figure 2-28
Nd
Avery labels.
Figure 2-30
LY IOse
Step Four: Select the Figure 2-29
fields and enter the text
you want to see on your u
labels.
T
Figure 2-31
ON Ae
The completed labels.
U b
ALto
EVot
For bulk mailings, nothing beats a good stack of mailing labels. The Access Label Wizard
helps you quickly create labels for any number of uses: mailing labels, name tags—even
labels for your floppy disks! The Label Wizard supports a huge variety of label sizes and
OnR:
New button
fields you want to use in your report.
Ev
g
4. Select Customers from the table or query drop-down list and click OK.
The first screen of the Label Wizard appears, as shown in Figure 2-29. If you’re using
in
Avery labels, the Label Wizard lists the various types of labels by product number.
Simply scroll down and find the number that matches the one on your label box. If
in
you’re not using Avery labels, you may have to click the Customize button and tell the
Label Wizard how to set up your nonstandard labels.
NOTE: Save yourself time and headaches and always make sure to buy Avery or
E tra
Avery-compatible labels.
5. Make sure that the Unit of Measure is set to English, and then select 5161
from the list and click Next.
The next window of the Label Wizard lets you change the font used in your label. You
UfSor
can format the font type, size, weight, and color. If you’re satisfied with the default
font (Arial 8 point), you can simply click Next.
6. Click Next to accept the default font.
It’s time to tell the Label Wizard which fields you want to use, as shown in Figure
Nd
2-30. You’ve done this before: Double-click a field to add it or select the field and click
the button.
7.
LY IOse
Double-click the ContactName field in the Available fields list.
The ContactName field appears in the Prototype label. OK, there’s a slight twist to the
Label Wizard. The Label Wizard creates labels exactly how you tell it to. So if you
row.
T u
want to place fields on separate rows, you need to press <Enter> to move to the next
Use the backspace key to delete a field from the Prototype label if you make a mistake.
ON Ae
8. Press <Enter>, double-click the CompanyName field in the Available
b
fields list, press <Enter>, double-click the Address field, and press
<Enter>.
U
If you want a character or text to appear on your labels, you’ll need to type it in. For
ALto
example, in the next step you will have to type in the comma and space between the Quick Reference
City field and the Region field. To Create Labels:
9. Double-click the City field, type a , (comma) followed by a <Spacebar>, 1. From the database
EVot
double-click the Region field, press <Spacebar>, and double-click the window, click the Reports
PostalCode field. icon in the Objects bar,
When you’re finished, compare your prototype label to the one in Figure 2-30, then click the New button in
N
you want to use to sort the labels. 2. Select the table or query
you want to use to create
11. Double-click the PostalCode field and then click Next. your labels and click OK.
tFio
The final window of the Label Wizard appears. All you have to do now is give your 3. Select the product
new report a name. number for your labels
12. Type Customer Labels in the text box and click Finish. and click Next.
ua
After a few moments, your labels appear on the screen, as shown in Figure 2-31. You 4. Select the fields that you
don’t have to worry about saving your new labels—the Label Wizard does this for you want to appear on the
automatically as part of the report creation process. report and enter any text.
Click Next when you’re
al
NOTE: Depending on your computer’s printer setup, Access may warn you that some
finished.
data may not be displayed. Go ahead and click OK.
13. Close the report.
5. Give your report a name
Ev
g
in
Lesson 2-14: Database Object
Management
in
E tra
Figure 2-32
The Paste Table As dialog
box.
UfSor
Figure 2-33
Right-click any database
object to open a shortcut
menu that lists everything Figure 2-32
Nd
you can do to the object.
LY IOse
T u
ON Ae
Figure 2-33
b
Not only can you view, open, and modify database objects (tables, queries, forms, etc.) from
U
the Database window, you can also use it to cut, copy, paste, delete, and rename database
ALto
objects.
Naming Conventions
Intermediate and 1. Ensure that you’re at the Database window and click the Tables icon in
EVot
easy to identify database example, you might copy an Employees table so that you could create a new table
objects. You are strongly using its structure.
encouraged to use the You can use standard cut, copy, and paste procedures on any Microsoft Access
OnR:
following naming database object in the Database window. That’s right—the same cut and paste stuff you
convention as well, as it already know how to do with text works with tables, queries, forms, pages, and reports!
makes it easier to refer 2. Select the Employees table and click the Copy button on the toolbar.
tFio
to database objects in
On the surface nothing appears to happen—but Microsoft Access has copied the
expressions, macros, and
Employees table to the Windows clipboard. Move on to the next step and paste the
VB procedures.
copied Employees table.
3.
ua
Macro mcr mcrSales • Structure Only: Pastes only the structure or design of the table.
Module bas basSales • Structure and Data: Pastes the structure of the table and its data.
g
• Append Data to an Existing Table: Adds the copied records to an existing
table in the database.
in
For this exercise we just need to paste the structure of the Employees table.
5. Select the Structure Only option and click OK.
in
Access pastes the copied Employees table as a new Fired Employees table.
NOTE: You can also copy objects from one database to another using simple copy and
E tra
paste commands. Copy the database object, start another session of Microsoft
Access by clicking the Start menu and selecting Programs → Microsoft
Access, and open the destination database. Click the Paste button to paste the
copied object into the other database.
6. Double-click the Fired Employees table.
UfSor
Notice that there aren’t any records in the Fired Employees table because you specified
that you only wanted to copy the structure of the Employees table.
7. Close the Fired Employees table.
You can also rename a database object from the Database window. Here’s how:
Nd
8. Right-click the Fired Employees table, select Rename from the
shortcut menu, type Previous Employees and press <Enter>.
LY IOse
The Fired Employees table is now named Previous Employees. Finally, here’s how to
delete any database object. Database object
shortcut menu
9. Select the Previous Employees table and press the <Delete> key.
u
Confirm the deletion by clicking Yes.
T
Whenever you’re unsure or curious about what you can do with a database object, try right-
ON Ae
clicking it. A shortcut menu will appear with a list of commands related to the database object.
b
The following table contains some of the commands you’ll see on the database object shortcut
menu. Quick Reference
U
Copy Copies the selected object to the Windows clipboard. button on the toolbar,
enter a name for the new
Save As Saves the selected object to a new object within the current database. object, and click OK.
tFio
Export Exports the selected object to another Access database or to a different file To Rename an Object:
format. • Right-click the object,
select Rename from the
ua
Send To Sends the selected object to an e-mail recipient via Microsoft Outlook.
shortcut menu, and enter
Add to Group Adds the selected object to Favorites or a new group. a new name for the
object.
Create Shortcut Creates a shortcut on the Windows desktop to the selected object.
al
To Delete an Object:
Delete Deletes the selected object.
• Select the object and
Ev
g
in
Lesson 2-15: File Management
in
Currently selected folder or drive. Click the to Go back to Search the Create a Menu of file-
Figure 2-34 list and change drives or folders. the previous Web. new folder. management
E tra
folder. commands
The Open and Save As
dialog boxes’ toolbar.
Figure 2-35
Go up one Delete the Views: Change
Figure 2-34
UfSor
The Views list button lets folder or level. selected how files are
you change how files are file(s). displayed.
displayed in the Open or
Save As dialog boxes.
Nd
LY IOse
Files and folders are Displays information Displays detailed Displays a preview of
displayed in a list, about every file, such as information about the the selected file (when
u
allowing you to view as
many files as possible.
T its name and size. selected file. possible).
ON Ae
Figure 2-35
b
File management includes moving, copying, deleting, and renaming the files you’ve created.
Although it’s a little easier to work with and organize your files using Windows Explorer or
Open button
U
My Computer, you can also perform a surprising number of file-management chores right
ALto
from inside Microsoft Access 2003—especially with its new and improved Open and Save
dialog boxes.
The Open dialog box appears. The Open dialog box is normally used to open files, but
you can also use it to perform several file-management functions. There are two
N
different ways to access file-management commands from inside the Open or Save As
dialog boxes:
• Select a file and then select the command you want from the dialog box’s Tools
OnR:
menu.
Tools menu • Right-click a file and select the command you want from a shortcut menu.
2. Right-click the Rename Me file.
tFio
A shortcut menu appears with a list of available file-management commands for the
selected file.
3. Select Rename from the shortcut menu, type Home Budget, and press
ua
<Enter>.
You have just changed the name of the selected file from “Rename Me” to “Home
Budget.” Instead of right-clicking the file, you could have selected it and then selected
al
Rename from the Tools menu. Move on to the next step to learn how to delete a file.
4. Click the Home Budget file to select it and press the <Delete> key.
Ev
A dialog box appears, asking you to confirm the deletion of the Home Budget file.
g
5. Click Yes.
The Home Budget file is deleted. If you work with and create numerous files, you may
in
find it difficult to remember what you named a file. To find the file(s) you’re looking
for, it can help to preview your files without opening them.
6.
in
Click the Views button arrow and select Details.
The Open dialog changes the display of Access files in the Practice folder from List
View to Details View. Change back to List mode to display as many files in the
E tra
window as possible.
7. Click the Views button arrow, select List to display the files in List
View, and then close the dialog box by clicking Cancel.
UfSor
Table 2-7: File Shortcut Menu Commands
Command Description
Select Opens the selected file.
Open Inactive command.
File shortcut
Nd
New Inactive command. menu
LY IOse
Send To Depending on how your computer is set up, it lets you send the selected file
to a printer, to an email recipient, to a fax, or to a floppy drive.
Cut Used in conjunction with the Paste command to move files. Removes the
u
selected file from its current folder or location.
T
Copy Used in conjunction with the Paste command to copy files. Copies the
ON Ae
selected file.
b
Create Shortcut Creates a shortcut—a quick way to a file or folder without having to go to its
permanent location.
U
Quick Reference
ALto
Displayed:
• Click the Views button
arrow and select a view.
al
Ev
g
in
Lesson 2-16: Compacting and
Repairing a Database
in
E tra
Figure 2-36
Use the Compact and
Repair Database
command to clean up the
UfSor
database.
Nd
LY IOse
Figure 2-36
T u
ON Ae
Cars require maintenance to keep them running at their peak performance. Databases are no
different. Your Access databases require some routine maintenance to prevent and/or correct
b
problems and to keep them running at top performance. This lesson covers the two database
utility commands:
U
• Compact Database: When you delete a database object or record, it leaves behind an
ALto
empty hole where the object previously occupied. This isn’t a big deal unless, over time,
you have deleted lots of database objects and records. Compacting a database rearranges
how the database is stored and reduces its file size.
EVot
• Repair Database: Over time, normal wear and tear causes errors to appear in your
database, affecting its performance. Usually these errors are very minor and can easily be
fixed by repairing the database.
N
Quick Reference
Microsoft has combined compact and repair into a single command in Access 2003. When
To Compact and Repair a should you use the compact and repair command? If you have been busy adding, editing, and
Database: deleting records for a while or if your database seems buggy, seems sluggish, or is generating
OnR:
• Select Tools → error messages, it’s a good idea to run the Compact and Repair Database command. Here’s
how to compact and repair a database:
Database Utilities →
tFio
repairs any errors it finds. The amount of time it takes to repair or compact a database
depends on how large your database is, how long it’s been since you’ve last compacted
and repaired it, and how fast your computer is.
That’s all there is to compacting and repairing a database!
al
Ev
g
in
Lesson 2-17: Converting an Access
Database
in
E tra
Figure 2-37
Using the Convert
Database command.
UfSor
Quick Reference
To Convert an Old Access
Nd
Database to Access 2003:
LY IOse
1. Close any open
databases and select
Tools → Database
u Utilities → Convert
Figure 2-37 Database and select the
appropriate file format
T
Unlike other programs in the Microsoft Office XP suite, Access 2003 saves its files in a from the menu.
ON Ae
different format than previous Access 97 and 2000 databases. Thus you need to convert older
2. Browse to and double-
Access 97 and 2000 databases to the new Access 2003 format. This lesson explains how to do
b
Access 2003 database, you can erase the backup. the warning about version
incompatibility.
Once you’ve made your backup, move on to the next step.
2. To Convert an Access
N
2003 File Format from the menu. want to convert and select
The Database To Convert From dialog box appears. Here you need to browse to and Tools → Database
select the old Access database file you want to convert. Utilities → Convert
tFio
4. Browse to and double-click the old Access database file you want to Database and select the
convert. appropriate file format
from the menu.
Next you need to type a new name for the Microsoft Access 2003 database file.
ua
6. Click OK to acknowledge the warning about version incompatibility. converted database file
Microsoft Access converts the database to Access 2003 format. and click Save.
Ev
g
in
Chapter Two Review
in
Lesson Summary
E tra
Planning a Database
UfSor
• Know how to plan a good database design.
Nd
click the type of database you want to create. Follow the onscreen instructions and specify what
LY IOse
you what to appear in your database.
• To Create a New Table Using the Table Wizard: From the database window, click the Tables
ALto
icon in the Objects bar and then double-click the Create table by using wizard icon, then
select the type of table you want to create. Follow the onscreen instructions and specify what you
what to appear in your database.
EVot
or from the database window, click the Tables icon in the Objects bar, select the table, and click
the Design button.
OnR:
• To Change the Data Type for a Field: Display the table in Design View, click the field’s Data
Type box, click the Data Type list arrow, and select the data type.
• To Save Changes to a Database Object: Click the Save button on the toolbar, or select File
tFio
• To Create a Table from Scratch: From the database window, click the Tables icon in the Objects
bar and then double-click the Create table in Design View icon. Type a field name in the Field
Name column, press <Tab>, click the Data Type list arrow, and select a data type for the
al
field. Repeat the preceding steps as necessary to add additional fields. When you’re finished, close
the table window, click Yes to save the table, enter a table name, and then click OK.
Ev
g
Creating a Query in Design View
in
• To Create a Query in Design View: From the database window, click the Queries icon in the
Objects bar and then double-click the Create query in Design View icon. Select the table you
want to add to the query and click Add—repeat as necessary to add additional tables or queries.
in
When you’re finished, click Close. Double-click each field you want to include from the field list or
drag the field from the field list onto the design grid. In the design grid, enter any desired search
criteria for the field in the Criteria box and click the Sort box list arrow for the field and select
E tra
a sort order. Close the query window, click Yes to save the query, enter a query name, and then
click OK.
Modifying a Query
UfSor
• To Add a Field to a Query: Double-click each field you want to include from the field list or drag
the field from the field list onto the design grid.
• To Delete a Query Field: Click the top of the field you want to delete ( changes to ) and press
<Delete>.
Nd
• To Rearrange Fields: Position the pointer over the field ( changes to ) and then click and drag
the field to a new location.
LY IOse
Sorting a Query Using Multiple Fields
• To Sort a Query Using Multiple Fields: Open/display the query in Design View, and if necessary,
u
add the field you want to use to sort the query to the design grid. Click the Sort box list arrow
for the first field you want to use to sort the query and select a sort order. Repeat for each
T
ON Ae
additional field you want to use to sort the query, bearing in mind that the fields will be sorted from
left to right.
b
• To Create AND/OR Criteria: Open/display the query in Design View, enter your criteria in the
appropriate field’s first Criteria box. Enter additional criteria as follows:
AND: Enter additional criteria for one or more fields in the appropriate field’s Criteria box in the
same row.
EVot
OR: Enter additional criteria for one or more fields in the appropriate field’s Criteria box, using a
different row for each OR criteria.
N
the Objects bar and then double-click the Create form by using wizard icon. Select the table
or query you want to use to create your form, select the fields that you want to appear on the form,
and click Next when you’re finished. Select the type of form you want to create and click Next.
tFio
Select a format for your form and click Next. Give your form a name and click Finish.
• To Create a Report Using the Report Wizard: From the database window, click the Reports
icon in the Objects bar and then double-click the Create reports by using wizard icon. Select
the table or query you want to use to create your report and select the fields that you want to
appear on the report. Click Next when you’re finished. Specify the field(s) you want to use to sort
al
the report and click Next (optional) or select a field to group the report by and click Next (also
optional). Select a format for the report and click Next. Give your report a name and click Finish.
Ev
g
Creating Mailing Labels with the Label Wizard
in
• To Create Labels: From the database window click the Reports icon in the Objects bar, click the
New button in the Database window, and select the Label Wizard from the list. Select the table or
query you want to use to create your labels, and click OK. Select the product number for your
in
labels and click Next. Select the fields that you want to appear on the form, enter any text, and
click Next when you’re finished. Give your report a name and click Finish.
E tra
Database Object Management
• To Cut/Copy and Paste a Database Object: Select the database object, click the Cut button
or Copy button on the toolbar, click the Paste button on the toolbar, enter a name for the
new object, and click OK.
UfSor
• To Rename an Object: Right-click the object, select Rename from the shortcut menu, and enter a
new name for the object.
• To Delete an Object: Select the object and press the <Delete> key.
Nd
File Management
LY IOse
• Basic File Management in the Open Dialog box: Open the Open or Save As dialog boxes by
selecting Open or Save As from the File menu, right-click the file, and select the desired
command.
• u
To Change How Files Are Displayed: Click the Views button arrow and select a view.
T
Compacting and Repairing a Database
ON Ae
• To Compact and Repair a Database: Select Tools → Database Utilities → Compact and
b
• To Convert an Access Database: Close the database you want to convert and select Tools →
Database Utilities → Convert Database and select the appropriate file format from the menu.
Browse to and double-click the Access database file you want to convert. Type a name for the
EVot
converted Access database file and click Save. Click OK to acknowledge the warning message.
N
Quiz
OnR:
provides you with ready-to-use tables, forms, queries, pages, and reports.
B. Datasheet View lets you view and modify the structure of any database object.
C. The Table Wizard asks you a series of questions about what you want to appear in a
Ev
g
3. Which of the following is NOT a data type?
in
A. Text.
B. Number.
C. Picture/Graphic.
in
D. Date/Time.
4. You can add a field to a query without displaying it in the query results.
E tra
(True or False?)
5. Which of the following statements is NOT true? (Select all that apply.)
A. To add a field to a query, double-click the field from the field list.
UfSor
B. Selecting the asterisk (*) in a query is the same as selecting all of a table’s fields.
C. You can only specify one set of criteria for each query—for example, to display
customers from Texas AND from Minnesota you would have to create two separate
queries.
D. You can sort a query’s records by clicking the Sort box list arrow for the field you
Nd
want to use to sort the query and select a sort order.
LY IOse
6. The fastest and easiest way to create a form or report is with the Form
Wizard or the Report Wizard. (True or False?)
A. Just as you can with files, you can cut, copy, paste, rename, and delete Microsoft
U
B. Whenever you don’t know how to do something to a database object, right-click the
object. A shortcut menu listing everything you can do to the object will appear.
C. When entered in the criteria row of a query design grid, the expression <>"MN"
would display only those records equal to “MN.”
EVot
D. Avery labels are a nonstandard product and should never be used for mailing labels.
A. 512 characters.
B. There is no limit to how long a text field can be.
OnR:
C. 50 characters.
D. 255 characters.
tFio
g
11. Which of the following criterion would find records whose Personality field
does not equal “Nice”?
in
A. <> Nice.
B. NOT Nice.
in
C. IS NOT Nice.
D. <>"Nice".
E tra
12. What happens when you add the asterisk (*) from any Field List to a query?
A. The query uses the records from the table without displaying them.
B. The query sorts the table’s records in the order you specify.
C. The query will include every field from the table.
UfSor
D. The table will not include any fields from the table.
13. You want to sort a query by a table’s Last Name field. In order to do this,
the Last Name field MUST appear in the displayed results of the query.
(True or False?)
Nd
14. Where do reports and forms get their information from? (Select all that
LY IOse
apply.)
A. Tables.
B. Queries.
u
C. Forms.
D. Modules.
T
ON Ae
15. What is the first step in creating a form or report with the Form Wizard or
b
Report Wizard?
A. Selecting how the form or report should be formatted.
U
B. Selecting the underlying table or query on which you want to base the form or report.
ALto
Homework
N
3. Create a new table in Design View that contains the following fields:
Field Name Data Type
tFio
Last Text
First Text
Phone Text
ua
Age Number
4. Save the table as Phone Numbers.
al
5. Use the Forms Wizard to create and save a columnar form named InsuranceClaim,
using the Phone Numbers table as the data source.
Ev
6. Use the Reports Wizard to create and save a tabular report named InsuranceClaim,
using the Phone Numbers table as the data source.
g
Quiz Answers
in
1. C. Since there isn’t a Database Planning Wizard, you can’t use it to help determine
the structure of a database.
in
2. B. Design View lets you view and modify the structure of any database object.
Datasheet View lets you view the records in a table, query, or form in a grid format.
E tra
3. C. There isn’t a Picture/Graphic field in Microsoft Access, although OLE fields can
store pictures and graphics in addition to other files created with external programs.
4. True. You can include a field in a query without displaying it in the query results by
unchecking its Show box.
UfSor
5. C. You can specify additional AND / OR criteria in a query by entering them in the
appropriate AND / OR criteria rows.
6. True. Once you create a form or report using the Form Wizard or the Report Wizard,
you can modify it to better suit your needs.
Nd
7. False. The Label Wizard, included with Microsoft Access, makes creating mailing
LY IOse
labels a snap.
8. C and D. The expression <>"MN" would display only those records that are not
equal to “MN,” and Avery is the standard of the label industry.
u
9. D. A text field can have a maximum length of 255 characters.
T
10. B. The memo data field type is used long text entries of one or more sentences.
ON Ae
11. D.
b
12. C. Adding the asterisk (*) from a Field List is the same as adding every field from
the table.
U
ALto
13. False. You can sort the results of a query without displaying the field you used to sort
the query.
14. A and B. Reports and forms get their information from tables and queries.
EVot
15. B. The first step in creating a form or report with the Form Wizard or Report Wizard
is to select the underlying table or query for the form or report.
N
OnR:
tFio
ua
al
Ev
E tra
Finding, Filtering,
UfSor
and Formatting Data
Nd
LY IOse
Chapter Objectives: ; Prerequisites
• Find and replace database information • How to use menus,
u toolbars, dialog boxes,
• Sort table information in ascending or descending order and shortcut
keystrokes.
T
• Filter information by selection
ON Ae
• How to open and
• Filter information by form modify database
b
objects.
• Create an advanced filter
U
• Adjust the row height and column width in a datasheet database records.
As databases grow larger and larger, finding a specific record or group of records becomes
OnR:
harder and harder. Fortunately, Microsoft Access is equipped with an arsenal of Find, Sort,
and Filter commands that can track down and organize a table’s information in record time.
tFio
In this chapter you will learn how to use these commands. First, you’ll learn how to use the
Find command to look up a specific record. Next, you’ll learn how to sort information in a
table—in ascending or descending order. Then, you’ll learn all about filters: How they can
find and display only records that meet your criteria, such as customers from the state of
ua
Texas.
Once you’ve learned how to organize and sort all that information, you’ll learn how to make it
look more professional. This chapter explains how to format a datasheet to change its font and
al
appearance. You will also learn how to freeze and hide columns in a datasheet—an important
task if you need to view large amounts of information.
Ev
106 Microsoft Access 2003
g
in
Lesson 3-1: Finding and Replacing
Information
in
E tra
Figure 3-1
Type the data
The Find tab of the Find you want to find.
and Replace dialog box. Specify whether
UfSor
you want to
Figure 3-2 search a specific
field (faster) or all
The Replace tab of the the fields in the
Find and Replace dialog table (more
box. thorough).
Figure 3-1 Select one of the match types (described in
Nd
Table 3-1: Using the Match List Options).
LY IOse
Type the text you
want to find
here…
u
…and the text you
want to replace it
T
with here.
ON Ae b
Figure 3-2
U
ALto
Finding specific records or information in a large database would be like finding a needle in a
haystack if it weren’t for the Find feature. Find allows you to quickly search tables, queries,
and forms for specified text—a critical database task. Select a field to search through all
records in the current field only. This is usually quicker, especially if the field is indexed. Or
EVot
select the datasheet or form to search through all fields in all records.
The Find and Replace feature is very useful. Imagine you are working on a huge database that
tracks the feeding patterns of squirrels. You’re almost finished when you realize that you’ve
N
instance of “Sciuridae Sciurus” in your database and replace it with “Sciuridae Glaucomys.”
Or it could take you less than a minute if you use Access’s Find and Replace function.
tFio
1. Start Microsoft Access, open the Lesson 3 database, and then find and
Find button open the Employees table.
Other Ways to Find First you need to put the cursor in the field that contains the data you want to look for.
Information:
ua
g
4. In the Find What text box type Redmond. Other Ways to Find and
Also important are the following options: Replace Information:
in
• Look In combo box: Allows you to search only the current field (which is • Press <Ctrl> + <H>.
faster) or all the fields in the entire table (which is slower).
in
• Match combo box: See Table 3-1: Using the Match List Options for a
description of the Match combo box and its options. Quick Reference
E tra
• Search combo box: Allows you to search up or down from the insertion To Find Information:
point or search the whole document.
1. Click the Find button
• Match Case check box: Finds only text that has the same pattern of on the toolbar.
uppercase and lowercase characters as the text you specified.
Or..
•
UfSor
Search Fields as Formatted check box: Check to search based on the
format rather than the value. Press <Ctrl> + <F>.
5. Click the Find Next button. Or…
Access jumps to the first (and only) occurrence of the word “Redmond” that it finds in Select Edit → Find from
the table. the menu.
Nd
6. Click Cancel. 2. Enter the text you want to
search for in the Find
LY IOse
The Find and Replace dialog box closes. You can also replace information in a What text box.
database.
3. Click the Find Next
7. Click anywhere in the Title field and select Edit → Replace from the button.
menu. u 4. Repeat Step 3 until you
The Find and Replace dialog box appears with the Replace tab in front, as shown in find the text you’re looking
T
Figure 3-2. for.
ON Ae
8. In the Find What box text box type Sales Representative.
To Find and Replace
b
You want to replace every occurrence of the phrase “Sales Representative” with the Information:
phrase “Sales Associate.”
1. Select Edit → Replace
U
9. Select the Replace With text box by clicking it or by pressing the from the menu.
ALto
Access finds all the occurrences of the phase “Sales Representative” in the table and
replaces them with the words “Sales Associate.” search for in the Find
What text box.
NOTE: Think before you use the Replace All button—you might not want it to
N
The Find and Replace dialog box disappears and you’re back to your datasheet. Notice 4. Click the Find Next
how all the occurrences of the phase “Sales Representative” have been replaced by the button.
tFio
Match Description
occurrence that you want
Whole Field Finds only data that is exactly the same.
to replace.
Example: John finds John, but not Johnson, or Sue and John.
Or…
al
Any Part of Field Finds data anywhere in the field. Click Replace All to
Example: John finds John, Johnson, and Sue and John. search and replace every
occurrence of text in the
Ev
g
in
Lesson 3-2: Sorting Records
in
++
Figure 3-3
E tra
A table is normally
displayed in the order its
records were entered.
Figure 3-4
UfSor
The table sorted by the
LastName field.
Nd
LY IOse
Figure 3-3
T u
ON Ae
U b
ALto
EVot
Figure 3-4
N
When you enter new records in a table they are added at the end of the table in the order you
enter them. Working with information in such a jumbled order can be difficult if not
impossible. Fortunately you can sort, or change the order of records in a table. You can sort
OnR:
records alphabetically, numerically, or chronologically (by date). Additionally, you can sort
information in ascending (A to Z) or descending (Z to A) order. This lesson will show you
several techniques you can use to sort information in your tables, queries, pages, and forms.
tFio
NOTE: If you frequently sort a table the same way, you should consider creating and using a
query that automatically sorts the table data for you. A query that sorts a table
alphabetically by name would be a good example of such a query.
ua
g
3. Click the Sort Ascending button on the toolbar.
Access sorts the table, ordering the records in ascending (A-Z) order by last name, as
in
shown in Figure 3-4. You can also sort a list in descending (Z-A) order.
4. Click the Sort Descending button on the toolbar.
in
The list is sorted in descending (Z-A) order by the LastName field.
Sort Descending
Let’s try sorting the table using a different field. button
5.
E tra
Click anywhere in the BirthDate field and click the Sort Ascending
button on the toolbar.
Access sorts the table by the BirthDate field and we instantly discover that poor
Margaret Peacock is the oldest employee in the company.
UfSor
Table 3-2: Sort Examples
Order Alphabetic Numeric Date
Ascending A, B, C 1, 2, 3 1/1/99, 1/15/99, 2/1/99
Nd
Descending C, B, A 3, 2, 1, 2/1/99, 1/15/99, 1/1/99
LY IOse
T u
ON Ae
U b
ALto
Quick Reference
EVot
on the toolbar.
ua
al
Ev
g
in
Lesson 3-3: Filtering by Selection
in
Figure 3-5
E tra
Filtering a table by
selection.
Figure 3-6 Right-click the field
value that contains the
UfSor
The table is filtered so that filter criterion and
only records that have select Filter By
Selection.
“WA” in the Region field
are displayed.
Nd
LY IOse
Figure 3-5
Sometimes you may want to see only certain records in your table. By filtering a table, you
display only the records that meet your criteria and hide the records that do not. For example,
you could filter a client list to display only clients who live in California.
tFio
• Advanced Filter/Sort: The most powerful and complicated filter method. Creating an
advanced filter is really not any different from creating a query.
Ev
In this lesson, you will learn how to use the fastest and easiest way to filter a list with the nifty
Filter by Selection feature.
g
1. If it isn’t already open, find and open the Employees table. Other Ways to Filter by
The first step is finding a record and field that matches your criterion. For example, to Selection:
in
find all the addresses from Minnesota you would put the cursor in any State field that • Select the record and
contained MN. field that matches your
2.
in
Find the Region field and then right-click any WA value. criterion and click the
Filter by Selection
A shortcut menu with the Filter by Selection command appears, as shown in Figure
3-5. Notice that the shortcut menu actually contains four filter-related commands: you button on the toolbar.
E tra
can read more about these other commands in Table 3-3: Filter Shortcut Menu
Commands.
3. Select Filter By Selection from the shortcut menu.
Access filters the table so that only records that contain “WA” in the Region field are
Apply/Remove
UfSor
displayed, as shown in Figure 3-6. Notice that the bottom of the table window tells you
Filter button
the number of records that match your filter criteria. Also the message (Filtered)
indicates that the table is currently being filtered.
Here’s how to remove a filter:
4. Click the Remove Filter button on the toolbar.
Nd
All the records in the table are displayed.
LY IOse
The opposite of Filter by Selection is Filter Excluding Selection, which filters all
records that don’t contain the criteria value. For example, to find all the addresses that Quick Reference
aren’t from Minnesota, you would put the cursor in any State field that contained MN.
To Filter by Selection:
5. u
Find the City field and then right-click any London value. Select Filter
1. Find the field value on
Excluding Selection from the shortcut menu.
which you want to base
T
This time Access displays all the records that do not contain London in the City field.
ON Ae
the filter.
6. Click the Remove Filter button on the toolbar. 2. Right-click the field value
b
All the records in the table are displayed. and select Filter by
Selection from the
U
The following table describes the filter commands that appear in the table shortcut menu. shortcut menu.
ALto
Or…
Table 3-3: Filter Shortcut Menu Commands
Click the field value, then
Command Description click the Filter by
EVot
Filter by Selection Finds and displays all records with the selected value. Selection button on the
toolbar.
Filter Excluding Selection Finds and displays all records that don't contain the selected value.
N
shortcut menu.
To Remove a Filter:
• Right-click the filtered
ua
toolbar.
g
in
Lesson 3-4: Filtering by Form
in
Figure 3-7
E tra
The Filter by Form
window.
If you specify more than
one criterion on the
same tab, Access treats
UfSor
it as an AND criteria,
meaning that a record
has to pass all the
criteria in order to be
displayed.
Nd
LY IOse
Figure 3-7 If you specify criterion on another OR tab, Click a field’s down arrow to
u
Access treats it as an OR criteria, meaning
that a record has to pass the criteria on
only one tab in order to be displayed.
T select a value from the field.
ON Ae
Filtering by Form makes it easy to create a filter that uses more than one criterion. The Filter
by Form window enables you to enter your filter criterion by picking values that you want the
b
If you look at Figure 3-7, you’ll notice that several tabs appear at the bottom of the Filter by
ALto
Form window. If you specify more than one criterion on the same Filter by Form tab, Access
treats it as an AND criteria statement, meaning a record must match all the criteria in order to
be displayed. For example, you could filter for employees who are from Washington AND
who had been with the company for more than five years.
EVot
If you specify filter criterion on different tabs, Access treats it as an OR criteria statement,
meaning a record has to match the criterion on one tab or the other to be displayed. For
N
The Filter by Form window, which looks like an empty replica of your table, appears
Filter by Form as shown in Figure 3-7.
The Filter by Form window may already contain a value from a previous filter. If that’s
not a field that you want to use in your filter, you can press <Delete> to clear the old
ua
criteria.
3. Press <Delete> to delete any old filter criteria.
Next you have to select the field and value you want to use as your criteria.
al
g
5. Click the City field arrow and select London from the list.
This will display only records whose City field contains “London.”
in
Apply/Remove
You can create an AND criteria statement by specifying more than one criterion on the Filter button
same Filter by Form tab. For example you could filter for employees who are from
in
London AND who have been employed since before 1994.
6. Click the Title field, click the Title arrow and select Sales Manager
from the list.
E tra
This will display only records for employees who are from London and whose title is
Sales Manager.
7. Click the Apply Filter button on the toolbar.
Access applies the filter and displays only those records whose City field equals
UfSor
“London” AND whose Title field equals “Sales Manager.” Only one record meets the
filter criteria. Let’s try modifying the query and adding an OR criteria statement.
8. Click the Filter by Form button on the toolbar.
If you have another set of criteria or rules to filter records by, click the Or tab at the
Nd
bottom of the Filter by Form window.
9. Click the Or tab at the bottom of the Filter by Form window.
LY IOse
Access displays another blank Filter by Form window. Access will search for any
criterion you enter on this tab in addition to your original criterion. You decide to filter
for records whose City field equals “London” AND whose Title field equals “Sales
10.
u
Manager” OR whose Title field equals “Vice President, Sales.”
Click the Title field and select Vice President, Sales from the list.
T
ON Ae
Notice that a new Or tab appears at the bottom of the Filter by Form window. You can
use as many “Or” statements as you need to define all your filter criteria.
b
Access applies the filter and displays records whose City field equals “London” AND
To Filter by Form:
whose Title field equals “Sales Manager” OR whose Title field equals “Vice President,
Sales.” Two records meet the filter criteria. 1. Click the Filter by
12. Click the Remove Filter button on the toolbar. Form button on the
EVot
toolbar.
Access once more displays all the records in the table.
2. Click the empty text box
Here are some criteria operators and examples you can use in your filters. below the field you want
N
LIKE LIKE "S*" Finds text beginning with the letter “S.” You can
use LIKE with wildcards such as *.
g
in
Lesson 3-5: Creating an Advanced
Filter
in
E tra
Field list Table name
Figure 3-8
The Filter window.
Double-click the field you
Figure 3-9
UfSor
want to appear in the design
grid or drag the field onto the
A close-up of the Design design grid yourself.
grid.
Nd
Design grid (See Figure 3-9
for closer look.)
LY IOse
Figure 3-8
T u Field names go here.
Figure 3-9
U
ALto
The most powerful filter is the Advanced Filter. The Advanced Filter is so powerful that you
can think of it as a baby query. In fact, the procedure for creating an Advanced Filter is
virtually the same as it is for creating a simple query. The problem with Advanced Filters is
that they can be difficult to set up the first few times—especially if you’re new to Access.
EVot
Advanced Filters have many advantages. They have the ability to:
• Sort by multiple fields: You can sort records using several fields. For example, you
N
could sort a table alphabetically by last name and then by first name.
• Use complex filter criteria and expressions: You can use advanced expressions
and operators to search for data. For example you could filter for dates that fall Between
OnR:
AND who had been with the company for more than five years.
This lesson explains how to get your own Advanced Filters up and running.
Clear Grid button 1.
ua
The Filter window appears, as shown in Figure 3-8. The Advanced Filter will probably
contain criteria from a previous filter that will have to be removed.
Ev
g
3. Click the Clear Grid button on the toolbar to clear the grid of any
preexisting criteria.
in
You’re ready to create your Advanced Filter. Notice in Figure 3-8 that the window is
split. The top half contains a box labeled Employees, which displays all the fields in
in
the current table. The bottom half of the screen contains a design grid, which is where
the filter information goes.
The first thing you need to do is select the fields that you want to use in your filter. You
E tra
can add fields to the design grid in two ways:
• By double-clicking the field on the field list.
• By clicking and dragging the field down to the design grid yourself.
Because the field list doesn’t have a lot of room you will usually need to use the field
UfSor
list’s scroll bar to scroll up or down the list.
4. Double-click the LastName field in the field list.
Access adds the LastName field to the design grid.
5. Add the FirstName, City, HireDate, and Region fields to the design
Nd
grid.
You can use any field on the design grid to sort or filter the table. To sort by a field,
LY IOse
click the Sort row in the column that contains the field that you want to sort and select
Ascending or Descending from the list.
6. Click the LastName column’s Sort row and select Ascending from the
u
drop-down list.
This will sort the table by the LastName field in Ascending order. You can also sort by
T
ON Ae
more than one field. For example, you could sort by LastName and then by FirstName.
When you use several fields to sort a table, Access performs the sort in the order the
b
To Create an Advanced
ALto
Next you need to specify the criteria for the Advanced Filter. You type the criteria in
the design grid’s Criteria row. Filter:
8. Click the City column’s Criteria row and type London. 1. Select Records → Filter
→ Advanced Filter/Sort
If you specify more than one criterion on the same Criteria row, Access treats it as an
EVot
Because it’s on the same Criteria row as the City field’s “London” criteria, the filter
will display only those records whose City field equals “London” and whose Hire Date field list onto the design
is after 1/1/93. grid.
tFio
If you specify filter criterion on different Criteria rows, Access treats it as an OR 3. In the design grid, enter
criteria statement, meaning a record has to match the criterion on one tab or the other any desired search
to be displayed. For example you could filter for employees from California OR criteria for the field in the
Minnesota. Criteria row.
ua
10. Click the Region column’s second Criteria row and type WA. 4. Click the Sort box
list arrow for the field and
Your completed design grid should look similar to the one shown in Figure 3-9. You’re
select a sort order
ready to try the Advanced Filter.
(optional).
al
11. Click the Apply Filter button on the toolbar to apply the filter.
5. Click the Apply Filter
The Advanced Filter window closes, and Access applies the filter and displays the button on the toolbar.
Ev
g
in
Lesson 3-6: Adjusting Row Height
and Column Width
in
E tra
Figure 3-10
Adjusting the width of a
column.
UfSor
Figure 3-11
The resized column.
Figure 3-12
Nd
Adjusting the height of a
row.
LY IOse
Figure 3-13 Figure 3-10 Figure 3-11
The resized row. Click and drag the line that
separates field names to change
T u
the width of a column.
ON Ae
U b
ALto
Access is usually pretty smart about how wide to make the columns of a table or query so
hopefully you won’t have to do much resizing. Sometimes, however, you will discover that
OnR:
some of the columns or rows are not large enough to display the information they contain.
This lesson explains how to change the width of a column and the height of a row.
1.
tFio
Carefully position the pointer over the right edge of the LastName field
until it changes to a .
Once the pointer is positioned over the column line and appears as a , you can adjust
the column width to make it narrower or wider.
al
3. Click and hold the mouse button and drag the line to the right about a
half-inch, as shown in Figure 3-10, then release the mouse button.
Ev
g
You can also have Access automatically adjust the width of a field or column so that it
can hold the widest entry. This neat feature is called AutoFit. To use AutoFit, simply
in
double-click the right edge of the column or field you wish to adjust.
4. Scroll to the right until the Address field is displayed. Double-click the
in
right edge of the Address field name to automatically adjust its width.
AutoFit automatically adjusts the width of the Address field so that it is wide enough to
display its longest entry.
E tra
Unless you are working with a table that contains several memo fields with lots of text,
you will probably want to stick with the default row height. The procedure for Quick Reference
adjusting the height of a row is almost the same as adjusting the width of a column—
simply click and drag the bottom of any record’s row heading. To Adjust the Width of a
5. Column:
UfSor
Move the pointer to the record selection area and carefully position the
pointer between any two records, until it changes to a . • Drag the column header’s
right border to the left or
Once the pointer appears as a you can adjust the row height to make it smaller or
right.
wider.
Or…
6. Click and hold the mouse button and drag the line down until the row
Nd
height doubles, as shown in Figure 3-12, then release the mouse button. • Right-click the column
header(s), select Column
LY IOse
The height of all the rows in the table is doubled.
Width from the shortcut
Splendid! In just one lesson you’ve learned how to adjust the width of columns and the height menu, and enter the
of rows in a datasheet. column width.
T u Or…
• Select the column
header(s), select Format
ON Ae
→ Column Width from
b
Row:
• Drag the row header’s
bottom border up or
EVot
down.
Or…
• Right-click the row
N
height.
Or…
tFio
To Automatically Adjust
the Width of a Column or
Row:
al
g
in
Lesson 3-7: Rearranging Columns
in
Figure 3-14
E tra
Moving a column to a new
location in the datasheet.
UfSor
Click any field
name and drag it
to its new
destination. Drag
to the left or right
of the window to
scroll the window.
Nd
LY IOse
Figure 3-14
u
When you first created a table, hopefully, you thought about its field order, so that most of the
T
time your data will appear in the order you want. Sometimes, however, you may want to
ON Ae
temporarily change the column order of a table.
b
This lesson explains how to move a field to a different location on the datasheet.
U
For this exercise, imagine that you have to call all the people listed in the Employees
table. The only problem is that you can’t view both the employee name fields and
Home Phone fields at the same time. To fix this problem, you decide to move the
EVot
1. Click the field name of Phone field name and hold down the mouse button.
the column you want to Now you have to drag the column to its new destination. If the destination is too far to
move. the left or right to appear on the screen, drag the column to the left or right of the
OnR:
2. Drag the selected column window—the datasheet will scroll in that direction.
to its new location. 3. Drag the Home Phone column to the far left of the window to scroll the
tFio
4. Drag the column to the left of the Region field and release the mouse
button to drop the column.
The Home Phone column and all its data moves next to the Region field.
al
Ev
g
in
Lesson 3-8: Changing Gridline and
Cell Effects
in
E tra
Select a cell effect for Clear these boxes to remove a Figure 3-15
your table. (Flat is the table’s gridlines (must be using the
default setting.) Flat cell effect). The Datasheet Formatting
dialog box.
UfSor
Select the color of
the table’s gridlines Figure 3-16
and background. Flat (Default)
Examples of the three cell
effect optio ns: Flat,
Raised, and Sunken.
Select the style of
Nd
the table’s lines and
borders.
LY IOse
Raised
Figure 3-15 T u
ON Ae
Sunken
b
Figure 3-16
U
Unless you are the type of person who likes to frequently change their Windows desktop
ALto
wallpaper or rearrange your bedroom furniture on a monthly basis, you can safely skip this
lesson. Changing the appearance of cells in a table is purely cosmetic and is probably one of
the least important things to know about Access.
Quick Reference
EVot
Are you still there? Okay, here’s how to give a table a three-dimensional look:
To Change a Datasheet’s
Gridline Effects:
1. If it isn’t already open, open the Employees table.
N
1. Select Format →
2. Select Format → Datasheet from the menu. Datasheet from the
The Datasheet Formatting dialog box appears, as shown in Figure 3-15. You can select menu.
OnR:
one of the 3-D effects from the Cell Effect area. See Figure 3-16 for an illustration of 2. Select the Cell Effect
each of these cell effects. option you want and click
OK.
You can also change the color of a table’s gridlines (the lines that separate the rows and
tFio
columns) and background as well as the border and line styles. Unless you have a
compelling reason for doing so, you should normally leave these settings as they are.
If you don’t want gridlines at all, set the Cell Effect to Flat and uncheck both of the
ua
g
in
Lesson 3-9: Freezing a Field
in
Figure 3-17
E tra
Freeze a field by right-
clicking the field name and
selecting Freeze Columns
from the shortcut menu.
UfSor
Figure 3-18
Information in the frozen
field remains on the
screen as you scroll and
move through the table.
Nd
LY IOse
Figure 3-17 Figure 3-18 This field is frozen and will remain
on the screen at all times.
u
Most tables have so much information that it won’t all fit on the same screen. When this
happens, you have to scroll through the datasheet to add, delete, modify, and view
T
ON Ae
information. The problem with scrolling and viewing information in a large table is that it can
be confusing when you can’t see such important information as names or product numbers.
b
To overcome this problem, you can freeze a field so it stays in the same place while you scroll
around the rest of the table.
U
ALto
the rest of the table. Try scrolling the table window to see for yourself.
• Right-click the column
field name you want to
3. Scroll the table to the right to view all its data.
freeze and select Freeze Notice how the frozen LastName field stays on the screen as you scroll the table,
OnR:
Columns from the allowing you to always be able to see the last name for each record. Now you’re ready
shortcut menu. to unfreeze the LastName field.
4. Select Format → Unfreeze All Columns from the menu.
tFio
To Unfreeze a Column:
All the fields in the table are now unfrozen.
• Select Format →
Unfreeze All Columns
from the menu.
ua
al
Ev
g
in
Lesson 3-10: Hiding a Column
in
Figure 3-19
E tra
Hide a field by right-
clicking the field name and
selecting Hide Columns
from the shortcut menu.
UfSor
Figure 3-20
The Unhide Columns
dialog box lets you check
and uncheck the columns
you wish to hide or
Nd
display.
Figure 3-19
LY IOse
Figure 3-20
A hidden column or field is still in your table—you just can’t see it. You can temporarily hide
u
a column when you want to reduce the amount of information that is displayed on the screen.
The procedure for hiding and unhiding a column is almost the same as freezing a column.
T
Here it is:
ON Ae
1. If it isn’t already open, open the Employees table.
b
Right-click the LastName field name and select Hide Columns from
ALto
then dragging to the last field name, but you will have to select Format → Hide
Columns from the menu. You can right-click any of the columns to display the shortcut To Hide a Column:
menu without deselecting the columns. • Right-click the column
N
When you want to make your hidden columns reappear try this: field name you want to
3. Select Format → Unhide Columns from the menu.
hide and select Hide
Columns from the
The Unhide Columns dialog box appears, as shown in Figure 3-20. To redisplay a
OnR:
shortcut menu.
column, simply click the check box next to the field you want to see again.
4. Click the LastName check box and click Close.
To Unhide a Column:
• Select Format → Unhide
tFio
g
in
Lesson 3-11: Changing the
Datasheet Font
in
E tra
Figure 3-21
The Font dialog box.
UfSor
Nd
This area displays a preview
of how the new font settings
LY IOse
will look.
Figure 3-21
u
Being a practical business program, Access displays its tables in a no-nonsense, easy-to-read
T
font. You can change the font used to display table data. You can make the text appear darker
ON Ae
and heavier (bold), slanted (italics), larger, and in a different typeface or color. Most people
are satisfied with the default font used in tables, and if you’re one of them, you may want to
b
One very important note about changing a table’s font: The font settings you make apply to
ALto
1.
EVot
The Font dialog box makes its entrance, as shown in Figure 3-21. To select a new font,
simply find and click it from the Font list.
3.
OnR:
Scroll down the Font list until you find Times New Roman. Click the
Times New Roman font.
The table data will now be displayed using the Times New Roman font.
tFio
NOTE: When selecting fonts always try to use a TrueType font. TrueType fonts are the
universal font standard used by Windows and they look great when printed.
TrueType fonts have a double-T icon next to them.
ua
Next try changing the font size. Font sizes are measured in points (pt.) which are 1/72
of an inch. The larger the number of points, the larger the font. Here’s how to change
font size:
4. Select 11 from the Size list.
al
Notice that the Sample area of the Font dialog box displays what your new font setting
will look like.
Ev
You’ve finished making changes to the font settings so move on to the next step.
g
5. Click OK to save your font-change settings and close the Font dialog
box.
in
The Font dialog box closes and Access displays the table with the new font settings.
Don’t like your new font settings? Don’t worry—you can always close a table without
in
saving your layout changes.
6. Close the Employees table without saving any of your layout changes.
E tra
There are several other font formatting options available in the Font dialog box. The purpose
of this lesson isn’t to go through all of them, but to explain how to use the Font dialog box.
You can experiment with the different font formatting options to see what they do. Table 3-5:
Font Formatting Options explains the different options in the Font dialog box.
UfSor
Table 3-5: Font Formatting Options
Option Description
Font Displays and allows you to change the font from those installed on your computer.
Font style Formats the style of the font: Regular (no emphasis), Italic, Bold, and Bold Italic
Nd
Size Displays and allows you to increase or decrease the size of the font.
LY IOse
Color Displays and allows you to change the font color.
Underline Allows you to add underlining to your fonts.
T u
ON Ae
U b
ALto
EVot
N
OnR:
tFio
ua
al
Ev
g
in
Chapter Three Review
in
Lesson Summary
E tra
Finding and Replacing Information
UfSor
• To Find Information: Click the Find button on the toolbar, or press <Ctrl> + <F>, or select
Edit → Find from the menu. Enter the text you want to search for in the Find What text box, and
then click the Find Next button until you find what you are looking for.
• To Find and Replace Information: Select Edit → Replace from the menu, or press <Ctrl> +
<H>. Enter the text you want to search for in the Find What text box, enter the text you want to
Nd
replace the word with in the Replace With text box. Click the Find Next button to move the first
occurrence of the text and click the Replace button to replace the text or click the Find Next
LY IOse
button to move the next occurrence of the text. Repeat if there is more than one occurrence that
you want to replace or click Replace All to search for and replace every occurrence of text in the
table.
Sorting Records
T u
ON Ae
• To Sort Records by One Field: Click anywhere in the column you want to use to sort the list, and
click either the Sort Ascending button or Sort Descending button on the toolbar.
b
Filtering by Selection
U
ALto
• To Filter by Selection: Find the field value on which you want to base the filter, right-click the field
value, and select Filter by Selection from the shortcut menu, or click the field value, then click the
Filter by Selection button on the toolbar.
EVot
• To Filter Excluding the Selection: Right-click the field value you want to exclude and select Filter
Excluding Selection from the shortcut menu.
• To Remove a Filter: Right-click the filtered table and select Remove Filter/Sort from the shortcut
N
Filtering by Form
OnR:
• To Filter by Form: Click the Filter by Form button on the toolbar, click the text box for the
field you want to filter, click the drop-down arrow, and select the value you want to use to filter
tFio
the records. Repeat this step for each additional field you want to use to specify additional filter
criteria—if you want to use Or criteria, click the Or tab at the bottom of the screen to specify the
additional filter criteria. Click the Apply Filter button on the toolbar.
ua
the field list onto the design grid. In the design grid, enter any desired search criteria for the field in
the Criteria row. Click the Apply Filter button on the toolbar.
Ev
g
Adjusting Row Height and Column Width
in
• To Adjust the Width of a Column: Drag the column header’s right border to the left or right. You
can also right-click the column header(s), select Column Width from the shortcut menu, and enter
the column width, or you can select the column header(s), select Format → Column Width from
in
the menu, and enter the column width.
• To Adjust the Height of a Row: Drag the row header’s bottom border up or down. You can also
E tra
right-click the row header(s), select Row Height from the shortcut menu, and enter the row height
or select the row header(s), select Format → Row Height from menu and enter the row height.
• To Automatically Adjust the Width of a Column or Row: Double-click the right border of the
column or bottom border of a row.
UfSor
Rearranging Columns
• To Move a Column: Click the field name of the column you want to move, then drag the selected
column to its new location.
Nd
Changing Gridline and Cell Effects
LY IOse
• To Change a Datasheet’s Gridline Effects: Select Format → Datasheet from the menu, select
the Cell Effect option you want, and click OK.
Freezing a Field u
• To Freeze a Column: Right-click the column field name you want to freeze and select Freeze
T
Columns from the shortcut menu.
ON Ae
• To Unfreeze a Column: Select Format → Unfreeze All Columns from the menu.
b
Hiding a Column
U
ALto
• To Hide a Column: Right-click the column field name you want to hide and select Hide Columns
from the shortcut menu.
• To Unhide a Column: Select Format → Unhide Columns from the menu.
EVot
Quiz
OnR:
in a database?
A. Click the Find button on the toolbar.
B. Select Edit → Find from the menu.
ua
g
2. The only way to find and replace information in Microsoft Access is with an
Update Query. (True or False?)
in
3. Which of the following is NOT true? (Select all that apply.)
in
A. Filter by Selection finds all records that match a selected value.
B. Filter Excluding Selection finds all records that do not match a selected value.
E tra
C. Filter by Form lets you enter your filter criteria in a blank form and works well so
long as you do not need to use multiple AND/OR criteria.
D. An Advanced Filter is similar to creating a simple select query.
UfSor
A. Display records between the dates 1/2/99 and 1/1/00.
B. Display records whose dates equaled 1/1/99 or 12/31/99.
C. Display records between the dates 1/1/99 and 12/31/99.
D. Do nothing – this criteria has not been entered using the proper syntax.
Nd
5. In an Advanced Filter, which of the following are ways you can add fields to
the design grid? (Select all that apply.)
LY IOse
A. Select the field from the Add Field List on the toolbar.
B. Double-click the field in the field list.
C. Select Edit → Add Field from the menu, select the field from the list, and then click
u
OK.
D. Drag and drop the field from the field list to the design grid.
T
ON Ae
6. The only way you can rearrange the order of fields in a datasheet is by
b
C. You can temporarily hide a field or column if you want to reduce the amount of
information that is displayed on the screen.
D. To hide a field, select the field and click the Hide Column button on the toolbar.
N
A. Click anywhere in the column and click the Freeze button on the toolbar.
B. Place an ice cube on the column.
C. Right-click the column and select Freeze Columns from the shortcut menu.
tFio
D. Click anywhere in the column and select Edit → Freeze Column from the menu.
B. Find the value on which you want to base the filter, right-click the field value, and
select Filter by Selection from the shortcut menu.
C. Find and select the value on which you want to base the filter and select Tools →
al
g
10. What is a fast way to adjust the width of a column?
in
A. Double-click the left side of the column heading.
B. Double-click the right side of the column heading.
C. Right-click the left side of the column heading.
in
D. Select Tools → Adjust Column Width from the menu.
E tra
Homework
1. Start Microsoft Access and open the Homework database.
2. Open the Customers table in Datasheet View.
UfSor
3. Click anywhere in the LastName field and find any customers with the last name
“Eller,”
4. With the cursor in the FirstName field, use the Find and Replace command to replace
every instance of the first name “John” with the first name “Jack.”
Nd
5. Use the Sort command to sort the Customers table by the LastName field, in
LY IOse
ascending order.
6. Use the Filter by Selection command to display only records from the state of Texas
(TX).
9. Create an Advanced Filter to display records for customers from “TX” or “MN” and
U
Hint: Use the following illustration as an example of how the Advanced Filter
should look:
EVot
N
OnR:
tFio
Quiz Answers
al
1. C. There are buttons to add and navigate records in the record navigation area,
however, there isn’t a Find button.
Ev
g
2. False. An Update Query can find and replace information in Microsoft Access (more
about that later) but so can the Find and Replace command, which you can use by
in
selecting Edit → Replace or pressing <Ctrl> + <H>.
3. C. Filter by Form is great for using multiple AND/OR criteria.
in
4. C. Displays records between the dates 1/1/99 and 12/31/99.
5. B and D. Both of these are ways to add fields to the design grid in an Advanced
E tra
Filter.
6. False. You can rearrange the order of fields in a datasheet by simply selecting them
and then dragging and dropping them to the new desired location.
7. D. To hide a field, simply right-click the column and select Hide Columns from the
UfSor
shortcut menu.
8. C. You can freeze a column by right-clicking the column and selecting Freeze
Columns from the shortcut menu.
9. B. You can filter a selection by finding the value on which you want to base the filter,
Nd
right-clicking the field value, and selecting Filter by Selection from the shortcut
menu.
LY IOse
10. B. Double-clicking the right side of a column automatically adjusts its width.
T u
ON Ae
U b
ALto
EVot
N
OnR:
tFio
ua
al
Ev
E tra
Working with Tables
UfSor
and Fields
Nd
LY IOse
Chapter Objectives: ; Prerequisites
• Understand and modify a table’s field properties • How to use menus,
u toolbars, dialog boxes,
• Index a field and add a primary key to a table and shortcut
keystrokes.
T
• Change a field’s data type
ON Ae
• How to open and
• Format how information is displayed in a field modify database
b
objects.
• Specify data validation options for a field
U
• Create a lookup field that lets you pick a field’s entry from a list of database records.
values
tables
N
Tables are by far the most important part of any database. Tables are where a database stores
all of its information. All the other database objects—queries, forms, reports, pages, and
macros—are merely tools to analyze, manipulate, and display the information stored in a
OnR:
table. Any of these other database objects are optional—but without tables, a database
wouldn’t be a database.
If you are interested in creating your own databases, this may be the one of the most
tFio
important chapters in the entire book. Why? Because, at their heart, the most useful and
efficient databases use well-structured tables to store their information.
This chapter explains just about everything you will ever need to know about tables and
ua
fields: how to link two or more related tables, how to create indexes for faster performance,
and how to create a primary key field, which uniquely identifies each record in a table. This
chapter also explains how to change all the properties and settings for your tables’ fields, such
as how they are formatted and what kind of information they can store.
al
Ev
130 Microsoft Access 2003
g
in
Lesson 4-1: Understanding Field
Properties
in
E tra
Figure 4-1
A comparison of a car’s The properties for The properties for this
properties with a field’s this car are: Field are:
properties. Color = Red Size = 2
UfSor
Doors = 2 Default Value = “MN”
Figure 4-2 Make = Toyota Required = No
Model = Corolla
You need to be in Design
View to view and change Figure 4-1
Nd
a table’s field properties.
LY IOse
T u Click the field name
whose properties you
want to view/change…
ON Ae
…and the properties for
b
Figure 4-2
N
for a numeric field might be the number of decimal places displayed or the maximum number
of characters a field can hold.
tFio
Just about every object in Access—every heading on a report, every label on a form, every
field in a table—has its own set of properties that you can view and change. This property
concept might seem a little confusing at first, but it’s something you have to learn if you want
to become proficient at using Microsoft Access. Because you can almost always change
ua
object properties, you can also sometimes think of an object’s properties as its settings.
Over half of this chapter is devoted to working with a table’s field properties so consider this
your introduction to field properties and to properties in general.
al
To view and modify the Field Properties for a table you need to open the table in
Design view.
g
2. Select the tblCustomers table and click the Database window’s
Design button.
in
As you can see in Figure 4-2, the table design window is broken into two sections. The Design button
top section contains the table’s field names and the bottom section displays the Other Ways:
in
properties for the selected field. Simply click the field name whose field properties you • Open the table and click
want to view. the Design View
3. Click the LastName field name. button on the toolbar.
E tra
The lower Field Properties section of the window displays the properties for the • Open the table and
LastName field. To change a field property, simply click the property box you want to select View → Design
change and enter the new settings—simple. View from the menu.
Table 4-1: Important Field Properties describes all the field properties. Don’t worry if some
UfSor
of them seem confusing—you will get a lot of practice adjusting each and every one of these
properties in this chapter. It’s important to note that certain types of fields have their own sets
of properties. For example, number fields have a Decimal Places property while text fields do
not.
Nd
Table 4-1: Important Field Properties
LY IOse
Field Property Description
Field Size Text fields: The maximum number of characters (up to 255) that can be
entered in the field. The default setting is 50.
u
Number / Currency fields: Stores the number as a Byte, Integer, Long Integer,
Single, Double, or Replication ID. The default setting is Long Integer.
T
ON Ae
Format How the data in the field will be displayed on the screen.
Input Mask Creates a format or pattern in which data must be entered.
b
Decimal Places The number of decimal places in Number and Currency fields.
U
ALto
Caption A label for the field that will appear on forms. If you don’t enter a caption,
Access will use the field name as the caption.
Default Value A value that Access enters automatically in the field for new records. Quick Reference
EVot
Validation Rule An expression that limits the values that can be entered in the field. To Display a Table in
Validation Text The error message that appears when an incorrect or restricted value is entered Design View:
N
Allow Zero Length Specify if the field allows zero-length text strings (a string containing no Or…
characters). Zero-length text strings are useful if you must enter data in a field,
but no data exists. For example, if a Social Security field requires data, but you • In the Database window,
click the Tables icon in
tFio
don't know the social security number, you enter a zero-length text string in the
field. To enter a zero-length text string type "" in the cell. The cell will appear the Objects bar, select the
empty. The default is No. table, and click the
Design button.
Indexed Specify if you want to index the field to speed up searches and sorts performed
ua
g
in
Lesson 4-2: Indexing a Field
in
3.1"3.1"
Figure 4-3
E tra
Adding an Index to a
table’s LastName field.
UfSor
you want to index.
Nd
LY IOse
2. Click the Indexed
drop-down list
u and select an
T index option .
Figure 4-3
ON Ae b
Just like an index in a book, when you index a field, it helps Access find and sort information
quickly, especially in large tables. You can index any field in a table to dramatically speed up
U
queries and sorts. When you sort or query a large table using an indexed field, Access finds or
ALto
sorts the information by consulting the index instead of sifting through the entire table.
Here are some more important notes about indexes:
• Since indexes speed up searching and sorting, you should index the fields you frequently
EVot
use to search or sort. For example, if you often search for specific last names, you should
create an index for the LastName field.
• Don’t index too many of a table’s fields. The more fields you index, the slower your
N
searches and sorts will be—defeating the entire purpose of indexes. Only index the fields
you use to search and sort data.
• Any field can be indexed except memo, OLE, and hyperlink fields.
OnR:
• Primary key fields are indexed automatically (we’ll discuss primary keys more in future
lessons).
tFio
• If you choose, indexes can prevent duplicate entries in your table (for example, if you
don’t want to allow two customers to have the same social security number).
This lesson will give you some practice adding indexes to your tables.
ua
1. Make sure you have the tblCustomers table open in Design View.
Indexing a field is a simple one- or two-step operation. First you need to click the name
of the field you want to index. The LastName field is a great index candidate because it
al
The blinking cursor should appear in the LastName field name. Here’s how to index
the selected field.
g
3. Click the Indexed drop-down list in the Field Properties section, as
shown in Figure 4-3.
in
The Indexed list gives you three choices:
• No: The field is not indexed. This is the default setting.
in
• Yes (Duplicates OK): The field is indexed and Access will allow records in
this field to have the same value.
E tra
• Yes (No Duplicates): The field is indexed and Access won’t allow records in
this field to have the same value (for example, if you don’t want to allow two
customers to have the same social security number).
Most of the time you will want to choose the Yes (Duplicates OK) option. Since people
may have the same last name the Yes (Duplicates OK) option is what you’ll want to
UfSor
use here.
4. Select the Yes (Duplicates OK) option from the Indexed list.
Most of the time Access creates the index in a matter of seconds. If you have a huge
table with thousands of records, it will take longer to create the index.
Nd
Let’s try indexing another field. Since you do a lot of sorting by Zip Codes, you decide
to index the ZipCode field as well.
LY IOse
5. Click the ZipCode field name and then click the Indexed drop-
down list.
Since people can (and do) live in the same Zip Code, you want to select the Yes
6.
(Duplicates OK) option.
u
Select the Yes (Duplicates OK) option from the Indexed list.
T
ON Ae
You don’t need to index any of the other fields in this table, since you don’t use them
as frequently in your sorts and queries. You do need to save the changes you’ve made
b
the table.
If you need to remove an index from a field, select the field, click the Indexed drop-down list
and select the No option. Access will delete the field’s index.
Quick Reference
EVot
To Index a Field:
1. Display the table in
N
the following:
• Yes (Duplicates OK) if
you want to allow multiple
ua
g
in
Lesson 4-3: Adding a Primary Key
to a Table
in
E tra
Figure 4-4
Create a primary key by
clicking the field you want
to use as the primary field 1. Select the field you
UfSor
want to use for your
and clicking the Primary table’s primary key.
Key button on the toolbar.
2. Click the Primary
Key button on the
toolbar.
Nd
LY IOse
Figure 4-4
T u
ON Ae
A key symbol ( ) appears by
the primary key field.
b
A primary key is a special kind of indexed field that uniquely identifies each record in a table.
U
When you think about primary key fields, think unique—each primary key value must be the
ALto
only one of its kind in a table. A customer ID or invoice number would be two good examples
of fields that could be used as a table’s primary key.
Here are some things you need to know about primary keys:
EVot
AutoNumber field as their primary key. AutoNumber fields automatically add a new,
unique number to each record in a table.
• Every table you create should have a primary key because it helps keep your data
OnR:
organized and easy to work with. In fact, if you create a table without a primary key,
Access will ask if you want to add one. If you answer Yes, Access will create an
AutoNumber field at the beginning of the table and set it as the primary key.
tFio
primary key, so long as their combined values are unique. Such multifield keys are
usually difficult and confusing to work with, however.
• Primary keys are especially important in creating relationships between tables.
al
So what makes a good primary key field? The most important consideration for a primary key
is its uniqueness. A primary key field must always be different in every record, so you might
Ev
be able use a Customer ID, Invoice Number, or Social Security Number field as your table’s
primary key.
g
If a table doesn’t have a unique field that is suitable as the primary key (and most tables
don’t), you can add an AutoNumber field to your table. The AutoNumber field will
in
automatically add a new, unique number to each of the records in a table.
This lesson explains how to add a primary key to a table.
in
1. Make sure the tblCustomers table is open in Design View.
First you need to click the name of the field you want to use as your primary key. If
E tra
your table doesn’t have a natural primary key field, you will need to add one.
AutoNumber fields make great primary keys. Primary Key
button
For this exercise we’ll use the CustomerID AutoNumber field as the table’s primary
key. Other Ways to Set the
Primary Key:
2.
UfSor
Click the CustomerID field name.
• Right-click the field you
Now you can set the CustomerID field as the table’s primary key. want to use as the
3. Click the Primary Key button on the toolbar. primary key and select
A key symbol ( ) appears next to the CustomerID field, indicating that it is the table’s Primary Key from the
Nd
primary key. Notice that Access also sets the Indexed field to “Yes (No Duplicates).” shortcut menu.
Access automatically indexes the CustomerID field so that sorts and queries using the
LY IOse
field will be faster and so that you cannot enter duplicate values in the field.
4. Click the Save button on the toolbar to save the changes you’ve made to
the table.
T u
ON Ae b
Quick Reference
U
ALto
toolbar.
Or…
Right-click the field you
want to use as the
ua
g
in
Lesson 4-4: Inserting, Deleting,
and Reordering Fields
in
E tra
Figure 4-5
The procedure for
changing the order of 1. Select the 2. …and then
fields in a table. row you want click and
UfSor
to move by drag the row
clicking its to a new
row location.
selector…
Nd
LY IOse
Figure 4-5
You can insert, delete, and reorder fields in your tables in Design View. Remember that in
u
Design View, for tables, each row corresponds to a field. You add a field by inserting a new
row and delete a field by deleting its corresponding row.
T
ON Ae
1. Open the tblCustomers table in Design View.
b
To insert a new field, you must first click the row selector for the field that will appear
below the new field you want to insert.
U
2. Click the row selector for the Phone field. Press <Insert> to add a
ALto
blank field.
Now all you have to do is give the new row a name and specify its data type.
3. Click the Field Name box for the new row and type MI.
EVot
You’ve added a new field. Now let’s see how to rearrange the order of fields in a table.
4. Click the MI row selector to select the MI field.
N
field.
Access deletes the MI field from the tblCustomers table.
ua
al
Ev
g
Great! In a very short lesson you’ve learned three new table skills.
in
in
E tra
UfSor
Nd
LY IOse
T u
ON Ae
U b
ALto
Quick Reference
To Insert a Row:
1. Click the row selector
EVot
2. Press <Insert>.
To Change the Order of
OnR:
Fields in a Table:
1. Click the row selector
for the field you want to
tFio
move.
2. Click and drag the
selected row to the
ua
desired location.
To Delete a Field from a
Table:
al
g
in
Lesson 4-5: Changing a Field’s
Data Type
in
E tra
Figure 4-6
This area
A field’s data type displays the
determines what type of table’s field
information the field can names.
UfSor
store.
Nd
LY IOse
T u
Figure 4-6 This area displays the data type for
each field. Click the Data Type area
Use this scroll bar
to browse through
ON Ae
for the field you want to change and a table’s fields.
select the data type you want to use
b
Because there are so many different types of data, Access offers several different types of
ALto
fields. A field’s data type determines the type of information that can be stored in a field.
Table 4-2: Data Types lists the various data types available in Access. A field’s data type helps
prevent data-entry errors because it restricts what type of information you can enter in a field.
For example, you cannot enter text in a number data-type field.
EVot
If you’ve been working with Access for a while, you probably already know some of this
stuff. Just consider this lesson a quick review.
N
4. Click the DOB Data Type arrow and select Date/Time from the list.
The DOB field will now only accept date and time information. The new Date/Time
Save button data type also makes your database more flexible and powerful because now you can
al
Other Ways to Save a sort birthdays by date or use a person’s birthday in a calculation—for example, to
Database Object: determine a person’s age.
• Select File → Save Once you have finished modifying a table, you have to save your changes.
Ev
g
5. Click the Save button on the toolbar to save your changes.
in
Table 4-2: Data Types
Data Type Example Description
in
Text Legal Name: Stores text, numbers, or a combination of both, up to 255
John Doe characters long. Text fields are the most common of all
E tra
data types.
Memo Notes: Stores long text entries—up to 64,000 characters long (the
Sally displays a high equivalent of 18 pages of text!). Use memo fields to store
amount of… notes or anything else that requires lots of space.
UfSor
Number Age: Stores numbers that can be used in calculations.
31
Date/Time Birthday: Stores dates, times, or both.
April 7, 1969
Nd
Currency Price: Stores numbers and symbols that represent money.
$84.95
LY IOse
AutoNumber Invoice Number: Automatically fills in a unique number for each record.
187001 Many tables often contain an AutoNumber field that is also
u used as their primary key.
Yes/No Smoker?: Stores only one of two values, such as Yes or No, True or
T
Yes False, etc.
ON Ae
OLE Object Photo: Stores objects created in other programs such as a
b
Hyperlink Web Site: Stores clickable links to files on your computer, on the
www.amazon.com network, or to Web pages on the Internet.
Quick Reference
EVot
Lookup Wizard Purpose of Trip: A wizard that helps you create a field whose values are
selected from another table, query, or a preset list of To Change the Data Type
values. for a Field:
N
data type.
ua
al
Ev
g
in
Lesson 4-6: Using Field
Descriptions
in
E tra
Figure 4-7
A field’s description lets Enter a description for a
you provide your database field here.
users with onscreen
UfSor
prompts and instructions.
Figure 4-8
A field’s description
Nd
appears in the Status bar
whenever you select the
LY IOse
field.
Figure 4-7
T u
ON Ae b
Descriptions make your database fields easier to fill out and use by providing users with
onscreen instructions and help. Whenever a user selects a field, anything you type in that
EVot
field’s Description box will appear in the Status bar. There really isn’t anything to adding a
description to a field—just type the text you want to appear in the field’s Description box.
N
Quick Reference
1. Make sure the tblCustomers table is open in Design View.
To Add a Description to a First you need to select the field where you want to add a description.
Field:
2.
OnR:
g
in
Lesson 4-7: Adding a Caption
in
Figure 4-9
E tra
Adding a caption to a field.
Figure 4-10
Without Captions The same fields with and
UfSor
without captions.
Nd
With Captions
Figure 4-9 Figure 4-10
LY IOse
1. Select the field 2. Enter a caption for
where you want to the field here.
add a caption.
u
Think of the Caption property as a field’s pseudonym or stage name. When you create forms
T
and reports, Access uses the field’s Field Name as the field’s heading. When you add a
ON Ae
caption to a field, however, it appears as the heading for the field instead of the field name.
b
Captions are useful when you want to provide more detailed headings for your field names.
For example, instead of displaying the rather unclear DOB field name, you could add a more
U
meaningful “Date of Birth” caption to the DOB field to make your forms and reports easier to
ALto
read and understand. The original DOB field name is not affected in any way.
This lesson explains how to add a Caption to a field.
The tblCustomers table contains two unclearly labeled fields that could use captions: Quick Reference
the DOB (date of birth) and SSN (social security number) fields. You probably already
To Add a Caption to a
N
know the first step by now—click the name of the field where you want to add the
caption. Field:
2. Click the DOB field name.
1. Display the table in
Design View and click
OnR:
Now you can add a more meaningful caption to the DOB field that will appear as the the field in the field list.
field’s heading.
2. Click the Caption box in
3. Click the Caption box in the Field Properties section and type Date of
tFio
g
in
Lesson 4-8: Changing the Field
Size
in
E tra
Figure 4-11
The Field Size property 1. Select the field
determines the maximum whose size you
number of characters the want to change.
UfSor
field will accept.
2. Click the Field Size
box and…
For Text Fields:
Type the Field Size
Nd
value.
For Number Fields:
LY IOse
Choose the value
from the drop-down
list.
Figure 4-11
T u
ON Ae
The Field Size property determines the maximum size of information that can be stored in a
text or number field. For example, if you set the size of a text field to 2, you could enter
b
“MN” but not “Minnesota.” There are several reasons why you would want to change the size
of a field:
U
ALto
Field sizes work a little differently for text and number fields. In text fields, the Field Size
property determines the maximum number of characters the field can accept, as shown in
Figure 4-11. In numbers fields, the Field Size property determines what type of number the
N
Click the Field Size box in the Field Properties section and type 2.
The State field can now only accept a maximum of two characters so that users will
have to enter standard two-digit state abbreviations.
Let’s try changing the size of another field.
al
Zip Codes for at least a few more years so you can safely change the field size to a
smaller number.
g
5. Click the Field Size box in the Field Properties section and type 11.
The ZipCode field will now accept no more than 11 digits.
in
NOTE: Be very careful when you’re changing the Field Size of a field that already
contains data. Access will truncate or delete data that is larger than the new
in
field size.
6. Click the Save button on the toolbar to save your changes, click Yes to
E tra
confirm the change, and close the table.
If you are working with a number field, the Field Size property determines the type and size
of the number that a field will accept, as shown in the following table.
UfSor
Table 4-3: Available Number Field Sizes
Heading Number Range Decimal Places Storage Size
Byte 0 to 255 None 1 byte
Integer -32,768 to 32,767 None 2 bytes
Nd
Long Integer -2.1×1038 to 2.1×1038 None 4 bytes
LY IOse
Single -3.4×1038 to 3.4×1038 7 4 bytes
Double -1.8×10308 to 1.8×10308 15 8 bytes
Replication ID N/A T u N/A 16 bytes
ON Ae
U b
ALto
Quick Reference
EVot
g
in
Lesson 4-9: Formatting Number,
Currency, and Date/Time Fields
in
E tra
Figure 4-12
The Format property 1. Select the number,
determines how values currency, or date
field you want to
are displayed in a field.
UfSor
format.
Nd
and select the
desired format from
LY IOse
the list.
Figure 4-12
T u
ON Ae
A field’s Format property changes how information appears in the field. The Format property
only changes how data is displayed on the screen, not how the data is actually stored in the
b
field. For example, a date field could be formatted to display the same value as 6/10/2000;
Saturday, June 10, 2000; or 10-Jun-00. Each field type has its own set of formats. For
U
example, number fields have a different set of formats than date/time or text fields.
ALto
This lesson explains how to format number, currency and date/time fields. There are two ways
to format a number, currency and date/time field:
• By selecting a ready-made format from the Format drop-down list (the easy way).
EVot
• By typing a series of formatting characters in the Format box (the hard way).
Hopefully, the ready-made formats listed in Table 4-4: Number, Currency, and Date/Time
N
Formats will be all you will ever need to format your fields. This lesson explains how to
format number, currency, and date/time fields by selecting a ready-made format.
1.
OnR:
this is the case, you should visit the Microsoft Office Update Web site, located
at www.officeupdate.com, and download Microsoft Office 97 Service Pack 2.
2. Switch to Design View by clicking the View button on the toolbar.
al
Now you can change the formats of the fields in the tblCustomerTours table.
View button
Ev
g
3. Click the Date field name and click the Format box in the Field
Properties section.
in
A downward-pointing arrow appears in the Date Format box. You can format this
field the easy way by clicking the arrow to select from one of the ready-made number
in
formats shown in Table 4-4: Number, Currency, and Date/Time Formats.
4. Click the Format drop-down list and select Medium Date.
The Date field will now display its dates in 1-Jan-00 format instead of the 1/1/2000
E tra
format.
You can also specify how many decimal places you want numbers in a field to display.
To change the number of decimal places in a number field, you enter the number of
decimal places you want displayed in the Decimal Places box.
UfSor
5. Click the Cost field, click the Decimal Places drop-down list, and
select 0.
The Cost field will not display any decimal places. Access will round any decimals
equal to or greater than five to the next number.
Nd
NOTE: The Decimal Places property setting has no effect if the Format property is
blank or is set to General Number.
LY IOse
NOTE: The Decimal Places property affects only the number of decimal places that
are displayed, not how many decimal places are stored.
You’ll need to save the table before you can view your new Format settings.
u
6. Click the Save button on the toolbar to save your changes.
T
Now let’s see how the fields look with their new formats.
ON Ae
7. Switch to Datasheet View by clicking the View button on the toolbar.
Quick Reference
b
Notice the Date field now displays dates in a 1-Jan-00 format and the Cost field no
longer has any decimal places. To Format Number and
U
Here’s a list of ready-made number, currency, and date/time formats you can choose from. Currency Fields:
ALto
These standard formats should be all that you’ll ever need—if not, take a look at the lesson on 1. Display the table in
formatting number, currency, and date/time fields by hand. Design View and click
the field in the field list.
EVot
Table 4-4: Number, Currency, and Date/Time Formats 2. Click the Format box in
Number Format Example Date/Time Format Example the Field Properties
section.
N
to display.
g
in
Lesson 4-10: Formatting Number,
Currency, and Date/Time Fields by
in
Hand
E tra
Figure 4-13
UfSor
The Format property 1. Select the number,
determines how values currency, or date
field you want to
are displayed in a field. format.
You can create your own
custom number, currency,
or date formats by 2. Click the Format box
Nd
and enter the
entering the appropriate appropriate formatting
formatting characters,
LY IOse
characters shown in
shown in Table 4-5: Table 4-5: Number,
Number, Currency, and Currency, and
Date/Time Formatting
Date/Time Formatting Characters.
Characters. T u
ON Ae
Figure 4-13
b
If none of the ready-made number, currency, or date/time formats meets your needs, you can
U
format your number, currency, and date/time fields the old-fashioned way—by hand.
ALto
Formatting fields by hand is a laborious and confusing process—you tell Access how you
want the field to be formatted by typing the formatting characters listed in Table 4-5: Number,
Currency, and Date/Time Formatting Characters in the Format box. On the other hand,
manually formatting a number, currency, or date/time field gives you complete flexibility on
EVot
fields by hand isn’t exactly a difficult process, but you will probably need to use the
reference on the next page to know which formatting characters to enter.
3. Click the Format box in the Field Properties section and type
ua
ddd mmm d.
This will display the date in Sun Mar 8 format. Look at Table 4-5: Number, Currency,
and Date/Time Formatting Characters for a description of the characters you just
entered.
al
4. Click the Save button on the toolbar to save your changes, and then
switch to Datasheet View by clicking the View button on the toolbar.
Ev
Notice the Date field now displays its days using the Date format you specified.
g
5. Close the tblCustomerTours table.
in
Use the following characters when you want to format number, currency, or date/time
characters by hand. You can mix and match any of the following characters. For example, you
could add “mmmm” (full name of month) to “yy” (last two digits of the year) to get January
in
00.
E tra
Date/Time Formatting Characters
Character Description Format Display
: Time separator h:nn 8:45
UfSor
/ Date separator m/d/yy 10/8/00
- Date separator m-d-yy 10-8-00
d Day in one or two numeric digits m/d/yy 10/8/00
Nd
dd Day in two numeric digits m/dd/yy 10/08/00
LY IOse
ddd First three letters of the weekday ddd, m/d/yy Sun, 3/8/00
dddd Full name of the weekday dddd, m/d/yy Sunday, 3/8/00
m Month in one or two digits
u m/d/yy 3/15/00
mm Month in two digits mm/dd/yy 03/15/00
T
ON Ae
mmm First three letters of the month mmm-d-yy Mar-15-00
b
mmmm Full name of the month mmmm d, yyyy March 15, 2000
yy Last two digits of the year m/d/yy 3/15/00
U
ALto
Field:
AM/PM Twelve-hour clock (uppercase) hh:nn AM/PM 08:45 AM 1. Display the table in
Design View and click
am/pm Twelve-hour clock (lowercase) hh:nn am/pm 08:45 am
OnR:
section.
# Display a digit or nothing 50 # 50
3. Enter the appropriate
0 Display a digit or 0 50 #.00 50.00 formatting codes for how
you want the date or
ua
g
in
Lesson 4-11: Formatting Text
Fields
in
E tra
Figure 4-14
The Format property 1. Select the text field
determines how values you want to format.
are displayed in a field.
UfSor
You can determine how
text is displayed by 2. Click the Format
entering the appropriate box and enter the
formatting characters, appropriate
formatting
shown in Table 4-6:
Nd
characters shown in
General and Text Table 4-6: General
Formatting Symbols. and Text Formatting
LY IOse
Symbols.
Figure 4-14 T u
ON Ae
Just like number, currency, and date/time fields, a text field’s Format property changes how
information appears in the field. The Format property only changes how data is displayed on
b
Unfortunately, unlike number fields, text fields don’t have any ready-made settings built into
ALto
them and must be formatted manually. Luckily, text fields don’t have nearly as many
formatting options as number, currency, and date/time fields. The most common of these text
formatting characters are the greater than symbol (>), which makes all text in the field appear
in uppercase, and the less than symbol (<), which makes all text in the field appear in
EVot
lowercase, regardless of how it was entered. In both cases, Access actually stores the data
exactly as it was typed.
This lesson will give you some practice formatting text fields.
N
Access displays the tblCustomers table in Design View. First you have to click the
name of the field you want to format.
4. Click the State field name.
al
You can make sure that the contents of the State field are always capitalized by adding
a greater than symbol (>) to the Format box.
Ev
g
5. Click the Format box in the Field Properties section and type a greater
than symbol (>).
in
Access will display the contents of the State field in uppercase, even if it was entered in
lowercase.
in
NOTE: Remember that the Format property only changes how data is displayed on
screen, not how the data is actually stored in the field.
6.
E tra
Click the Save button on the toolbar to save your changes.
Now let’s see how the State field looks with its new format.
7. Switch to Datasheet View by clicking the View button on the toolbar.
Notice that the lowercase state abbreviation you entered back in Step 2 now appears in
UfSor
uppercase.
The table below contains formatting options for text fields.
Nd
Character Description Text Format Display
! Aligns text from the right Hello ! Hello
LY IOse
< Lowercase Hello < hello
> Uppercase Hello > HELLO
"ABC"
T u
Always displays quoted text 4 &" oz." 4 oz.
@ Character is required 5558000 @@@-@@@@ 555-8000
ON Ae
* Fill available space with next character Alert &*! Alert!!!!!!!!!!
b
Quick Reference
EVot
g
in
Lesson 4-12: Setting a Default
Value
in
E tra
Figure 4-15
A field’s default value is 1. Select the field.
automatically entered in
the field whenever you
UfSor
add a new record.
Figure 4-16
2. Enter its Default
The default value for the Value here.
Nd
State field automatically
appears in a new record.
LY IOse
The default value is
automatically
entered in the field
whenever you
Figure 4-15 T u create a new
record.
ON Ae
A common default
b
date. To automatically
ALto
new record is created. For example, if most of your clients are from Texas, you could set the
default value for the State field to “TX.” When a user adds a record to the table, they can
either accept the “TX” default value for the State field or enter their own value.
N
Quick Reference 1. Make sure the tblCustomers table is open in Design View.
To Enter a Default Value Since the majority of your customers are from Minnesota, you decide to add “MN” as
OnR:
Properties section. Click the Save button on the toolbar to save your changes, and then
3. Enter the default value click the View button to display the table in Datasheet View.
you want to appear in the You will need to add a new record in order to see any default values.
field for new records. 5. Click the New Record button on the Record Navigation bar.
al
Access adds a new blank record to the table. Notice that the State field already contains
the “MN” default value. If the customer is from another state, you can simply replace
Ev
g
in
Lesson 4-13: Requiring Data Entry
in
Figure 4-17
E tra
1. Select the field. The Required field
property lets you specify if
a field must contain data
or not.
UfSor
2. Specify if the field
is required or not.
Nd
LY IOse
Figure 4-17
u
In most tables, there are usually at least a few fields that absolutely must contain data in order
for the record to be meaningful. For example, at the absolute minimum, a customer record New Record
button
T
needs to have the customer’s first and last name—otherwise, why bother entering it? You can
ON Ae
specify that a field must contain data to prevent users from leaving out important information
when they are entering data.
b
This lesson explains how you can make sure that a field has a value for each record.
U
ALto
Here’s how to prevent a user from leaving out a data in a field. To Require
Do This:Data Entry for
3. Click the Required drop-down list and select Yes. a• Field:
Instructions here.
N
button to display the table in Datasheet View. 2. Click the Required box in
You will need to add a new record in order to see any default values. Tothe
Create
FieldaProperties
New
Document:
section.
5. Click the New Record button on the Record Navigation bar.
tFio
1. Step
3. Click one
the here. Required
Access adds a new blank record to the table. drop-down arrow and
2. Step two here.
6. Enter a new record with your own information. Leave the LastName field select Yes.
blank, however.
ua
Access displays a dialog box that states that the LastName field cannot contain a null
value.
Ev
g
in
Lesson 4-14: Validating Data
in
Figure 4-18
E tra
Data validation tests
incoming data to make
1. Select the field.
sure it conforms to a
specified set of rules.
UfSor
2. Enter the validation rule
Figure 4-19 for the field (see Table 4-7:
Data Validation
Access displays the error Examples).
message you entered
whenever the validation 3. Enter a message that will
appear if the validation
rule is broken.
Nd
rule is broken.
LY IOse
Figure 4-18
T u
ON Ae
U b
Figure 4-19
ALto
Without a doubt, data validation is the most powerful tool you can use to prevent data-entry
errors. With data validation, Access actually tests data to make sure that it conforms to what
you want to appear in the table. If the incoming data doesn’t meet your requirements, Access
EVot
• Validation Rule box: Use to specify the requirements for data entered into the field.
• Validation Text box: Use to specify the message to be displayed to the user when data
is entered that violates the validation rule.
tFio
Creating data validation rules can be a little tricky—you create a data validation using the
same hard-to-remember operators that you use in filters and queries. Table 4-7: Data
Validation Examples contains some data validations that you can modify and use in your
ua
tables.
You decide to specify that the DOB field cannot be later than today’s date. (We can’t
have any people with birthdays in the future, can we?)
2. Click the DOB field name.
Ev
Before we get started, you need to make sure that the DOB is a Date/Time field—you
should have changed this in a previous lesson.
g
3. Verify that the DOB field’s Data Type is set to Date/Time.
First you need to enter a validation rule.
in
4. Click the Validation Rule box and type <Date().
The validation rule you just entered will prevent users from entering dates later than
in
today’s date in the DOB field. Next you have to specify the error message that Access
will display if someone tries to break your validation rule by entering a future date.
5.
E tra
Click the Validation Text box and type Date must not be later
than today’s date.
Let’s test our new data validation rule.
6. Click the Save button on the toolbar to save your changes, click No to
close message about testing existing data, and then click the View
UfSor
button to display the table in Datasheet View.
Data validation rules apply to both new and existing records. Move on to the next step
and try modifying a record so that it breaks our data-validation rule.
7. Click the DOB field for any record. Try changing the date to a future date
Nd
that falls after today.
When you try to violate the validation rule, Access displays the Validation Text you
LY IOse
entered back in Step 5, as shown in Figure 4-19.
8. Click OK and press <Esc> to cancel the change.
u
Consider the following table your data-validation “cheat sheet.” It contains samples of the
most common types of validation rules. Feel free to copy, modify, or mix and match these
examples to create your own validation rules.
T
ON Ae
Table 4-7: Data Validation Examples
b
>= Date( ) Must be today’s date or later. 2. Click the Validation Rule
<= Date( ) Must be today’s date or earlier. box in the Field
Properties section.
OnR:
"Business" Or "Pleasure" Or "Other" Must be “Business” or “Pleasure” or “Other.” 3. Enter an expression you
Like "??" Must have two characters. want to use to validate the
tFio
g
in
Lesson 4-15: Creating an Input
Mask
in
E tra
Figure 4-20
The first step of the Input
Mask Wizard.
UfSor
Figure 4-21
Specify how you want
your text to be stored: with
or without the input mask
Nd
symbols.
LY IOse
Figure 4-20 Figure 4-21
Try the selected input mask by
typing the appropriate data here.
u
An Input Mask limits the amount and type of information that can be entered in a field. You
T
have probably already seen an example of an input mask on an ordinary paper form—the type
ON Ae
of form that assumes you’re too dimwitted to know how to write down your phone number or
b
social security number and thus provides you with a guide like (___) ___ - _____ or
____-___-______. Look familiar? That’s an input mask, pure and simple.
U
Note: Depending on
There are two ways to create an input mask:
ALto
the Additional Characters to see what you have to enter to create an input mask.
Wizards option. In this lesson you will learn how to use the Input Mask Wizard to add an input mask to a field.
OnR:
Mask Wizard.
Now let’s look at the Input mask property…
3. Click the Input Mask box.
al
A button appears next to the Input Mask box—click this button to start the Input
Mask Wizard.
4. Click Build button to start the Input Mask Wizard.
Ev
The first step of the Input Mask Wizard appears, as shown in Figure 4-20. All you need
to do here is select the input mask you want to choose.
g
If you want to try an input mask to see how it works, click the input mask you want to
use and then type some sample text in the Try It box.
in
5. Click the Phone Number input mask and then try typing a phone
number in the Try It box. Click Next when you’re finished.
in
The next step of the Input Wizard appears. If you want, you can select a different
placeholder to use than the default underscore ( __ ) character.
6. Click Next.
E tra
The next step of the Input quite important—you have to specify how Access should
store your data. You have two choices:
• With the Symbols in the Mask
This will store only the text you type in the field and the input mask symbols.
UfSor
For example, if you enter 5555555555 in a Phone field, Access will save the
input mask symbols with the text you enter, so (555) 555-5555 would be saved.
• Without the Symbols in the Mask
This will store only the text you type in the field. For example, if you enter
5555555555 in a Phone field, Access will display (555) 555-5555 but only store
Nd
the numbers you typed (5555555555).
LY IOse
This may not seem like much of an issue, and it’s not unless you want to export your
table. Then you will have to work with the results of the decision you made here: the
phone numbers will be in either 5555555555 or (555) 555-5555 format.
7. Select the With the Symbols in the Mask option and click Next.
u
That’s it! You’re ready to create your input mask!
8.
T
Click Finish to create the input mask.
ON Ae
The Input Mask Wizard creates an input mask for the field.
b
Creating an input mask by hand is difficult, but it can be done. You need to create the input
mask by entering the characters shown in the following table in the Input Mask box.
U
ALto
0 Numbers 0 to 9 required; plus and & Character or space required. To Create an Input Mask
minus signs not allowed. for a Field:
9 Number or space optional; plus C Character or space optional. 1. Display the table in
N
g
in
Lesson 4-16: Creating a Lookup
Field
in
E tra
Lookup field
Figure 4-22
A lookup list displays
values from a table or
query.
UfSor
Figure 4-23
Create a lookup list by
selecting Lookup Wizard
Nd
for the field’s Data Type.
Figure 4-24
LY IOse
Figure 4-22
Step One: Selecting a Lookup field list
source for the lookup Figure 4-23
field’s values. u
Figure 4-25
T
ON Ae
Step Two: Selecting the
table or query that
b
Figure 4-26
Step Three: Selecting the
fields that contain the
Figure 4-24 Figure 4-25
EVot
values.
Figure 4-27
N
• From a list of values in a table or query. For example, instead of entering a CustomerID
number, you could select the CustomerID from a list of names.
g
You can see an example of a lookup field in Figure 4-22. Instead of you having to type a hard-
to-remember CustomerID number, the lookup field displays more meaningful information,
in
such as the customer’s name, yet still stores the CustomerID number in the field. Lookup
fields make more sense once you have actually worked with them, so let’s jump right into this
lesson’s exercise.
in
1. Close the tblCustomers table if it’s still open, and then open the
E tra
tblCustomerTours table in Design View.
You decide to use a lookup field to make the CustomerID field easier to view and add
data to. Here’s how to create a lookup field.
2. Click the Data Type area next to the CustomerID field, click the
down arrow and select Lookup Wizard, as shown in Figure 4-23.
UfSor
The Lookup Wizard dialog box appears, as shown in Figure 4-24, and asks if you want
your lookup field to get its values from another table or query or if you want to type a
list of options yourself. Since you want your lookup field to get its values from the
tblCustomers table, you will select the first option.
3.
Nd
Click Next.
The next step in the Lookup Wizard is to select the table or query that contains the
LY IOse
values for your lookup field. You want to look up customer names, so you would select
the tblCustomers table.
Quick Reference
4. Select the tblCustomers table and click Next.
u
Next you have to select the fields that contain the values you want to display in your
lookup field. The Lookup Wizard displays the field names in tblCustomers table that
T To Create a Lookup Field:
1. Display the table in
you can add to your lookup field. To add a field to your lookup field, double-click the Design View.
ON Ae
field or select the field and click the button. 2. Click the field’s Data
b
This step can be a little confusing at first. You will need to add the field that contains Type box, click the
the value you want to enter—the CustomerID field—but you also want to add some Data Type list arrow,
U
fields to display some more meaningful information in the value list, such as the and select Lookup
ALto
The next step in the Lookup Wizard dialog box is to specify which fields you want to
actually display in the lookup list. The first field, CustomerID, is the key field, or the or query option and click
value that will actually be stored in the field. Any primary key fields will be hidden by Next.
N
default to make the lookup field less confusing. 4. Select the table or query
you want to use for the
NOTE: Because you can use queries to sort and filter information, consider using lookup list and click Next.
them as the source for your lookup fields.
OnR:
7. Click Yes to save your changes and then click the View button to key in the column. If the
display the table in Datasheet View. table or query doesn’t
have a primary key, you
The CustomerID field still contains CustomerID numbers, but now it looks up and will be prompted for the
ua
displays the customer’s LastName field—much easier to understand. column that will act as the
8. Click the CustomerID field for any record. Click the down arrow bound column.
that appears in the field. 6. Click Next.
Out pops a list of all the customers in the tblCustomers table—neat, huh? All you have
al
g
in
Lesson 4-17: Creating a Value List
in
Figure 4-28
Lookup field
E tra
A value list displays a list
of options that you specify.
Figure 4-29
UfSor
Create a value list by
selecting Lookup Wizard
for the field’s Data Type.
Figure 4-30
Figure 4-28 Value list
Nd
Step One: Selecting a
source for the lookup
Figure 4-29
LY IOse
field’s values.
Figure 4-31
Enter the options you want
to see in the value list.
T u
ON Ae
U b
ALto
Similar to its cousin the lookup list, a value list displays a list of values in a drop-down list.
select an option from a
Unlike a lookup list, which displays data in a table or query, a value list displays a list of
lookup field by typing options that you manually enter. A value list is useful if you enter the same data in a field
the first few letters
N
again and again. For example, if you ship a product using three different courier services, you
of the entry. could create a value list that displays the three courier services, such as AirBorne, FedEx, and
UPS.
OnR:
Although it’s possible to change the options displayed in a value list, doing so is a rather
cumbersome process, and for that reason, you should only use value lists for values that will
not change very often. If you want to display a lot of options, such as a list of state
tFio
abbreviations, or values that may change frequently, you should create a table to store those
values and then display them with a lookup list instead. It’s a lot easier to change values in a
table than it is to change options in a value list.
ua
This lesson will show you how to create a value list that contains several static options.
g
2. Click the Data Type box next to the Ship Via field, click the down
arrow, and select Lookup Wizard, as shown in Figure 4-29.
in
The Lookup Wizard dialog box appears, as shown in Figure 4-30, and asks if you want
your lookup field to get its values from another table or query or if you want to type a
in
list of options yourself. Since you want to enter the options that appear in the value list,
you will want to select the second option.
3. Click the I will type in the values that I want option and click Next.
E tra
The next step of the Lookup Wizard appears, as shown in Figure 4-31. This step is
pretty easy—you simply enter the options you want to be displayed in the value list.
4. Click in the Col1 box, type Airborne, press <Tab>, type FedEx, press
<Tab>, and type UPS.
UfSor
The value list will display these three values.
NOTE: If you want to add a lot of options (ten or more) to your value list or if the
values in the list will change, consider creating a table to store the values and
display them with a lookup list instead. Adding the initial options to a value
Nd
list is easy, but adding, changing, or deleting these values is a non-intuitive
process.
5.
LY IOse
Click Next.
You’ve finished creating the value list!
6. Complete the Lookup Wizard by clicking Finish.
u
Let’s see how our new value list works.
7. Click the Save button on the toolbar to save your changes and then
T
ON Ae
click the View button to display the table in Datasheet View. Quick Reference
To display the value list for the Ship Via field, simply click the Ship Via field and click
b
Click the Ship Via field for any record. Click the down arrow that
Design View.
ALto
g
in
Lesson 4-18: Modifying a Lookup
List
in
E tra
Figure 4-32
You can display and
modify the properties of a Click the Lookup tab to
lookup field by clicking the
UfSor
display and modify the
Lookup tab in the Field properties of a lookup field.
Properties section.
Click the Row Source
Figure 4-33 button to modify a
lookup list.
Nd
The SQL Statement:
Query Builder window lets Table 4-9: Lookup Field
LY IOse
you modify what appears Properties describes each
in a lookup list. of these settings.
Figure 4-32 T u
ON Ae
U b
ALto
EVot
Figure 4-33
Modifying an existing lookup field isn’t nearly as straightforward as creating one. You can
OnR:
display and modify the properties for a lookup field by clicking on the Lookup tab in the Field
Properties section. There are several reasons why you would want to modify a lookup field:
tFio
• To sort the records in a lookup list. For example, to sort the records in a lookup list
alphabetically by last name.
• To add, change, or delete the static options in a value list. For example, you could add
“U.S. Postal Service” to a Ship Via value list.
ua
In this lesson you will learn how to view and modify an existing lookup field.
The CustomerID lookup field we created in an earlier lesson is neat, but its list of
names isn’t displayed in alphabetical order. Not a problem—we can change this by
Ev
modifying the lookup field. You can display and change the properties for a lookup
field by clicking the Lookup tab in the Field Properties section.
g
2. Click the CustomerID field name, then click the Lookup tab in the Field
Properties section.
in
The properties for the CustomerID lookup field are displayed, as shown in Figure 4-32.
You can learn more about these properties in Table 4-9: Lookup Field Properties.
3.
in
Click the Row Source box.
That technical SELECT [tblCustomers].[CustomerID] stuff in the Row Source box is a
SQL statement. SQL (Structured Query Language) is a language most database
E tra
programs use to create queries—and it tells lookup fields where to get their values.
Fortunately, you don’t have to know how to write SQL to modify a lookup field—you
can use the familiar query grid to create the SQL statement for you.
4. Click the Row Source button to display the SQL Statement: Query
UfSor
Builder window.
The SQL Statement: Query Builder window appears as shown in Figure 4-33. Yep—
it’s the same query grid that you’re already familiar with.
5. Click the LastName field’s Sort row’s drop-down list and select
Ascending, as shown in Figure 4-33.
Nd
This will sort the CustomerID lookup field by the LastName field.
6.
LY IOse
Close the SQL Statement: Query Builder window and click Yes when you
are prompted to save your changes.
Access updates the SQL statement for the CustomerID lookup field. You can also view,
The Row Source box contains the text "Airbone";"FedEx";"UPS". You can add
U
options to the value list by typing them into the Row Source box—just make sure that
ALto
the options are enclosed by quotation marks (") and separated by a semi colon (;).
9. Type ; "US Mail" so that the Row Source reads
"Airbone";"FedEx";"UPS";"US Mail".
That’s it—you’ve finished modifying the lookup fields in the tblCustomers Tours table. Quick Reference
EVot
10. Save your changes, close the tblCustomers Tours table and the database. To Modify a Lookup List:
1. Display the table in
N
Display Control Determines whether the lookup field is a text box, combo box, or list box. click the Lookup tab in
Row Source Type Determines how Access provides data to the lookup field: from a table or query, the Field Properties
from a list of values specified in the Row Source box, or from a list of field section.
tFio
Bound Column The column in the lookup list that contains the value that is actually stored in the 4. Make the desired
field. The bound column is the first column (1) by default. changes and then close
Column Count The number of columns that are displayed in the lookup field list. the SQL Statement:
al
Limit to List Determines whether a field can accept a value that is not in the lookup list.
g
in
Chapter Four Review
in
Lesson Summary
E tra
Understanding Field Properties
UfSor
• To Display a Table in Design View: Open the table and click the View button on the toolbar,
or from the Database window, click the Tables icon in the Objects bar, select the table, and click
the Design button.
Indexing a Field
Nd
• To Index a Field: Display the table in Design View. Click the field you want as an index, click the
LY IOse
Indexed box, click the drop-down arrow, and select Yes (Duplicates OK) if you want to allow
multiple records to have the same data in this field or select Yes (No Duplicates) if you want to
ensure that no two records have the same data in this field.
u
Adding a Primary Key to a Table
T
• To Add a Primary Key to a Table: Display the table in Design View and click the field that you
ON Ae
want to set as the primary key. If such a field doesn’t exist, you will have to create it. Click the
Primary Key button on the toolbar or right-click the field you want to use as the primary key and
b
• To Change the Order of Fields in a Table: Click the row selector for the field you want to
move and click and drag the selected row to the desired location.
•
N
To Delete a Field from a Table: Click the row selector for the field and press <Delete>.
• To Change the Data Type for a Field: Display the table in Design View, click the field’s Data
Type box, click the Data Type list arrow, and select the data type.
tFio
field.
Adding a Caption
al
• To Add a Caption to a Field: Display the table in Design View, click the field in the field list, click
the Caption box in the Field Properties section, and type the caption.
Ev
g
Changing the Field Size
in
• To Change the Field Size: Display the table in Design View, click the field in the field list, click the
Field Size box in the Field Properties section, and either type the Field Size value (for text fields)
or choose the value from the drop-down list (for number fields).
in
Formatting Number, Currency, and Date/Time Fields
E tra
• To Format Number and Currency Fields: Display the table in Design View, click the field in the
field list, click the Format box in the Field Properties section, click the Format drop-down
arrow, and select a number format.
• To Change the Number of Decimal Places: Display the table in Design View, click the field in
UfSor
the field list, click the Decimal Places box in the Field Properties section, click the Decimal
Places drop-down arrow, and select the number of decimal places you want to display.
Nd
the field in the field list, click the Format box in the Field Properties section, and enter the
appropriate formatting symbols.
LY IOse
Formatting Text Fields
• u
To Manually Format a Text Field: Display the table in Design View, click the field in the field list,
click the Format box in the Field Properties section, and enter the appropriate text formatting
symbols.
T
ON Ae
Setting a Default Value
b
• To Enter a Default Value for a Field: Display the table in Design View, click the field in the field
U
list, click the Default Value box in the Field Properties section, and enter the default value you
ALto
• To Require Data Entry for a Field: Display the table in Design View, click the field in the field list,
click the Required box in the Field Properties section, click the Required drop-down arrow,
and select Yes.
N
Validating Data
OnR:
• To Validate Field Data: Display the table in Design View, click the field in the field list, click the
Validation Rule box in the Field Properties section, enter an expression you want to use to
validate the field’s data, click the Validation Text box in the Field Properties section, and then type
tFio
the text that Access will display when the user tries to enter incorrect data for the field.
• To Create an Input Mask for a Field: Display the table in Design View, click the field in the field
list, click the Input Mask box in the Field Properties section, click the Build button to start the
Input Wizard, and select an input mask from the predefined list or manually create the Input Mask
by entering the appropriate formatting codes.
al
Ev
g
Creating a Lookup Field
in
• To Create a Lookup Field: Display the table in Design View, click the field’s Data Type box, click
the Data Type list arrow, and select Lookup Wizard. Click the I want the lookup column to
look up the values in a table or query option, click Next, select the table or query you want to
in
use for the look up list, and click Next. Resize the column width and indicate whether or not to
include the primary key in the column. If the table or query doesn’t have a primary key, you will be
prompted for the column that will act as the bound column. Click Next, enter a label for the Lookup
E tra
column, and click Finish.
UfSor
the Data Type list arrow, and select Lookup Wizard. Click the I will type in the values that I
want option and click Next. Specify the number of columns you want to appear in the Value list,
Enter the values in the list. Resize the column widths, if necessary, and click Next when you’re
finished. Enter a label for the Lookup column and click Finish.
Nd
Modifying a Lookup List
LY IOse
• To Modify a Lookup List: Display the table in Design View, click the lookup list’s field name
box, then click the Lookup tab in the Field Properties section, click the Row Source button
to display the SQL Statement: Query Builder window, make the desired changes, and then close
u
the SQL Statement: Query Builder window.
T
Quiz
ON Ae b
A. Field Size.
B. Format.
C. Color.
D. Indexed.
EVot
False?)
A. The Indexed property has three settings: No, Yes (Duplicates OK), and Yes (No
Duplicates).
tFio
4. Which of the following fields would NOT make a suitable primary key?
A. An AutoNumber field.
al
g
5. Text entered in the field Description box will appear in a pop-up window
whenever a user selects that field. (True or False?)
in
6. The Field Size property works differently, depending on whether the field is
in
a text or number field. (True or False?)
E tra
7. Which of the following Format properties would display the full name of the
month?
A. MONTH.
B. FULLMONTH.
C. mm.
UfSor
D. mmmm.
Nd
created.
B. The Required property determines if a user must enter a value in a field or not.
LY IOse
C. A lookup field lets you pick a field’s entry from a list of values, which often comes
from another table or query.
D. (___) ___ - _____ is an example of a Required property.
u
9. What does adding a > into the Format box of a text field do?
T
A. Requires all characters entered in the field to be in uppercase.
ON Ae
B. Displays the characters in the field in uppercase.
C. Requires all characters entered in the field to be numbers.
b
A. The Default Value box lets you specify a value that is automatically entered in a field
when a new record is created.
B. The Required box lets you specify if data entry is required for a field.
EVot
11. You want to create a field that lets you add a customer’s name by picking it
OnR:
from a drop-down list. Which of the following fields would let you do this?
A. A memo field.
tFio
B. A lookup field.
C. An OLE field.
D. A hyperlink field.
ua
12. What is the corresponding text for the <#1/1/95# Validation Rule Setting?
A. Enter a date before 1995.
B. Enter a value less than 1,195.
al
g
13. You can set a field as the primary key by selecting the field and clicking the
Primary Key button on the toolbar. (True or False?)
in
in
Homework
E tra
1. Open the Homework database.
2. Open the Customers table in Design View.
3. Limit the Field Size of the LastName and FirstName fields to 15 characters.
UfSor
4. Specify a format for the State field that will display all entries in uppercase.
5. Create an Input Mask for the SSN field so that users must enter information in a
___-__-___ format and make the SSN field a required field.
6. Index both the LastName and FirstName fields (duplicates OK).
Nd
7. Make the SSN field the table’s primary key.
LY IOse
8. Save your changes to the Customers table and close the Homework database.
Quiz Answers T u
ON Ae
1. C. There are Color properties for other database objects, but not for fields in a table.
2. False. Only index those fields that you frequently use to filter or sort information.
b
Indexing too many fields in a table slows down filters and sorts, defeating the whole
U
3. D. This was a tricky question—you can’t index memo, OLE object, or hyperlink
fields.
4. D. Because the date isn’t usually a unique value (the same date might appear more
EVot
than once in the same table), it wouldn’t normally make a good candidate for a
table’s primary key.
5. False. Text in the field Description box will appear in the Status bar when a user
N
properties.
7. D. Another difficult question—“mmmm” would display the full name of the month.
tFio
13. True. This is the procedure for setting a field as a table’s primary key.
Ev
E tra
Creating Relational
UfSor
Databases
Nd
LY IOse
Chapter Objectives: ; Prerequisites
• Understand table relationships • How to use menus,
u toolbars, dialog boxes,
• Create a relationship between two tables and shortcut
keystrokes.
T
• Understand referential integrity
ON Ae
• How to open and
Chapter Task: Join two related tables modify database
b
objects.
U
This chapter covers what many people agree is one of the most difficult database concepts— • How to add and edit
ALto
how to create and work with relational databases. A relational database contains two or more database records.
tables that are related to each other in some way. For example, a database might contain a
Customers table and an Invoices table that contains the customer’s orders.
EVot
In this chapter you will learn how to link tables in an existing database together in a one-to-
many relationship to create a relational database. You will also learn how to enforce
referential integrity between those tables to keep records in related fields valid and accurate.
N
Relational databases can be confusing at first, so we’ll take things slowly and explain
everything in great detail as we go. Let’s get started!
OnR:
tFio
ua
al
Ev
168 Microsoft Access 2003
g
in
Lesson 5-1: Understanding Table
Relationships
in
E tra
Figure 5-1 Customers Table
ID Last First Address Invoice
This database tracks
80 Hill Brad 10 Park Ave.
customers and their
95 Gill Julie 1201 50th St. Dave Smith
orders in two separate but
UfSor
100 Pine St.
related tables. 74 Smith Dave 100 Pine St. Chaska, MN 55413
Figure 5-2 103 Williams Adam 1131 Palm Ave.
Date Product Cost
Sketch out a diagram of You create a relationship between tables 4/5/00 Soap $1.50
by linking the matching fields in the tables.
Linked Field
Nd
your database, including
You will usually link the primary key in one
its tables and how they table with the matching field in another
LY IOse
relate to each other. table.
Orders Table
u
ID Date Product Cost
74 4/5/00 Soap $1.50
T
ON Ae
95 4/5/00 Shampoo $2.99
b
Figure 5-1
ALto
1 ∞
Primary Key Student ID Student ID Related Field
First Name Class ID
EVot
State Time
Zip Code
OnR:
E-mail
Figure 5-2
tFio
addresses are stored on a Rolodex card. Flat-file databases are incredibly simple to create
and use, but they’re not very powerful or well suited to many business tasks.
• Relational: A relational database contains multiple tables that are related through
al
matching fields. Figure 5-1 illustrates the design of a relational database. The database in
Figure 5-1 has two tables—one that stores customer names and addresses, and another
that stores customer orders. The two tables are related or linked by a common field.
Ev
Relational databases are very powerful, but developing one takes a lot of skill, a lot of
practice, and a strong understanding of tables and fields.
g
Microsoft Access can create either type of database—flat file or relational. However, most
Access databases tend to be of the relational type.
in
Still fuzzy about how relational databases work? To see an example of a relational database, Jim Ross
look at the diagram illustrated in Figure 5-1. This database tracks customers and their orders. (800) 555-1862
in
To store this information, the database uses two tables: Customers and Orders. Each table
contains fields that store similar information. The Customers table contains only information
about customers and their addresses. The Orders table contains only information about any
E tra
orders that were placed—it doesn’t contain any information about the customers. The two
tables both have an ID field, and it’s this ID field that relates or links the two tables.
Relational databases save storage space by cutting down on duplicate data. For example, the
relational database shown in Figure 5-1 stores information in two related tables and eliminates
A flat-file database is
UfSor
the need to reenter a customer’s name and address each time that customer places a new order.
similar to the cards in
Relational databases require lots of planning ahead. Before you attempt to create your a Rolodex. Each record
database, you should sit down with a trusty pencil and a pad of paper and walk through the is stored in the same
following steps: place.
• Determine the Purpose of the Database
Nd
Write down a list of the reports and lists that you want to come out of the database. This
may seem a little backward at first, but these reports are the reason you’re creating the
LY IOse
database. Make a list of the reports and lists you want to see and then sketch some
samples of these reports and lists—be as detailed as possible. This will help determine
the tables and fields to include in your database.
• Write Down the Fields You Need
u
This should be an easy step once you have determined the purpose of your database and
T
have sketched some sample reports and lists.
ON Ae
• Organize and Group Related Fields into Separate Tables
b
Each table in the database should be based on only one subject. By breaking each subject
into its own table, you avoid redundant information and make the database more
U
organized. The database in Figure 5-1 is broken down into two tables, Customers and
ALto
Orders, so there isn’t any duplicated data. When you brainstorm, try to break down your
information as much as possible. If your table contains fields like Item 1, Item 2, Item 3,
Item 3, and so on, you should probably break each item up into its own table.
EVot
each of your tables and write the table’s field names inside that box. Draw a line between
the related fields. Most table relationships are a one-to-many relationship. This means
that a record in one table may be related to one or more records in another table. For
tFio
example, in Figure 5-1, each record in the Customers table is related to one or more
records in the Orders table. This makes sense since, hopefully, most customers will place
more than one order. You should indicate the two sides of the relationship by drawing a
“1” on the “one” side of the relationship line and an “∞” (infinity symbol) on the “many”
ua
would they? No—and it’s no different if you’re going to create a good relational database.
Ev
g
in
Lesson 5-2: Creating Relationships
Between Tables
in
E tra
Figure 5-3
The Show Table dialog
box.
UfSor
Figure 5-4
The Edit Relationships
dialog box.
Figure 5-5
Nd
Click and drag the primary Figure 5-3
LY IOse
key field from one table to Figure 5-4 Check to avoid “orphan”
the matching field in the Displays the names of the tables you are records in a related table.
related table. creating a relationship between and the
names of the common fields.
Figure 5-6
u
The Relationships window.
T tblCustomerTours
ON Ae
To join two tables, click and drag the tblCustomers table table tblTours table
related field from the first table to the
b
Figure 5-5
Figure 5-6
N
Once you begin to understand the difficult concept of relational databases, the process of
OnR:
actually linking the tables in a database is rather simple. You link related tables by connecting
the table’s common fields in Access’s Relationships window, shown in Figure 5-6. The
Relationships window lets you view, create, and modify relationships among tables in a
tFio
database.
Keep the following rules in mind when you link two tables together:
• Linked fields should be (almost) identical.
ua
Related fields must have the same data type and field size, and they must contain the
same kind of information. Related fields don’t have to have the same field name—but
they should so that things don’t get confusing. The most common problem people have
when they try to link two tables is caused by fields with different data types and/or sizes.
al
• The primary key in one table is usually linked with a matching field in the
other table.
Ev
Notice that in Figure 5-6 the tblTours table’s primary key, TourID, links to the TourID
field in the tblCustomerTours table.
g
• Fields related to an AutoNumber primary key field must be Number fields
with the Long Integer Field Size.
in
Now you’re ready to create a relationship between the tables in your database. Here’s
Relationships
button
how to do it:
Other Ways to Define
in
Table Relationships:
1. Open the Lesson 5 database.
• Right-click any blank
To view and create relationships between tables, you need to display the Relationships
E tra
area in the Database
window.
window and select
2. Click the Relationships button on the toolbar. Relationships.
The Relationships window appears. If any relationships exist between the tables in
your database, each of these tables will appear in a small box with lines connecting the
UfSor
table’s linked fields.
3. If the Show Table dialog box doesn’t appear when you open the
Relationships window, click the Show Table button on the toolbar.
First you have to add the tables that you want to relate using the Show Table dialog
Show Table
button
Nd
box, as shown in Figure 5-3. In this exercise you want to relate the tblCustomers,
tblCustomerTours, and tblTours tables, so you will need to add these tables to the
LY IOse
Relationships window.
4. Click the tblCustomers table and click Add. Quick Reference
The tblCustomers table appears in the Relationships window.
To Define Table
5. u
Add the tblCustomerTours table and tblTours table to the Relationships:
Relationships window.
1. In the Database window,
T
ON Ae
You can close the Show Table window when you have finished adding all the tables click the
that you want to relate to one another. Relationships
6.
b
Click Close to close the Show Table dialog box. button on the toolbar.
U
You’re ready to start relating the tables you added. Relating tables may sound difficult, Or…
ALto
but it’s really nothing more than dragging and dropping the field you want to use to Right-click any blank area
link one table to the other. Before you can drag and drop the matching field from one in the Database window
table to the other, you have to make sure that the linking fields in both tables are and select
visible. Relationships.
7.
EVot
Drag the TourID field from the tblTours table to the TourID field in the 2. If necessary, click the
tblCustomerTours table, as shown in Figure 5-5.
Show Table button
Dragging a field from one table to another in the Relationships window links the two on the toolbar.
N
about where you point, click, drag, and drop. You need to be very accurate and 4. Repeat Step 4 for each
drag the pointer right next to the field you’re linking to. table you want to use in
The Edit Relationships dialog box appears as shown in Figure 5-4. What’s especially the relationship.
tFio
important here is the Enforce Referential Integrity check box. Referential integrity 5. Click Close.
helps you avoid “orphan” records and maintains database accuracy. For example, 6. Click the related field in
checking the Referential Integrity box would ensure that you could not enter an invoice the first table and drag it
for a customer in an Invoice table unless that same customer existed in a Customers to the related field in the
ua
table. We’ll discuss referential integrity more later in the chapter. second table.
8. Click Create to create the relationship between the tblTours and 7. Specify any referential
tblCustomerTours tables. integrity and/or join type
al
The Edit Relationships dialog box closes and a line appears between the two tables’ options (optional).
TourID fields, indicating that the tables are linked, as shown in Figure 5-6. 8. Click Create to create the
Ev
g
in
Lesson 5-3: Enforcing Referential
Integrity
in
E tra
Figure 5-7 Enforce Referential Integrity
Ensures that you don’t accidentally change or
The Edit Relationships delete related data in one table but not in the
dialog box. other.
UfSor
Figure 5-8 Cascade Update Related Fields
When you change data in the main field of one
The Relationships window. table, Access will automatically update the
The relationship line matching data in the related table.
between the tblCustomers
Nd
table and the Cascade Delete Related Records
When you delete a record in the main table,
tblCustomerTours table Access will automatically delete any matching
LY IOse
indicates a one-to-many Figure 5-7 records in the related table.
relationship.
table.
• The ∞ (infinity) symbol indicates
U
When you create a relationship between two tables, it is usually a good idea to enforce
referential integrity. So what does this technical-sounding phrase mean? Referential integrity
keeps records in related fields valid and accurate. Referential integrity ensures that you don’t
N
accidentally change or delete related data in one table but not in the other. For example, say
you were using two related Social Security fields to link two tables. Referential integrity
would not allow you to change the Social Security number in one record without changing the
OnR:
you can relate it to a Number field with a Long Integer Field size.)
• Both tables are in the same Access database.
• You can’t have a record in a related table unless a matching record already exists in the
al
primary table. Orphan data in a related table is the most common problem people
encounter when attempting to establish referential integrity.
Once you have established referential integrity, the following rules are set:
Ev
• You can’t add a record to a related table unless a matching record already exists in the
primary table.
g
• You can’t change the value of a primary key in the primary table if matching records exist
in the related table (unless you select the Cascade Update Related Fields option).
in
• You can’t delete a record from a primary table if matching records exist in a related table
(unless you select the Cascade Delete Related Records option).
in
In this lesson you will learn how to enforce referential integrity. You should still have the
Relationships window open from the previous lesson in order to complete this lesson.
E tra
First, let’s establish a relationship between the tblCustomers table and the tblCustomerTours
table…
1. Drag the CustomerID field from the tblCustomers table to the
CustomerID field in the tblCustomerTours table.
UfSor
The Edit Relationships dialog box appears. We want to enforce referential integrity so
that you can’t enter a CustomerID in the tblCustomerTours table unless that
CustomerID number already exists in the tblCustomers table.
2. Check the Enforce Referential Integrity box.
This will enforce referential integrity between the tables. If you get an error message,
Nd
it’s because your tables and fields don’t meet all the required conditions listed on the
previous page.
LY IOse
There are two other very important boxes in the Edit Relationships dialog box: Quick Reference
• Cascade Update Related Fields To Enforce Referential
When you change data in the main field of one table, Access will automatically
u Integrity:
update the matching data in the related table.
1. In the Database window,
• Cascade Delete Related Records
T click the
ON Ae
When you delete a record in the main table, Access will automatically delete any Relationships
matching records in the related table. button on the toolbar.
b
These are both very powerful options—think twice before using them. Or…
3.
U
Check both the Cascade Update Related Fields box and the Cascade Right-click any blank area
ALto
tblCustomerTours tables.
Access creates the relationship between the two tables and enforces referential integrity for the relationship you
between them. Notice that the join line between the tblCustomers table and the want to work with.
N
tblCustomerTours table looks a little different. This relationship indicates that 3. Check the Enforce
referential integrity is being enforced between the two tables and that the tables have a Referential Integrity
one-to-many relationship (more about that later). box.
5.
OnR:
Close the Relationships window and click Yes to save the changes you 4. If you want changes to
made. the primary field of the
primary table copied to
tFio
In the next lesson you will get to test the results of your new referential integrity settings. the related field in the
related table, check the
Cascade Update
Related Fields box.
ua
6. Click OK.
g
in
Lesson 5-4: Testing Referential
Integrity and Printing and Deleting
in
Table Relationships
E tra
Figure 5-9
UfSor
The Cascade Delete
Related Records option
automatically deletes
orphan records in related
tables. Here Access asks Figure 5-9
you to confirm the deletion
Nd
of any related records.
LY IOse
Figure 5-10
Because a record doesn’t
exist in the tblCustomers u
table, referential integrity Figure 5-10
will not let you add an
T
orphan record. In this lesson you will get to test the referential integrity rules you established in the previous
ON Ae
lesson. You just went over it, but since this referential integrity stuff is a little tricky and
b
• You can’t add a record to a related table unless a matching record already exists in the
primary table.
• You can’t change the value of a primary key in the primary table if matching records exist
in the related table (unless you select the Cascade Update Related Fields option).
EVot
• You can’t delete a record from a primary table if matching records exist in a related table
(unless you select the Cascade Delete Related Records option).
N
Think you have a better understanding of referential integrity yet? No? This lesson will give
you a chance to work with some related tables where referential integrity has been set. You
will also learn how to delete a relationship between two tables.
OnR:
2. Click on the record selector for the record with the CustomerID 1
(Antonio Rommero) and click the Delete Record button on the toolbar.
Because you enabled both referential integrity and cascaded deletes in the previous
ua
lesson, Access displays the dialog box shown in Figure 5-9. Access wants you to
confirm your deletion, as deleting the customer record will delete any related data for
the customer in the tblCustomerTours table.
3.
al
Click Yes.
Access deletes the record from the tblCustomers table and any related tours for the
customer in the tblCustomerTours table. If you hadn’t enforced referential integrity
Ev
between these tables, you would be left with one or more “orphan” records for Antonio
Rommero in the tblCustomerTours table.
g
4. Close the tblCustomers table and open the tblCustomerTours table in
Datasheet View.
in
Yikes! The tblCustomerTours table contains a lot of ID number fields, such as
CustomerID and TourID. Unless you have a printed a list of these ID numbers (or have
in
a super-human memory), you won’t know which CustomerID to enter. (By the way,
this is why you will want to use a lot of forms and queries in relational databases—to
hide all the technical inner workings of a database from your hapless users.)
E tra
Anyway, let’s try adding a new record to the tblCustomerTours table.
5. Click the New Record button on the Record Navigation bar.
Access adds a new blank record to the table.
6. Enter a new record using the following information: Relationships
UfSor
button
CustomerID EmployeeID TourID Number of Tickets Date
1 4 2 1 4/2/00
First Class Smoker Ship Via Cost
Nd
No No FedEx 450
Before you finish adding the record, it’s very important that you remember that you
LY IOse
deleted the CustomerID 1 record back in Steps 2 and 3. Since you enforced referential
integrity between the two related CustomerID fields, watch what happens when you try
to add the record… Quick Reference
7.
u
Finish adding the record by pressing <Tab> or clicking in any other
record when you have finished entering the record’s information.
T To Print the Relationships
Window:
ON Ae
Because a CustomerID 1 doesn’t exist in the tblCustomers table, a dialog box appears, 1. In the Database window,
as shown in Figure 5-10, informing you that Access can’t add the record because doing click the
b
other two topics in this lesson—printing and deleting table relationships. Relationships.
10. Click the Relationships button on the toolbar. 2. Select File → Print
Relationships from the
N
Sometimes you may want a printed hard copy of the Relationships window. menu.
11. Select File → Print Relationships from the menu. 3. Modify the report that
A report appears in Print Preview. You don’t actually need to print anything for now, appears in Print Preview,
OnR:
Sometimes you may want to delete the relationship between two tables. Access is very
restrictive about letting you modify a related table, and often you must temporarily To Delete a Table
delete the relationship between two tables, modify one of the tables, and then re- Relationship:
connect them. Here’s how to delete a table relationship. 1. Open the Relationships
ua
13. Click the join line between the tblTours table and the tblCustomerTours window.
table to select it and press <Delete>. 2. Click the join line that
NOTE: Clicking a tiny join line between two tables requires a lot of mouse connects the tables and
al
dexterity—you probably will have to try several times before you get it. press <Delete>.
Access asks you to confirm the deletion. Let’s leave the table relationship be for now. 3. Click Yes to confirm the
deletion.
Ev
g
in
Lesson 5-5: Understanding
Relationship Types
in
E tra
Figure 5-11
The Edit Relationships
dialog box indicates the
type of relationship that
UfSor
exists between two tables.
Nd
Indicates the type of relationship that
exists between two tables.
LY IOse
Figure 5-11
When you link two tables together, they form one of three possible relationships. This
information is rather technical, but it’s good to know if you’re working with related or linked
u
tables. There isn’t a step-by-step exercise in this lesson—all you have to do is look over Table
5-10: Types of Relationships to get a better understanding of table relationships.
T
ON Ae
Table 5-10: Types of Relationships
b
Relationship Description
U
ALto
g
in
in
E tra
UfSor
Nd
LY IOse
T u
ON Ae
U b
ALto
EVot
N
OnR:
tFio
ua
al
Ev
g
in
Chapter Five Review
in
Lesson Summary
E tra
Understanding Table Relationships
UfSor
• Make sure that you have a good understanding of table relationships.
Nd
necessary, click the Show Table button on the toolbar, click the table you want, and click Add.
LY IOse
Repeat for each for table you want to use in the relationship and click Close when you’re finished.
Click the related field in the first table and drag it to the related field in the second table, specify any
referential integrity and/or join type options (optional). Click Create to create the relationship.
u
Enforcing Referential Integrity
T
• To Enforce Referential Integrity: In the Database window, click the Relationships button on
ON Ae
the toolbar or right-click any blank area in the Database window and select Relationships. Double-
click the join line for the relationship you want to work with and check the Enforce Referential
b
Integrity box. If you want changes to the primary field of the primary table copied to the related
U
field in the related table, check the Cascade Update Related Fields box, or if you want Access to
ALto
automatically delete orphan records in the related table, check the Cascade Delete Related
Records box. Then Click OK.
Relationships
• To Print the Relationships Window: In the Database window, click the Relationships button
N
on the toolbar or right-click any blank area in the Database window and select Relationships.
Select File → Print Relationships from the menu. Modify the report that appears in Print Preview,
if necessary, and then click the Print button on the toolbar.
OnR:
• To Delete a Table Relationship: Open the Relationships window, click the join line that
connects the tables, and press <Delete>. Click Yes to confirm the deletion.
tFio
ua
al
Ev
g
Quiz
in
1. You can use fields with different data types to link two tables. (True or
in
False?)
E tra
2. Which of the following statements is NOT true?
A. Click the Relationships button on the toolbar to display the table relationships in a
database.
B. Once you have added the required tables to the Relationships window, you can relate
the tables by clicking the related field in the first table and dragging it to the related
UfSor
field in the second table.
C. Referential integrity keeps records in related fields valid and accurate.
D. For most people, table relationships are an easy-to-understand, straightforward
concept.
Nd
3. You have created a relationship between a Customers table and a related
Customer Orders table and have established referential integrity in this
LY IOse
relationship without the Cascade Delete Related Records option. Can you
delete a record in the Customers table if it has related records in the
Customer Orders table? (Yes or No?)
u
4. If the Cascade Delete Related Records referential integrity option is
T
selected, when you delete a record in the main table, Access will
ON Ae
automatically delete any matching records in the related table. (True or
b
False?)
U
Homework
1. Open the Homework database.
ua
2. Open the Customers table in Design View. Set the SSN field as the table’s primary
key (if it isn’t already). Save your changes and close the Customers table.
al
3. Using the Relationship window, establish a relationship between the Customers table
and the Insurance Claims table, using the SSN field to join the two tables.
Ev
g
5. Enable Cascade Update Related Fields and Cascade Delete Related Records for the
Customers/Insurance Claims relationship.
in
6. Close the Relationships window.
7. Close the Homework database.
in
Quiz Answers
E tra
1. False. With the exception of AutoNumber and Number fields, related fields must
always have the same data type in order to be used to join two tables.
UfSor
2. D. If only this were true! The truth is, understanding how to create and work with
table relationships is a concept that most users struggle with initially.
3. No. Referential integrity would prevent you from deleting a record in a primary table
if it has records in a related table (unless the Cascade Delete Related Records option
is selected).
Nd
4. True. The Cascade Delete Related Records option automatically deletes records in
LY IOse
any related tables.
5. C. Click the Relationships button on the toolbar to display the relationships in a
database.
u
6. B. You can add a table to the Relationships window by clicking the Show Table
button on the toolbar.
T
ON Ae
U b
ALto
EVot
N
OnR:
tFio
ua
al
Ev
E tra
Working with
UfSor
Queries
Nd
LY IOse
Chapter Objectives: ; Prerequisites
• Understand the various types of queries and their purposes • How to use menus,
u toolbars, dialog boxes,
• Create queries based on more than one table and shortcut
keystrokes.
T
• Create queries that calculate and summarize information
ON Ae
• How to open and
• Use the Expression Builder to create expressions modify database
b
objects.
• Create parameter queries that prompt the user for information
U
• A basic understanding
ALto
• Create queries that find duplicate and unmatched records of queries: how to
specify criteria and sort
• Create action queries that delete, update, append, and export information.
information
EVot
Queries are the stars of Microsoft Access. Queries make sense out of all the thousands of
jumbled records and display exactly what you need to know. Queries discover things like
OnR:
what the average price of tea in China is or which customers bought the most parakeet food
from your company. Queries can even make widespread changes to the records in your
tFio
database without wearing out your mouse and keyboard! For example, a delete query can
automatically delete a whole bunch of records that meet your criteria.
In this chapter you will learn how to harness the power of queries. First you will learn about
all the different types of queries: simple select queries, parameter queries that prompt you for
ua
difficult database objects, and learning how to fully utilize queries isn’t something you can
learn in an afternoon. By the time you finish this chapter, however, you will have a good start
towards understanding and mastering queries.
Ev
182 Microsoft Access 2003
g
in
Lesson 6-1: A Quick Review
in
Field list Table name
Figure 6-1
E tra
The Query window in
Design View.
Double-click the field you
Figure 6-2 want to appear in the design
grid or drag the field onto the
UfSor
A close-up of the design design grid yourself.
grid.
Design grid (See Figure 6-2
for a closer look.)
Nd
Quick Reference
To Create a Query in
LY IOse
Figure 6-1
Design View: Field names go here.
1. Click the Queries icon in Table in which field
the Objects bar, then u is located
double-click the
Create query in Sort order goes here.
T
Design view icon.
ON Ae
Criteria goes here.
2. Select the table or query
b
you want to use and click Figure 6-2 A check mark means the field will be
displayed in the query results.
Add.
U
3. Repeat Step 2 as Before we start tackling the functions and types of queries, let’s take a step back and review.
ALto
necessary for additional This lesson is more of a “cheat sheet” than an exercise. Hopefully, it will help you remember
tables or queries. Click what you already know about queries.
Close when you’re
finished.
EVot
name, and then click OK. IS NOT NULL IS NOT NULL Finds records whose fields contain values.
g
in
Lesson 6-2: Understanding the
Different Types of Queries
in
E tra
Figure 6-3
Each type of query has its
own icon so that you can
identify it. Table 6-2: Types
UfSor
of Queries describes the
different types of queries.
Nd
LY IOse
Figure 6-3
u
Up until now, when you thought of a query, you were actually probably thinking of a select
query—a particular type of query. Select queries are by far the most common and useful type
T
of query in Access; however, there are other types of queries that are also important. We will
ON Ae
cover most of these query types in this chapter, so here’s a quick overview of the different
types of queries you’ll find in Microsoft Access.
U b
Prompts the user for specific information every time the query is • Refer to Table 6-2: Types
Parameter Query run. of Queries to be able to
identify the various types
N
Crosstab Query Summarizes data in a table format that makes it easy to read and Microsoft Access queries
compare information. and what each of them
does.
OnR:
While select queries display information that matches your criteria, action queries do something to
the data that matches your criteria—such as change or delete it.
Creates a new table from all or part of the data in one or more
tFio
Action Queries
Update Query
raise the prices on all trips to Europe by 15 percent.
Union Query Combines fields from two or more tables or queries into one field
Ev
g
in
Lesson 6-3: Creating a Multiple
Table Query
in
E tra
Figure 6-4
You can manually join two
tables by dragging a field
from one table’s field list to
UfSor
Join related tables by dragging the
the matching field in the related field from one table to the
other table’s field list. corresponding related field in the other
table.
Figure 6-5
Nd
A multible-table query in
Design View. Figure 6-4
LY IOse
T u
ON Ae
U b
ALto
Figure 6-5
EVot
In Access you will often need to look at and analyze information that comes from not one but
several different tables. Since Access is a relational database, it’s easy to establish a
relationship between two or more tables and look at the information that goes together.
N
Just like it sounds, a multiple-table query blends together information from two or more
Run button related tables. Working with a multiple-table query usually isn’t much different from working
Other Ways to Run a with a single-table query. You tell Access which tables you want to use in your query and
OnR:
Query: specify the fields and criteria you want to see. The main difference between a multiple-table
• Open the query from query and a single-table query is that with multiple-table queries, Access creates a link
between related tables. In query Design View, this link (called a join) appears as a line that
tFio
design window. You manually join two tables by dragging a field from one table’s field list to
• In Design View, select the matching field in the other table’s field list. If the tables don’t have any fields in common,
Query → Run from the you must add another table to act as a bridge between them. This lesson will give you some
menu. experience creating a multiple-table query.
al
g
2. Click the Queries icon in the Objects bar then double-click the
Create query in Design view icon.
in
The query design window and Show Table dialog box both appear. You have to select
the tables and/or queries you want to use.
3.
in
Click the tblEmployees table and click Add.
A field list for the tblEmployees table appears in the top half of the query design
window. You also want to add the tblCustomerTours table and the tblTours table to the
E tra
Quick Reference
query.
4. Add the tblCustomerTours table and tblTours table to the query. To Create a Multible-Table
Query in Design View:
When you have finished adding the tables and/or queries to your query, you can close
the Show Table dialog box. 1. Click the Queries icon in
UfSor
the Objects bar, then
5. Click Close. double-click the
If two tables are related, Access will automatically connect their common fields with a Create query in
join line. For example, Access automatically joined the tblTours table and the Design view icon.
tblCustomerTours table because they are already related. If the tables aren’t related you
2. Click the Show Table
Nd
will have to manually join the tables by dragging a field from one table’s field list to
the matching field in the other table’s field list. button if necessary.
Select the table or query
LY IOse
You need to connect the tblEmployees table with the tblCustomerTours table. you want to add and click
6. Click on EmployeeID in the tblEmployees field list and drag and drop it Add.
onto Employee in the tblCustomerTours field list. 3. Repeat Step 2 as
u
NOTE: You can remove a join from a query by clicking the join line (careful—there’s
not much there to click!) and pressing <Delete>.
T necessary for additional
tables or queries. Click
Close when you’re
ON Ae
Next you need to specify the fields you want to appear in the query results. You can
finished.
add fields to the query design grid in two ways:
b
4. If Access doesn’t
• By double-clicking the field on the field list. automatically join the
U
• By clicking and dragging the field down to the design grid yourself. tables, click the related
ALto
Because field lists don’t have much room to display their contents you may have to field in the first table and
scroll up or down the list in order to find the field you want. drag it to the related field
7. Double-click the LastName and FirstName fields in the tblEmployees
in the second table.
Repeat as necessary to
field list.
EVot
8. Double-click the TourName field in the tblTours field list and the Date the field list.
and Cost fields in the tblCustomerTours field list. Or…
Next you need to specify any criteria for the query. For this exercise, you want to see
OnR:
Click the Run button on the toolbar. 8. Close the query window.
Access displays the results of the query. The results show the names of the employees 9. Click Yes to save the
who sold tours and the names, dates, and costs of the tours. query, enter a query
Ev
g
in
Lesson 6-4: Creating a Calculated
Field
in
E tra
Figure 6-6
Creating a calculated field.
Figure 6-7
UfSor
To enter fields in an
expression, type the field
name in brackets ([Order
Total]).
Nd
Figure 6-8
LY IOse
If a field name exists in
more than one table, you
will need to enter the Figure 6-6
name of the table that u Arithmetic operator
contains the field in
brackets ([Customer Bonus: [Cost]*[Commission]
T
ON Ae
Tours]) followed by an
exclamation mark (!).
b
Then type the field name Name of the field Existing field
that will display the names used in the
in brackets ([Order Total]). results of the calculation must
U
calculation, be enclosed in
ALto
followed by a brackets [ ].
colon (:)
Figure 6-7 Arithmetic operator
Bonus: [tblCustomerTours]![Cost]*[tblEmployees]![Commission]
EVot
Name of the field Name of the table Existing field Table names must Existing field
N
that will display the that contains the name be enclosed in name
results of the field, followed by brackets [ ].
calculation, an exclamation
followed by a mark (!)
OnR:
colon (:)
Figure 6-8
tFio
Normally, when you create a database, you should only have to enter the information you
need and not worry about data or values that Access calculates based on information already
in the database. A calculated field performs some type of arithmetic on one or more fields in a
database to come up with a completely new field. For example, if your database has an Order
ua
Total field and a Tax Rate field, Access can calculate these two fields to find out the Sales Tax
for each order: [Order Total] × [Tax Rate] = [Sales Tax].
You must create an expression (or formula) to perform a calculation. To enter fields in an
al
expression, type the field name in brackets ([Order Total]). If a field name exists in more than
one table, you will need to enter the name of the table that contains the field in brackets
([Customer Tours]) followed by an exclamation mark (!). Then type the field name in
Ev
brackets, such as [Order Total]. For example if an Orders table and a Shipping table both
contain a Date field, you would tell Access which of the two Date fields you want to use by
g
typing the table name ([Orders]), an exclamation mark (!), and then the field name ([Date]) or,
in other words, [Orders]![Date]. Yes, calculated fields can be a little confusing at first…
in
This lesson will show you how to add a calculated field to a query.
You can also use the
1.
in
Click the Queries icon in the Objects bar if necessary, click the Expression Builder to
qryEmployeeSales query, and then click Design. help you create your
Instead of creating a query from scratch, you can modify an existing query and save it calculated fields. Click
E tra
with a different name. the Builder button on
2. Click the blank Field cell of the fourth column and type the toolbar, double-
click the field you
Bonus:[Cost]*[Commission].
want to use in the
The expression you entered will create a new calculated field in the query named calculation, click the
UfSor
“Bonus” that will display the results of the Cost field in the tblCustomerTours table button that
multiplied by the Commission field in the tblEmployees table.
corresponds to the
Let’s see the results of our calculated field. calculation you want,
3. Click the Run button on the toolbar. and then click or type
Nd
Access displays the results of the query. The Bonus calculated field multiplies the Cost any other fields or
field by the Commission field in each record and displays the results. values you want to use.
LY IOse
Save your changes in a new query with a different name. Here’s how:
4. Select File → Save As from the menu.
The Save As dialog box appears. u Quick Reference
5. Type qryEmployeeBonus in the Save Query ‘qryEmployeeSales’ To: To Create an Expression or
box and click OK.
T
Calculation in a Query:
ON Ae
Access saves your changes in a new query named “qryEmployeeBonus.” 1. Display the query in Design
6.
b
include math symbols such as the plus sign (+) to perform addition between values and the blank column in the design
ALto
Operator Description
4. Enter the expression you
* Multiplication want Access to calculate,
N
g
in
Lesson 6-5: Working with
Expressions and the Expression
in
Builder
E tra
Figure 6-9
The expression
UfSor
The Expression Builder appears here.
makes it easy to create
expressions and
calculations by letting you Expression buttons
select the fields and
Current table or
operators you want to use
Nd
query
in the expression.
LY IOse
T u
Figure 6-9
ON Ae
Fields in the current
query or table
b
You can add calculations to queries, forms, and reports by typing an expression, or a formula
U
that tells Access exactly what to calculate. An expression can be any combination of values,
ALto
identifiers (such as the value in a field), and operators that result in a value. Here’s an example
of an expression that calculates profit from two fields called Income and Expenses:
Profit: [Income] – [Expenses]
EVot
Number fields aren’t the only types of fields that you can use in expressions—you can also
perform calculations with dates, times, and text data.
The problem with creating expressions is you have to enter a formula so that Access
OnR:
understands it (and believe me, Access isn’t very bright). For example, when you create an
expression, some types of information must be enclosed between special characters so that
Access knows what type of information it is—table names and field names must be enclosed
tFio
in [brackets], text strings in "quotation marks," and so on. Table 6-4: How Types of Data
Should Look in an Expression has more information about how to use various elements in an
expression.
ua
If you know what you want an expression to do but not how to write it, you can try using the
Expression Builder. The Expression Builder lets you pick the fields, mathematical symbols,
and functions you can use to create an expression.
al
This lesson will give you some more experience writing expressions—both on your own and
using the Expression Builder.
Ev
g
2. Position the mouse over the top of the Normal Price field ( changes to
) and click to select the field. Press <Insert> to add a new column.
in
A column is inserted before the Normal Price column. In the next step, you will learn
how to create one of the most common database functions: how to combine the
in
tblEmployee table’s FirstName and LastName fields to display the full name.
3. Type Agent:[FirstName]&" "&[LastName] in the new blank Field row.
The ampersand (&) symbol is used to combine or concatenate two or more text fields. Build button
E tra
The " " adds a space between the [FirstName] and [LastName] fields. Other Ways to Use the
Next you need to enter an expression that calculates the cost of the tour by multiplying Expression Builder:
the Number of Tickets field by the Normal Price field. You will use the Expression • Right-click in any field
Builder to help you write this expression. and select Build from
UfSor
4. Click the first blank field row and click the Build button on the toolbar. the shortcut menu.
The Expression Builder appears, as shown in Figure 6-9. The Expression Builder
contains an area where you can build the expression, buttons you can use to build the
expression, and the fields and controls in the current query, report, or form.
5. Double-click Normal Price, click the Multiplication button, and Run button
Nd
double-click Number of Tickets. Other Ways to Run a
Query:
LY IOse
The completed expression appears in the Expression list box, as shown in Figure 6-9.
You’re finished writing the expression so you can close the Expression Builder. • Open the query from
the Database window.
6. Click OK.
u • In Design View, click
The Expression Builder closes. Add a meaningful label to the new calculated field.
7. In the new calculated field, replace the Expr1: label with Total:
the View button
T
on the toolbar.
ON Ae
The edited expression should read Total:[Normal Price]*[Number of Tickets]. Let’s see
the results of the new query. • In Design View, select
b
The query combines the FirstName and LastName fields in the new Agent field and
ALto
Microsoft Access is very strict about how you write your expressions. If your expressions with the Expression
aren’t written in the correct syntax, they won’t work. Use the following table as a guideline Builder:
for adding fields, text, and constants to your expressions.
1. Display the query in
N
Design View.
Table 6-4: How Types of Data Should Look in an Expression 2. Click the Field row of a
Type of Data How It Should Look blank column in the
OnR:
Date/Time #20-Mar-99# (Access will add the # symbols) 3. Click the Build
tFio
Concatenated (Combined) Text and Fields [Last]& ", "&[First] button that corresponds to
the calculation you want,
Calculated Field (Using Two Fields) [SalePrice]-[Cost] and then click or type any
other fields or values you
al
g
in
Lesson 6-6: Using an IIF Function
in
Figure 6-10 Rebate: IIF([First Class]=True,50,25)
E tra
The syntax for the IIF
Field name Function Logical Test Value if True Value if False
function. Value or Value that is Value that is
Figure 6-10
expression that returned if Logical returned if Logical
Figure 6-11 can be evaluated Test is True Test is False
to True or False
UfSor
Here the IIF function
evaluates the value in the
First Class field and
returns 50 if the First IF First Class = True
Class field is True and 25 (or 1)…
if the First Class field is
Nd
False. …Then Rebate = 50…
LY IOse
…Otherwise (if First Class
does not = True or 1)
Then Rebate = 25
Figure 6-11 T u
Functions are used to create more complicated calculations or expressions than operators can.
ON Ae
For example, the SUM function adds several values together, and the IPmt function calculates
A plus symbol ( ) on a the loan payments based on an interest rate, the length of the loan, and the principal amount of
b
all the subfolders it There are several hundred functions in Access, but all of them are used in a similar way: the
ALto
contains are hidden. name of the function, followed by the arguments in parenthesis. An argument in Access is the
Double-click the value a function uses to perform its calculation—not the heated disagreement you have over
folder to display the political views. For example, the argument in the formula πr2 would be r, or the radius, used
hidden subfolders. to find the area of a circle.
EVot
This lesson introduces a very useful database function: the IIF function. The IIF function is a
conditional function or logical function because it evaluates a condition and returns one value
N
if the condition is true and another value if the condition is false. For example, you could use
the IIF function in an invoice to create a formula that would subtract a 5-percent discount
from the invoice if the total were more than 500 dollars—otherwise, the IIF Function
OnR:
2. Click the blank field row in the fifth column and click the Build button on
the toolbar.
Ev
g
The bottom-left window of the Expression Builder displays several folders that contain
lots of information. For example, the Tables folder contains a list of all the tables in the
in
current database. These folders are displayed in a hierarchical view. A plus symbol
( ) or a minus symbol ( ) on a folder means a folder contains several subfolders.
Normally, these subfolders are hidden. You can display the hidden folders within a
in
folder by double-clicking the folder. To see the contents of a folder, simply select the
folder—its contents will appear in the middle and left windows.
E tra
To use one of the built-in functions, double-click the Functions folder and select the
Built-In Functions folder in the bottom-left window.
3. Double-click the folder in the bottom-left window.
The Functions folder expands and displays its contents. The Built-In Functions folder
contains several hundred functions that are included in Access.
UfSor
4. Click the Built-In Functions folder.
When you select the Built-In Functions folder in the left window, the middle window
displays the function categories you can use, and the right window displays the
functions in the selected category. If you know the category of the function you want to
Nd
use, you can select it in the middle window to narrow down your choices in the right
window.
LY IOse
5. Scroll down the bottom-middle window and find and select the Program
Flow function category.
The right window displays the Program Flow functions.
6.
u
Double-click the IIF function in the right window. Quick Reference
Access adds IIF («expr», «truepart», «falsepart») to the expression box. Now that you To Create an IIF
T
ON Ae
know the proper syntax of the IFF function, you need to replace the argument names (IF…THEN) Function:
with the data values. You can double-click to select any argument name so that you can 1. Display the query in
b
You need to specify the logical test—if the passenger flew first class or not. blank column in the
8. Double-click the Tables folder in the left window, click the design grid.
tblCustomers folder, and then double-click the First Class field in the 3. Enter the field name
middle window. followed by a : (colon).
EVot
The Expression Builder adds the First Class field to the expression. Finish the rest of 4. Type the expression using
the logical test. the syntax
9.
N
IIF(«expr»,
Type =True. «truepart»,
Your expression should read IIf ([First Class]=True, «truepart», «falsepart»). Now you «falsepart»)
have to replace the «truepart» and «falsepart» arguments with the values you want to
Or…
OnR:
Double-click the
11. Click OK. Functions folder in
The Expression Builder closes. We need to give the new calculated control a more the bottom-left window,
meaningful name… click the Built-In
ua
12. In the new calculated field, replace the Expr1: label with Rebate: Functions folder, and
scroll down and double-
Let’s see the results of the new query.
click the IIF function.
13. Click the Run button on the toolbar. Replace the parts of the
al
The IIF expression in the new Rebate field evaluates the First Class field and returns a pasted IIF function with
50-dollar rebate if the customer flew first class and a 25-dollar rebate if not. the fields and values you
Ev
g
in
Lesson 6-7: Summarizing Groups
of Records
in
E tra
Figure 6-12
Using a query to find the Click the Totals
button to display the
total number of tickets and Total row.
sales, grouped by the
UfSor
TourName field and the
Number of Tickets field.
Nd
Total Row
LY IOse
Figure 6-12
T u
This field will be
used to group
The query will find
the total, or sum, of
this field.
This field will be used to limit the
records grouped and calculated
in the query. Notice the Show box
ON Ae
the query. is unchecked.
U b
When you work with queries, you will often be less interested in the individual records and
ALto
more interested in summarized information about groups of records. A query can calculate
information about a group of records in one or more tables. For example, you could create a
query that finds the total amount of tea your company sold to China in 1998 or how much all
that tea cost. The Total row lets you group and summarize information in a query. The Total
EVot
row normally is tucked away from view in the query design window—you can make the Total
appear by clicking the Totals button on the toolbar or by selecting View → Totals from the
menu. Once the Total row is displayed, you can tell Access how you want to summarize the
N
A datasheet calculated
fields.
with a SUM function.
1. Open the qryTourSales query in Design View.
OnR:
First you need to add the field that you want to group data by onto the design grid. You
want to calculate the total sales and number of tickets sold for each tour package, so
you will group the query by the TourName field.
tFio
Total row to group the records by the TourName field. Next you need to select the
fields you want to summarize and the calculation you want to perform on them.
g
5. Click the Number of Tickets column’s Total row and click the
arrow that appears.
in
A list of calculations appears. You simply select the calculation you want to perform on
the field. Table 6-5: Total Options describes the available calculations.
6.
in
Select Sum from the list.
This will total the values in the Number of Tickets field.
7.
E tra
Click the Cost column’s Total row, click the arrow, and select Sum
from the list.
You can specify criteria to limit the records you want to be calculated—simply enter
the criteria in the Criteria row of any grouped or calculated fields. If the field you want
to use for the criteria isn’t one of the grouped or calculated fields, you must use the
UfSor
Where option in the field’s Total row. The Where option limits the records used in the
calculation without being included in the query results.
You want to calculate only those records from the second quarter of the year.
8. Double-click the Date field in the tblCustomerTours field list.
Nd
Here’s how to add criteria to the Date field.
9. Click the Date column’s Total row, click the arrow, and select
LY IOse
Where from the list.
The Where option is used only to limit records—its results cannot be displayed in the
results of the query. Access knows this and automatically turns off the Show checkbox.
10.
u
Click the Date column’s Criteria row and type Between 4/1/00 and
6/30/00.
T Quick Reference
To Calculate or
ON Ae
You’re ready to see the results of the new query. Summarize a Group of
11. Click the Run button on the toolbar. Records:
b
Access displays the results of the query, which calculates the total sales and number of 1. Display the query in
U
12. Save the query as qryTourTotals and then close the query. 2. If necessary, click the
Totals button the
Table 6-5: Total Options toolbar.
EVot
Where Specifies criteria for a field to limit the records included in a calculation. row.
g
in
Lesson 6-8: Display Top or Bottom
Values
in
E tra
Figure 6-13 Select the number of top
or bottom values to
Telling Access to display display.
only the top five values in
a query.
UfSor
Figure 6-14
Access displays the top Select the way you want to
five values it finds in the sort the records:
Nd
query. • Ascending: Displays
bottom values.
Figure 6-15
LY IOse
• Descending: Displays
top values.
Access displays the five
tours with the lowest total
Figure 6-13
sales. T u
ON Ae
U b
ALto
If all you care about is the highest or lowest values produced by a query, you can use the Top
Values list in the Query Design toolbar to display only these records. For example, you could
N
use the Top Values list to display the ten largest or smallest orders in the Invoices table.
This lesson explains how you can use the Top Values list to display the top or bottom values
in a query.
OnR:
Move to the next step and add the fields you want to see in your query.
2. Double-click the TourName field in the tblTours field list, and the Cost
and Smoker fields in the tblCustomerTours field list.
You want to create a query that retrieves the five most expensive nonsmoking tours.
ua
Sort row works a little differently when you’re using top or bottom values:
• Ascending: Displays bottom values.
Ev
g
4. Click the Cost field’s Sort Row and select Descending.
Next you have to use the Top Values list to specify the number of top values you want
in
to be displayed in your query results.
5. Click the Top Values list arrow on the toolbar and select 5.
in
This will display the five most expensive tickets. You’re ready to run the query. Top Values list
6. Click the Run button on the toolbar.
E tra
Access displays the results of the query, as shown in Figure 6-14. (There are more than
five records because some of the records have the same values.)
7. Click the View button on the toolbar to display the query in Design View.
You can also use the Top Values feature to display the top or bottom values from a
UfSor
calculation. Let’s modify the query so that it calculates the total sales of nonsmoking
tour sales.
8. Click the Totals button on the toolbar.
The Total row appears. You need to specify which field you want to use to group the Totals button
query, which field(s) you want to be calculated, and which fields are used to limit the
Nd
number of records displayed in the query.
You want to group records using the TourName field, and since its Total row already
LY IOse
displays Group By, you can leave it as it is. You will need to tweak the Total row for
both the Cost and Smoker fields, however.
9. Click the Cost column’s Total row, click the
u arrow, and select Sum
from the list.
This will total the Cost field. The Smoker field is used as criteria to limit the records
T
ON Ae
displayed to only nonsmokers—it shouldn’t be included in the query results. Move on
to the next step to tell Access this.
b
10. Click the Smokers column’s Total row, click the arrow, and select
Where from the list.
U
ALto
One more change before we run the query—this time instead of displaying the top
values for the Cost field we want to display its bottom values.
11. Click the Cost field’s Sort Row and select Ascending.
This will summarize the five tours with the lowest sales (for nonsmokers). Let’s see the
EVot
results…
Quick Reference
12. Click the Run button on the toolbar.
N
Access displays the results of the query, as shown in Figure 6-15. To View Top or Bottom
Values:
13. Save the query as qryBottomTours and then close the query.
1. Display the query in
OnR:
This table explains what each of the options in the Top Values list does. Design View.
2. Click the appropriate Sort
Table 6-6: The Top Values List field and select either:
tFio
Type a number, such as 15 in the Top Values box The top 15 (or specified number of) records top values
Click 5% or 25% from the Top Values List The top 5 or 25 percent of records 3. Select an option from the
Top Values list
Type a percentage, such as 20%, in the Top The top 20 percent (or specified percent) of on the toolbar.
al
g
in
Lesson 6-9: Parameter Queries
in
Figure 6-16
E tra
Enter a parameter by
entering a message or
prompt enclosed in
[brackets] in the field’s
criteria row.
UfSor
Figure 6-17
The parameter query
prompts the user to enter
the state.
Nd
Figure 6-18
LY IOse
The results of the
parameter query.
Figure 6-16
T u Parameter Parameter
ON Ae
U b
ALto
Figure 6-17
Figure 6-18
EVot
Getting tired of modifying a query every time you want to use a new criterion? A parameter
query is your answer. A parameter query prompts the user for the query’s criteria. For
N
example, you could create a Regional Sales query that would ask for the name of the state that
you want to filter by.
Creating a parameter query is easy. All you have to do is click the Criteria row for the field
OnR:
that you want to use as a parameter and type a message, enclosed in [brackets], that you want
Access to display when you run the query.
1. Open the qryTourSales query in Design View.
tFio
As always, you need to add the field that you want to group data by onto the design
grid. This time we want to create a query that summarizes total employee sales. Here
are the fields that we will use in the query:
ua
Next you need to tell the query that you want to group and summarize the query.
3. Click the Totals button on the toolbar.
Ev
Totals button The Total row appears. You need to specify which field(s) you want to use to group the
query, which field(s) you want to be calculated, and which field(s) you want to use to
limit the number of records displayed in the query.
g
You want to group records using the FirstName, LastName, and State fields and find
the total of the Cost field.
in
4. Click the Cost column’s Total row, click the arrow, and select Sum
from the list.
in
This will total the Cost field. We will use the Date field as criteria to limit the records
to those that fall between two dates. Instead of entering a criteria expression with two
fixed date values, such as “Between 1/1/00 and 3/31/00,” we will create two
E tra
parameters that will prompt the user to enter the two date values each time they run the
query.
5. Click the Date column’s Criteria row and type Between [Enter start
date] and [Enter end date].
UfSor
You’ve just created two parameters—the [Enter start date] parameter and the [Enter
end date] parameter.
Since the Date field is only being used as a criteria field, you need to select the Where
option from its Total row.
6. Click the Date column’s Total row, click the arrow, and select
Nd
Where from the list.
LY IOse
The Show box automatically turns off, indicating that the Date field will not appear in
the query results.
Let’s add one more parameter—one that prompts the user to enter the state where the
tour was sold. u
7. Click the State column’s Criteria row and type [Enter the state].
T
This will prompt the user to enter the name of the state.
ON Ae
Since the State field is only being used as a criteria field, you need to select the Where
b
Access prompts you for the next parameter—the start date. 1. Display the query in Design
11. Type 1/1/00 and click OK. View.
Access prompts you for the last parameter—the end date. 2. Click the Criteria row for
OnR:
of your query may be different if you put the FirstName field on the design grid before surrounded by square
the LastName field. brackets [ ].
13. Save the query as qryParameter and then close the query.
3. Click the View button
ua
Some advanced Access developers use custom-made forms to provide parameter queries with or Run button on the
their information. If developers bind a parameter to the controls on a form (such as toolbar to run the query.
[frmCustomers]![Name]), users can fill out one dialog box instead of having to fill out five or
4. Enter a criteria value in
six pop-up dialog boxes.
response to the prompt and
al
click OK.
Ev
g
in
Lesson 6-10: Finding Duplicate
Records
in
E tra
Figure 6-19
Step One: Select the table
or query you want to
search for duplicate
UfSor
values.
Figure 6-20
Step Two: Select the field
Nd
or fields that contain the
duplicate values.
LY IOse
Figure 6-19
Figure 6-21
The query displays those
records that have u
duplicate values in both
the LastName and
T
ON Ae
FirstName fields.
U b
ALto
Figure 6-21
Figure 6-20
EVot
The Find Duplicates Query Wizard helps you find records that have the same value in one or
more fields. So when would you need to use a Find Duplicates Query? Here are a few
scenarios:
N
• To search for duplicate values in an Orders table to find out which customers have placed
more than one order.
•
OnR:
To search for duplicate values in several fields to search for data-entry errors. For
example, if you and another user accidentally entered the same customers into a table,
you could search for duplicate values in the LastName and FirstName fields to find and
tFio
same customers into a database. Fortunately, you can find the duplicated records by using the
Find Duplicates Query Wizard.
1. From the Database window, click the Queries icon in the Objects bar
al
g
2. Select the Find Duplicates Query Wizard and click OK.
The first step of the Find Duplicates Query Wizard appears, as shown in Figure 6-19.
in
You need to choose the table or query that you want to sift through for duplicate
records.
3.
in
Select the tblCustomers table and click Next.
The second step of the Find Duplicates Query Wizard appears, as shown in Figure
6-20. Here you tell Access which field or fields might contain the duplicate
E tra
information.
Since you are trying to find duplicate customers, you decide to search the FirstName
and LastName fields for duplicate values.
4. Double-click the LastName and FirstName fields.
UfSor
The LastName and FirstName fields appear in the Duplicate-value fields list.
5. Click Next.
The next step of the Find Duplicates Query Wizard appears. You can select any field
(other than the ones you specified in Step 4) that you want to be displayed in the query.
Nd
You decide to display the City and State fields so that you can verify that the records
LY IOse
are duplicates.
6. Double-click the City and State fields. Click Next when you’re finished.
You’re finished! Well, almost. You have to give your query a name, or you can accept
7. Click Finish.
T u
the default name Access gives the query.
ON Ae
Access saves the query with the name “Find duplicates for tblCustomers” and displays
the results of the query, as shown in Figure 6-21.
b
Quick Reference
ALto
click Next.
4. Double-click the field(s)
that may contain the
duplicate values and click
ua
Next.
5. Double-click any
additional fields that you
al
6. Click Finish.
Figure 6-24
Figure 6-23
The Find Unmatched Query Wizard helps you find the records in one table that do not have
matching records in another table. Some scenarios when you might need to create such a
query include:
• To find customers who have never placed an order.
• To find products that have never been purchased.
• To find “orphan” records. If you haven’t enforced referential integrity in your related
tables, deleting a record in one table could leave one or more orphan records in a related
table. For example, if you delete a customer record from a Customer table, you may leave
several unmatched records for that customer in an Order table.
In this lesson you will use the Find Unmatched Query Wizard to create a query to find
customers who have never booked a tour.
1. From the Database window, click the Queries icon in the Objects bar
and click the New button.
The New Query dialog box appears.
5. Verify that the CustomerID field is selected in both tables and click the
button.
The Matching Field area displays the fields used to join the tables (CustomerID <=>
CustomerID).
6. Click Next.
Almost there! Now you have to specify which fields you want to see in the query.
7. Double-click the LastName, FirstName, City, and State fields.
The LastName, FirstName, City, and State fields should all appear in the Selected Quick Reference
fields list.
8. Click Next. To Use the Find
Unmatched Query Wizard:
You have to give your query a name—or you can accept the default name access gives
the query. 1. From the Database
window, click the Queries
9. Click Finish. icon in the Objects bar
Access saves the query with the name “tblCustomers Without Matching and click the New button.
tblCustomerTours” and displays the results of the query, as shown in Figure 6-24. 2. Select the Find
10. Close the query. Unmatched Query
Wizard and click OK.
3. Select the table whose
values you want to
display and click Next.
4. Select the table that
contains the related
records and click Next.
5. Specify the related fields
that join the two tables,
then click the button
to join the two tables and
click Next.
6. Double-click any
additional fields that you
want to appear in the
query results and click
Next.
7. Click Finish.
A crosstab query in
Design View.
Figure 6-27
Crosstab row
Figure 6-28
There are many ways that queries can help you summarize and analyze all that information in
your database. A crosstab query displays summarized information in a table format that makes
it easy to analyze and compare data. Look at the information displayed in Figure 6-25—
difficult to see the bottom line, isn’t it? Now look what happens when the same information is
placed in a crosstab query, as shown in Figure 6-26. Which do you think is easier to
understand?
You can create a crosstab query in Design View or by using the Crosstab Query Wizard. The
Crosstab Query Wizard is usually much easier, but it does have some limitations:
• If you need to use more than one table or query in the crosstab query, you will first need
to create a separate query that has the tables you want to use.
• You can’t specify any limiting criteria when using the Crosstab Query Wizard. (But you
can always modify the crosstab query in Design View and add the criteria yourself.)
In this lesson you will use the Crosstab Query Wizard to create a query that summarizes
monthly ticket sales by tours.
1. From the Database window, click the Queries icon in the Objects bar
and click the New button.
The New Query dialog box appears.
2. Select the Crosstab Query Wizard and click OK.
The first step of the Crosstab Query Wizard appears. You need to select the table or
query that contains the values you want. For this exercise you will use the
ToursByName query as the source for the crosstab query.
3. Click the Queries option in the View section to display the queries in the
database, select the qryToursByName query, and click Next.
The second step of the Crosstab Query Wizard is which field you want to use as the
row headings for the crosstab. You want to use the TourName field as row headings.
4. Double-click the TourName field and click Next.
The next step is determining which field you want to use as your column headings. You
want to use the Date field as the column heading.
5. Double-click the Date field.
Because you selected a date field, the Crosstab Query Wizard asks by which interval
you want to group the dates: date, month, quarter, year, or date/time. For this exercise
you want the date column to group dates by months.
6. Double-click the Month option.
Probably the most important step in the Crosstab Query Wizard is determining which Quick Reference
field you want to calculate where columns and rows intersect and the type of
To Create a Crosstab
calculation you want to use to summarize the fields.
Query:
7. Select the Number of Tickets field from the Fields list and the Sum
1. From the Database
option from the Functions list, as shown in Figure 6-27. window, click the Queries
This will calculate the total number of tickets sold for each tour, grouped by month. icon in the Objects bar
8. Click Next. and click the New button.
You have to give your crosstab query a name. 2. Select the Crosstab
9. Type qryTicketsByDate and click Finish. Query Wizard and click
OK.
Access saves the query with the name “qryTicketsByDate” and displays the results of
the query, as shown in Figure 6-26. Let’s modify the crosstab query and add some 3. Select the table or query
limiting criteria. you want to use and click
Next.
10. Click the View button to display the crosstab query in Design View.
4. Select the field you want
The crosstab query appears in Design View as shown in Figure 6-28. Notice the to use as the row heading
Crosstab row, which you use to determine if a field should be a column heading, row and click Next.
heading, or value.
5. Select the field you want
11. Double-click the First Class field in the qryToursByName list. to use as the column
You only want to see tours for passengers without first class tickets. heading and click Next.
12. Click the First Class column’s Total row, click the arrow and select 6. Select the field you want
Where from the list. Click the First Class column’s Criteria row and to summarize, the type of
type False. calculation you want to
13. Click the Run button on the toolbar.
use to summarize the
field, and click Next.
Access displays the crosstab query, which only includes non-first class tickets.
7. Type a name for the
14. Close the query without saving your changes. crosstab query and click
Finish.
Figure 6-30
Figure 6-29 The Delete query will …and use this field as the criteria to
delete From this table… select the records you want to delete.
Definitely the most dangerous of all queries is a delete query, a query that deletes a whole
bunch of records at a time. Once you have deleted records using a delete query, you cannot
undo the results—the records are gone forever! Creating a delete query is no different than
creating a select query—with one very important difference: While a select query displays the
records that match your criteria, a delete query deletes those records. For this reason, you
should always preview the results of a delete query in Datasheet View to see which records
will be deleted.
If you want to delete records from multiple tables—for example, a customer and all of that
customer’s orders—you need to do a few things first:
• Define relationships between the tables.
• Establish referential integrity for the join(s) between the tables and turn on the Cascade
Delete Related Records option.
LeAnne Chang, one of North Shore Travel’s managers, decides to open her own competing
travel agency across the street, and being the vindictive person she is, takes all her customers
with her. In this lesson you will create a delete query to delete all the tours sold by LeAnne
Chang.
Selecting a Type
of Query 1. From the Database window, click the Queries icon in the Objects bar
and click the New button.
The New Query dialog box appears.
2. Select Design View and click OK.
The query design window and Show Table dialog box both appear. You have to select
the tables and/or queries you want to use in the delete query.
3. Click the tblEmployees table and click Add.
A field list for the tblEmployees table appears in the top half of the query design
window.
Figure 6-32
Figure 6-31
An append query in
Design View.
An append query takes a group of records from one or more tables or queries in your database
and adds them to another existing table. Append queries are especially useful for importing
information into a table. For example, you could use an append query to import several dozen
customer records from an Excel spreadsheet into an existing table. Of course, you would have
to know how to import the Excel spreadsheet first—and that’s another lesson in and of itself.
There are several rules that you must follow when using an append query.
• The appended data must meet the data validation and referential integrity rules of the
table it is being added to.
• The appended data must have its own unique primary-key values. If the primary-key field
in the table to which the data is being added is an AutoNumber field, do not append that
field—Access will generate new numbers for the new records.
• The type of data in the records you’re adding must match the type of data in the table to
which you’re adding them.
In this lesson you will create an append query to add a new group of tours to the
tblCustomerTours table.
1. From the Database window, click the Queries icon in the Objects bar
and click the New button.
The New Query dialog box appears.
Figure 6-34
Figure 6-35
Like all queries, a make-table query asks a question of the information in one or more tables
and then retrieves results. Instead of displaying the results, however, a make-table query
creates a new table with the results of the query. Make-table queries are useful for:
• Exporting a table to another database or application.
• Creating a backup copy of a table.
• Creating an archive table that stores old records.
• Creating a table that includes information or fields from more than one table.
In this lesson you will create a make-table query to create a table with information about all
China tour records.
Query Type
1. Open the qryTourSales query in Design View. button
First you need to add the fields that you want to include in your new table. Other Ways to Create a
Make Table Query
2. Double-click the TourName field in the tblTours field list, the Number of
• Select Query → Make-
Tickets, Date, and Cost fields in the tblCustomerTours field list, and the
Table Query from the
LastName and FirstName fields in the tblEmployees field list.
menu.
The make-table query will create a table with these fields. Next you need to specify
any limiting criteria.
3. Click the TourName column’s Criteria row and type China.
Quick Reference
Access will add the “quotation marks” around the text string “China” for you. The
make-table query will only include China tours when it creates the new table. To Create a Make-Table
Query:
Here’s how to change the query type to a make-table query:
4. Click the Query Type button arrow and select Make-Table Query from
1. In Query Design View
create a select query,
the list. including any tables,
Access displays the Make Table dialog box, as shown in Figure 6-33. Here you need to fields, calculated fields,
tell Access the name of the new table. and criteria.
5. Type tblChinaTours in the Table Name box and click OK. 2. Click the Query
You’re ready to have the make-table query create the new table. Preview the results of Type button list on the
the query first. toolbar and select Make-
NOTE: As with any action query you should always preview the results in Datasheet Table Query.
View first. Click the View button on the toolbar to display the results of Or…
the make-table query in Datasheet View. Select Query → Make-
6. Click the View button on the toolbar to preview the results of the make- Table Query from the
table query in Datasheet View. menu.
The make-table query displays the records it will use to create the new tblChinaTours 3. Type the name of the
table. table you want to create,
or click the drop-down list
7. Click the View button on the toolbar to return to Design View and click and select a table from
the Run button on the toolbar. the list if you want to
Access asks you to confirm the creation of the tblChinaTours table. replace the existing one.
8. Click Yes. 4. Click one of the following
Access creates the new tblChinaTours table based on the results of the make-table options:
query. Current Database: If the
9. Close the query without saving your changes and open the table is in the currently
tblChinaTours table. open database.
Verify the results of the make-table query, then… Another Database: And
type the name of the
10. Close the tblChinaTours table. other database (including
the path, if necessary).
5. Click OK.
6. Click the View
button on the toolbar to
view the results of the
query or the Run
button on the toolbar and
click Yes to confirm the
creation.
Figure 6-37
Figure 6-38
You can use an update query to change a pile of records at the same time. For example, you
could create an update query to lower prices by eight percent or to change the sales
representative for all your clients in Oregon from “Mr. Potter” to “George Bailey.” Just like
other action queries, you create an update query by first creating a select query and then
converting the select query to an update query.
In this lesson you will create an update query to raise the prices of all trips to Europe by 10
percent.
1. From the Database window, click the Queries icon in the Objects bar
and click the New button.
The New Query dialog box appears.
2. Select Design View and click OK.
The query design window and Show Table dialog box both appear. You have to select
the tables and/or queries you want to use in the update query.
3. Double-click the tblTours table and click Close.
Now you need to convert the Select query to an update query. Here’s how:
g
4. Click the Query Type button arrow and select Update Query from the
list.
in
Access converts the select query to an update query. Notice an Update To row appears Query Type
button
in the design grid. Now you have to specify the fields you want to update.
Other Ways to Create an
5.
in
Double-click the TourID, Normal Price, and First Class Price fields in Update Query
the tblTours field list. • Select Query →
The next step is a little bit tricky—you have to tell Access what fields to update and
E tra
Update Query from the
how to update them. You want to raise the price of both the Normal Price and First menu.
Class Price fields by 10 percent—you will have to write an expression (or formula) in
the Update To rows of both fields to make this little bit of magic happen.
6. Click the Normal Price column’s Update To row and type
UfSor
[Normal Price]+([Normal Price]*.1).
So what does the confusing expression you entered actually mean? Let’s assume the
Normal Price for a record is $100. The expression would then look something like this:
[$100] + ([$100] * .1).
Access first calculates anything it sees in parenthesis, so it multiples $100 × 0.1 (or
Nd
10%) and comes up with $10. Access then adds this $10 to the Normal Price (as in $10
+ $100) and comes up with $110. Make a little more sense? Hope so—because you
LY IOse
have to do the same thing to the First Class Price field.
7. Click the First Class Price column’s Update To row and type Quick Reference
u
[First Class Price]+([First Class Price]*.1).
Next you need to specify any limiting criteria. You want to raise prices for only tours
To Create an Update
Query:
that are in Europe. Sadly, the only way to determine this is by looking at the values in
T
1. In Query Design View
ON Ae
the tblTours table. Here are all the European TourIDs: 1, 2, 3, and 9. You will have to create a select query,
create an OR statement in your query to make sure you get them all. including any tables,
b
8. Click the TourID field’s Criteria row and type 1. fields, calculated fields,
and criteria.
U
This will select the record whose TourID is “1,” but what about the rest?
9.
ALto
Press the <↓> (down arrow key) to select the TourID field’s or Criteria 2. Click the Query
row and type 2. Type button list on the
This will select the records whose TourID is “2.” Go to the next step and finish adding toolbar and select Update
the rest of the OR criteria. Query.
EVot
10. Press the <↓> (down arrow key) to select the TourID field’s second or Or…
Criteria row, type 3, press the <↓> (down arrow key) to select the Select Query → Update
N
TourID field’s third or Criteria row and type 9. Query from the menu.
Compare your query to the one in Figure 6-36. Look the same? Let’s run the update 3. Enter an expression to
query. update the selected field.
OnR:
11. Click the Run button on the toolbar. 4. Enter any criteria, if
needed, to select which
Access asks about the updating the selected records, as shown in Figure 6-37.
records should be
12.
tFio
g
in
Chapter Six Review
in
Lesson Summary
E tra
A Quick Review
UfSor
• To Create a Query in Design View: Click the Queries icon in the Objects bar, then double-click
the Create query in Design view icon. Select the table or query you want to use and click Add.
Repeat as necessary for additional tables or queries that you want to add to the query and click
Close when you’re finished. Double-click the fields that you want to appear in the query or click
and drag the fields onto the design grid. In the design grid, enter any desired search criteria for the
Nd
field in the Criteria box and/or click the Sort box list arrow for the field and select a sort order.
Click the Save button on the toolbar and give a name to the query.
LY IOse
Understanding the Different Types of Queries
• The Types of Queries Are:
u
- Select queries
- Parameter queries
T
- Crosstab queries
ON Ae
- Make-table queries
b
- Append queries
- Delete queries
U
- Update queries
ALto
- Union queries
• To Create a Multiple-Table Query in Design View: Click the Queries icon in the Objects bar,
then double-click the Create query in Design view icon. Select the table or query you want to use
and click Add. Repeat as necessary for additional tables or queries that you want to add to the
N
query and click Close when you’re finished. If Access doesn’t automatically join the tables, click the
related field in the first table and drag it to the related field in the second table. Repeat as
necessary to connect all the tables. Double-click the fields that you want to appear in the query or
OnR:
click and drag the fields onto the design grid. In the design grid, enter any desired search criteria
for the field in the Criteria box and/or click the Sort box list arrow for the field and select a
sort order. Click the Save button on the toolbar and give a name to the query.
tFio
Field row of a blank column in the design grid, enter the field name for the calculated field,
followed by a : (colon), followed by the expression you want Access to calculate, using the proper
syntax (or you can use the Expression Builder to help you create this expression).
al
Ev
g
Working with Expressions and the Expression Builder
in
• To Create an Expression with the Expression Builder: Display the query in Design View. Click
the Field row of a blank column in the design grid, click the Build button on the toolbar,
double-click the field you want to use in the calculation, click the button that corresponds to the
in
calculation you want, and then click or type any other fields or values you want to use. Click OK
when you’re finished.
E tra
Using an IIF Function
• To Create an IIF (IF…THEN) Function: Display the query in Design View. Click the Field row of
a blank column in the design grid, enter the field name followed by a : (colon) and type the
UfSor
expression using the syntax IIF(«expr», «truepart», «falsepart»)(or you
can use the Expression Builder to help you create the IIF expression).
Nd
necessary, click the Totals button on the toolbar. Move the field that you want to group data by
LY IOse
onto the design grid and make sure Group By appears in that field’s Total row. Move the field that
you want to perform calculations on to the design grid. Choose the type of calculation that you want
for each field from the drop-down list in the Total row.
Parameter Queries
ALto
• To Create a Parameter Query: Display the query in Design View, click the Criteria row for the
field you want to use for your parameter criteria, and enter the text of the prompt, surrounded by
square brackets [ ].
EVot
the Objects bar and click the New button. Select the Find Duplicates Query Wizard and click
OK, select the table or query you want to search and click Next, select the field(s) that may contain
the duplicate values and click Next. Double-click any additional fields that you want to appear in
OnR:
• To Use the Find Unmatched Query Wizard: From the Database window, click the Queries icon
in the Objects bar and click the New button. Select the Find Unmatched Query Wizard and click
OK, select the table whose values you want to display and click Next. Select the table that
ua
contains the related records, click Next, specify the related fields that join the two tables, then click
the button to join the two tables and click Next. Double-click any additional fields that you
want to appear in the query results, click Next, and then click Finish.
al
Ev
g
Crosstab Queries
in
• To Create a Crosstab Query From the Database window, click the Queries icon in the Objects
bar and click the New button, then select the Crosstab Query Wizard and click OK. Select the
table or query you want to use in the crosstab query and click Next. Select the field you want to
in
use as the row headings, click Next, select the field you want to use as the column headings, and
click Next. Select the field you want to summarize, the type of calculation you want to use to
summarize the field, click Next, type a name for the crosstab query, and click Finish.
E tra
Delete Queries
• To Create a Delete Query: In Query Design View create a select query, including any tables,
fields, calculated fields, and criteria. Click the Query Type button list on the toolbar and
UfSor
select Delete Query or select Query → Delete Query from the menu. Click the View button
to view the results of the delete query. If you’re satisfied that the appropriate records will be
deleted, click the Run button on the toolbar to delete the records.
Nd
Append Queries
LY IOse
• To Create an Append Query: In Query Design View create a select query, including any tables,
fields, calculated fields, and criteria. Click the Query Type button list on the toolbar and
select Append Query or select Query → Append Query from the menu. Select the table where
u
you want to add the records to from the drop-down list and select one of the following options:
Current Database (If the table is in the currently open database) or Another Database (and type the
name of the other database, including the path, if necessary). Add the fields you want to append
T
ON Ae
and identify a matching field if Access doesn’t supply one. Click OK and click the View
b
button on the toolbar to view the results of the query or the Run button on the toolbar to
append the records.
U
ALto
Make-Table Queries
• To Create a Make-Table Query: In Query Design View create a select query, including any
tables, fields, calculated fields, and criteria. Click the Query Type button list on the toolbar
EVot
and select Make-Table Query or select Query → Make-Table Query from the menu. Type the
name of the table you want to create, or click the drop-down list and select a table from the list if
you want to replace the existing one. Click one of the following options: Current Database (if the
N
table is in the currently open database) or Another Database (and type the name of the other
database, including the path, if necessary). Click OK. Click the View button on the toolbar to
view the results of the query or the Run button on the toolbar to create the new table.
OnR:
Update Queries
tFio
• To Create an Update Query: In Query Design View create a select query, including any tables,
fields, calculated fields, and criteria. Click the Query Type button list on the toolbar and
select Update Query or select Query → Update Query from the menu. Enter an expression to
ua
update the selected field and enter any criteria, if needed, to select which records should be
updated. Click the View button to view the results of the update query. If you’re satisfied that
the appropriate records will be updated, click the Run button on the toolbar to update the
al
records.
Ev
g
Quiz
in
1. Which of the following criterion is NOT written using the proper syntax?
in
A. "Harris"
B. Between 1/1/2000 and 12/31/2000
E tra
C. NO VALUE
D. <500
2. Which of the following types of queries are action queries? (Select all that
apply.)
UfSor
A. Parameter queries.
B. Append queries.
C. Update queries.
D. Crosstab queries.
Nd
3. Which of the following expressions is NOT written in the correct syntax?
LY IOse
A. [Order Total]*[Tax Rate]
B. "Order Total"*0.1
C. [tblCustomerTours]![Cost]*[tblEmployees]![Commission]
D. 100+10 u
4. If you are having trouble remembering how to write expressions using the
T
correct syntax, you can use the Expression Builder to help you create the
ON Ae
expression. (True or False?)
b
A. Something I learned back in high school algebra and thought I would never see
again.
B. A financial expression.
C. Something that belongs in a Microsoft Excel book.
EVot
D. A conditional expression.
6. A query prompts a user for a date and then displays only records that
N
B. A crosstab query.
C. An action query.
D. An update query.
tFio
7. You must create a report if you want to calculate totals for a group of
records, as queries can’t perform this task. (True or False?)
ua
B. A crosstab query.
C. An action query.
D. An update query.
Ev
g
9. Your company finally agreed to buy you a nifty 3COM Palm palmtop. Now
you want to extract your clients from the company’s database and put them
in
into a separate table that you can export to your Palm. Which type of query
could help you accomplish this task?
in
A. A parameter query.
B. A crosstab query.
C. An update query.
E tra
D. A make-table query.
10. If you are creating a crosstab query, what must the table you are querying
contain?
UfSor
A. At least one text field.
B. At least one number field.
C. More than 100 records.
D. Lots of confusing information.
Nd
11. How can you add a table to the query design window?
A. Select Edit → Add Table from the menu.
LY IOse
B. Click the Show Table button on the toolbar.
C. Select the table from the Table list on the toolbar.
D. Select Tools → Add Table from the menu.
u
12. You want a query to calculate the total sales for your employees. How can
T
you do this from the query design window?
ON Ae
A. Click the Totals button on the toolbar. In the Total row select “Group By” under the
b
C. You need to export this information to Microsoft Excel and calculate it there.
ALto
D. Click in the Sales field and select Tools → AutoSum from the menu.
Homework
EVot
2. Using the Customers and Insurance Claims tables, create a multi-table query that
counts the total number of claims, grouped by the State field.
Hint: Use the Count function on any field in the Insurance Claims table.
OnR:
5. Change the select query to a delete query and delete all records from the state of
Wisconsin (WI).
6. Change the delete query back into a select query. Remove the current criteria and add
ua
parameter criteria that ask for the beginning and ending date.
6. Create a concatenated field that combines the FirstName and LastName fields.
al
g
Quiz Answers
in
1. C.
in
2. B and C. Append queries and update queries are both action queries.
3. B. Fields should be enclosed in [ ] brackets, not "" quotation marks.
E tra
4. True. The Expression Builder helps you create expressions in your queries (and in
forms, reports, and macros too!).
5. D. The IIF function is a conditional expression that evaluates a field for a specified
condition and returns one value if the condition is true and another value if the
UfSor
condition is false.
6. A. A parameter query prompts the user for information.
7. False. Queries can calculate groups of records—just click the Totals button on the
toolbar and choose the type of calculation that you want for each field from the drop-
Nd
down list in the Total row.
8. B. A query that summarizes information in a grid, organized by columns and rows,
LY IOse
sounds an awful lot like a crosstab query.
9. D. Since a make-table query creates a new table with the results of the query, this
would be your best bet. u
10. B. A crosstab query must contain at least one number field.
T
11. B. You can add a table to the query design window by clicking the Show Table
ON Ae
button on the toolbar.
b
12. A.
U
ALto
EVot
N
OnR:
tFio
ua
al
Ev
E tra
Working with Forms
UfSor
Chapter Objectives: ; Prerequisites
Nd
• Create and modify a form • How to use menus,
LY IOse
toolbars, dialog boxes,
• Add, delete, move, and size controls and shortcut
keystrokes.
• Change a form’s tab order
u • How to open and
• Work with control properties and settings modify database
objects.
T
Work with form properties and settings
ON Ae
•
• How to add and edit
• Use the Control Wizard to create interactive forms database records.
b
relationship
A form created in Access is similar to the ordinary paper forms that you fill out with a pen or
pencil—only you don’t have to worry about trying to read poor penmanship. In Access, forms
provide an easy way to enter and view data in a table. Here are just a few examples of how
N
• See Data Any Way You Want: You can design forms to present information any way
you like.
tFio
• Combine Data from Linked Tables: One form can display data from several related
tables or queries—and your users will never know that they are working with two
sources!
And that’s just for starters. No doubt about it—forms make your database easier to use. Just
ua
like a Windows dialog box (which is really what a form is), Access forms can include fill-in-
the-blank fields, check boxes, drop-down lists, and more.
This chapter explains everything you have ever wanted to know about forms—and maybe a
al
g
in
Lesson 7-1: Creating a Form with
AutoForm
in
E tra
Figure 7-1
Selecting an AutoForm
from the New Form dialog AutoForms
box.
UfSor
Figure 7-2
A Columnar form created
by the AutoForm Wizard.
Nd
Select the table or query you want to
use for your form.
LY IOse
Figure 7-1
T u
ON Ae
U b
ALto
EVot
N
OnR:
Figure 7-2
tFio
The fastest and easiest way to create a form in Access is with one of the AutoForm Wizards.
The AutoForm Wizard automatically creates a form by arranging all the fields from a table or
query.
ua
The AutoForm Wizards are fast and easy to use but limited: There are only five AutoForm
Wizards, and each can create only one type of form, as shown in Table 7-1: Available Form
Layouts. Of course, you can always modify a form created by an AutoForm Wizard.
In this lesson you will learn how to create a form using an AutoForm Wizard.
al
g
2. Click the Forms icon in the Objects bar, then click the New button.
The New Form dialog box appears, as shown in Figure 7-1. You create a form with the
in
AutoForm Wizard by selecting one of the five AutoForm Wizards…
New button
3. Select AutoForm: Columnar from the list.
in
… and the table or query you want to use in your form.
4. Click the Choose the table or query where the object’s data comes
E tra
from: arrow and select qryCustomers from the list.
That’s all the information the AutoForm Wizard needs to create your form.
5. Click OK to create the columnar form.
Access takes all the fields in the qryCustomers query, arranges them, and creates a
UfSor
report similar to the one shown in Figure 7-2.
6. Close the form without saving your changes.
AutoForm Wizards forms aren’t really very pretty to look at, but they can give you a good
start at creating the form you really want since it’s a lot easier to modify an existing form than
it is to create one from scratch.
Nd
LY IOse
Table 7-1: Available Form Layouts
Form Form Layout Description
Type
Columnar T u Displays only one record at a time.
Data for each record is displayed
vertically. Technically, Columnar
ON Ae
form’s Default View property is set to
Single.
U b
AutoForm: Columnar
PivotTable Dynamically analyzes information and AutoForm: Tabular
summarizes it into a datasheet-like AutoForm: Datasheet
table. AutoForm: PivotTable
ua
AutoForm: PivotChart.
3. Click the table or query
PivotChart Dynamically analyzes information and you want to use for the
al
g
in
Lesson 7-2: Modifying a Form
in
Form Selector Field List button Toolbox button Properties button
Figure 7-3 Click to select Click to display/hide Click to display/hide Click to display properties
E tra
the entire form. the Field List. the Toolbox. for the selected object.
A form in Design View. Double-click to
display the form’s
properties.
Form Header
UfSor
Divider
Drag down to
create a form Field List
header. Drag and drop to
place fields on
Form Header the form.
Appears at the
Nd
top of the form.
Toolbox
Detail Divider Click to create
LY IOse
Separates the controls on the
form body from form. See Table
the form header 7-2: Toolbox
and footer. Buttons and
Form Footer
Divider
T u Controls for
more about each
of these
Drag to create or
Figure 7-3 controls.
ON Ae
resize a form Form Footer Control
footer. Appears at the An object that can contain text or that
b
After you create a form, you may decide to modify it to add additional features or make it
ALto
easier to use. For example, you might want to add or delete a field or change the location of a
field on the form. You modify a form in Design View, which you can get to in two different
ways:
• From the database window: Click the Forms icon to list the forms in the database.
EVot
Click on the form you want to modify and click the Design button.
• From a form window: Click the View button on the toolbar or select View → Design
N
1. From the Database window, click the Forms icon in the Objects bar if it
Design button isn’t already selected, then select the frmCustomers form and click the
Design button.
tFio
the Toolbox and Field List as the paintbrushes you use to add fields, text boxes, and buttons to
the form.
Any graphic object that appears on forms and reports is called a control. A text box used to
al
enter and display information, a text label, and a button you click to print a report would all be
examples of controls. You add controls to a form by clicking the control you want to use and
then by clicking and dragging it on the form to draw the control.
Ev
g
Table 7-2: Toolbox Buttons and Controls
in
Toolbox Button Description
Click this button and then click the control you want to select. To
select multiple controls, click this button and hold down the <Shift>
in
Select Objects key as you click each control, or drag a rectangle around all controls
you want to select.
E tra
Control Wizards Click to use Control Wizards when you add controls to your form.
Creates a static text label that is the same for every record, such as
Label a heading. Most controls already have a text label attached.
UfSor
Creates a text box that displays information from a table and query.
Text Box You can also use text boxes to enter text.
Creates a box around a group of option buttons so that the user is
Option Group only allowed to make one selection from the group box.
Creates a toggle button that allows you to display and enter data
Nd
Toggle Button from a Yes/No field.
LY IOse
Creates an option button (or radio button) that allows the user to
Option Button make a single selection from two or more choices. Option Buttons
are normally used with a Group Box control.
Check Box
u
Creates a box that is checked or unchecked. Use to enter data from
a Yes/No field.
T
ON Ae
Creates a drop-down box that lets the user enter text or select an
Combo Box item from a list of options.
b
List Box Creates a box that lets the user select an item from a list of options.
U
ALto
Command Button Creates a button that runs a macro or Visual Basic function.
in the database. Normally used with OLE Object fields. modify and click Design.
Or…
Page Break Inserts a page break.
Open the form and click
tFio
Enables you to create tabs (like the ones found in some dialog the View button on
Tab Control boxes) to include more than one page of controls on the form. the toolbar.
Inserts another form within the main form. Use when you want to
ua
g
in
Lesson 7-3: Adding and Deleting
Fields
in
E tra
Figure 7-4
Deleting a control is a
quick and easy process.
UfSor
Figure 7-5 Figure 7-4 1. Click the control that 2. …and press the
you want to delete… <Delete> key
Add a field to a form by
clicking and dragging it
from the Field List onto the
Nd
form.
Figure 7-6
LY IOse
The modified form.
Field List
T u
ON Ae
U b
ALto
EVot
Figure 7-5
N
OnR:
tFio
Figure 7-6
Once you have created a form, you can delete unnecessary fields or add more fields to display
ua
additional information. You add fields to a form by dragging the fields from the Field List
onto the form. The Field List lists all the fields from the table or query you used to create the
form.
al
In this lesson you will modify an existing form by adding and deleting fields.
1. Make sure you have the frmCustomers form open in Design View.
Ev
g
2. Click the DOB text box to select it.
Handles () appear around the control, indicating that it is selected.
in
NOTE: Selecting a label will select only the label. Selecting a text box will select both
the text box and the corresponding label.
in
3. Press the <Delete> key to delete the DOB text box.
Poof! The DOB text box disappears without any fuss.
E tra
So much for deleting fields. Here’s how to add a field:
4. If the Field List isn’t displayed, click the Field List button on the toolbar.
The Field List displays all the fields from the table or query you used to create the Field List button
form—although you will usually have to scroll down the Field List to find the field that Other Ways to Display
UfSor
you want. Once the Field List is displayed you can click and drag the field you want to the Field List:
add from the Field List to where you want the field to appear on your form.
• Select View → Field
Move on to the next step and add the DOB field you had previously deleted from the List from the menu.
form.
5. Scroll down the Field List until you find the DOB field. Click and drag
Nd
the DOB field just above the Phone field, as shown in Figure 7-5, then
release the mouse button.
LY IOse
The DOB field appears above the Phone field, as shown in Figure 7-6. Don’t worry if
the DOB field isn’t positioned perfectly—you’ll learn how to move controls in the next
lesson. u
See how your form looks in Form View.
6.
T
Click the View button on the toolbar to display the form in Form View.
ON Ae
Compare your form with the one in Figure 7-6.
7.
b
Select File → Save As from the menu. Save the form as frmFirstForm.
U
ALto
Quick Reference
EVot
necessary.
2. Find the field you want to
add to the form in the
tFio
To Delete a Field or
Control:
1. Click the field or control to
al
select it.
2. Press <Delete>.
Ev
g
in
Lesson 7-4: Moving and Sizing
Controls
in
E tra
`
Figure 7-7
To move a control,
position the mouse over a
border of the control until
UfSor
the pointer changes to a
, and then drag and Select the control you want
drop the control to a new to move, then click and
location on the form. drag it to the desired
location on the form.
Nd
Figure 7-8
LY IOse
Most controls have a
corresponding label.
Figure 7-7
T u
Label Text Box Control
ON Ae b
Figure 7-8
U
ALto
It’s easy to change the location and size of a control on a form. Moving a control allows you
to change the order that information appears on the form. When you size a control, you
increase or decrease the amount of information the control can display. Once you have
Move a control by
EVot
selected a control on a form, sizing handles appear around the edges of the control. Now you
clicking and dragging can drag its sizing handles to adjust the size of the control or move the control to a new
the control to a new location on the form.
N
location.
This lesson will give you some experience moving and sizing the controls on the form you
created in the previous lesson.
1.
OnR:
Make sure that you have the frmFirstForm form open in Design View.
Click and drag the You need to select a control before you can move or size it.
2. Click the Phone text box to select it.
tFio
border of a control to
move both the control Sizing handles appear around the selected Phone field. Here’s how to move a control:
and its label. 3. Position the pointer on any border of the Phone text box (but not over a
sizing handle) until it changes to a .
ua
When the mouse pointer changes to a , it means that you can drag and drop the
control to a location.
Click and drag the
upper left sizing NOTE: It takes a good deal of precision to position the pointer over the tiny border of
al
handle to move a label a control. Move the pointer very slowly and wait until it turns into a before
or control you try to move the control.
Ev
independently.
g
4. Click and hold down the mouse button while the pointer is still over the
border of the Phone text box. Drag the field directly to the right of the
in
FirstName text box and directly above the SSN text box, as shown in
Figure 7-7, then release the mouse button.
in
By simply dragging and dropping with the mouse, you can move any object on a form
or report—any shapes, lines, pictures, or text boxes.
Sometimes, you may want to move the object just a smidgen. You can use the keyboard Resize a control by
E tra
to move or nudge controls with greater precision. To move the control, simply hold clicking it to select it
down the <Ctrl> key as you press any of the arrow keys on the keyboard. and then grabbing one
5. With the Phone field still selected, hold down the <Ctrl> + <←> (left of its sizing handles,
arrow) key. dragging, and then
releasing the mouse
UfSor
The Phone field moves to the left a smidgen. Go to the next step and try moving the
DOB field. button when the
control reaches the
6. Follow the procedure you learned in Step 5 and move the DOB text box desired size.
directly to the right of the LastName text box and directly above the
Phone text box.
Nd
Don’t worry if the DOB field isn’t the same size or aligned with the other controls—
LY IOse
we’ll fix that in a minute.
Notice that the DOB text box moves with its label control. You can move labels and
controls independently of one anther by dragging them by their upper left sizing
handles. u
7. Position the pointer over the upper left sizing handle of the DOB label
until it changes to a .
T
ON Ae
When the mouse pointer changes to a , it means that you can drag and drop the text
box or label independently of one another.
b
NOTE: Most controls have a corresponding label, as shown in Figure 7-8. Make sure
U
that you position the mouse over the DOB label and not the DOB text box.
ALto
Quick Reference
8. Click and hold down the mouse button while the pointer is still over the
upper left sizing handle of the DOB label. Drag the DOB label so that To Resize a Control:
the DOB label is left-aligned with the Phone label below it. 1. Click the control to select
EVot
Enough about moving controls and labels—here’s how to change their size. it.
When you select a control, sizing handles appear around its edge. You can use these 2. Click one of the control’s
sizing handles to change the size and proportions of the selected control. Move on to sizing handles and drag
N
the next step to see how we can reduce the size of the selected DOB label. until the control reaches
9. With the DOB label still selected, position the pointer over the middle- the desired size.
right sizing handle until it changes to a . Click and hold down the To Move a Control:
OnR:
mouse button and drag down and to the right until the label is the • Click and drag the control
same width as the other labels on the form, then release the mouse to the desired location.
button.
tFio
g
in
Lesson 7-5: Changing the Tab
Order
in
E tra
Figure 7-9
The tab order determines
the order by which you 1
2
advance from one field to n
UfSor
3
the next when you press 4 o r
<Tab>. 5
6 q p
7
Figure 7-10 8 s t
9 u v
Nd
Even when you reposition
fields on a form the tab Figure 7-10
LY IOse
order remains the same.
Figure 7-11
Figure 7-9
Changing the tab order. T u
ON Ae
U b
ALto
If you add, remove, or move fields on a form, you’ll want to change the form’s tab order. A
OnR:
form’s tab order determines the order in which you advance from one field to the next when
you press the <Tab> key. When a form is first created, the order of the fields determines the
initial tab order. Even when you reposition the fields on a form, the form’s tab order remains
tFio
the same. For example, the tab order shown in Figure 7-9 is from when the form was
originally created. Because you have rearranged several controls, the tab order no longer
reflects the order in which the fields appear on the form, as shown in Figure 7-10. This isn’t
really a big problem, since it’s easy to change the tab order.
ua
To change the tab order for a form select View → Tab Order from the menu. The Tab Order
dialog box will appear, as shown in Figure 7-9. From here all you have to do is click and drag
the field in the order you want. Or you can click the Auto Order button, which automatically
al
rearranges the tab order to correspond with the order in which controls appear on the form.
First let’s see the current tab order of the frmFirstForm form.
g
2. Switch to Form View by clicking the View button on the Form Design
toolbar.
in
Go to the next step and see what happens when you try tabbing through the fields on
the form.
View button
3.
in
Press the <Tab> key several times. Other Ways to Change
When you press the <Tab> key, the cursor jumps from the CustomerID field to the to Design View:
LastName field to the… Phone field? The tab order for the frmFirstForm form was
E tra
• Select View → Design
determined when the form was created. You may have moved the Phone name field in View from the menu.
the previous lesson, but its position in the tab order hasn’t changed.
You can view and change the tab order by opening the Tab Order dialog box. First you
need to be in Design View.
UfSor
4. Click the View button on the Form Design toolbar to switch to Design
View. Row selector
Here’s how to display the Tab Order dialog box.
5. Select View → Tab Order from the menu.
Nd
The Tab Order dialog box appears, as shown in Figure 7-9. The order of the fields in
the list is the order in which you will advance from one field to the next when you
LY IOse
press the <Tab> key. There are a couple of ways to change the tab order. The fast and
easy way is to click the Auto Order button, which automatically rearranges the tab
order to correspond with the order in which controls appear on the form.
T u
NOTE: The initial tab order of a form and the Auto Order option both create a tab
order from left to right, top to bottom. Quick Reference
6. Click the Auto Order button.
ON Ae
To Change a Form’s Tab
Access looks at the order in which fields appear on the form and adjusts the tab order Order:
b
accordingly.
1. Display the form in
Sometimes the tab order may not be intuitive for data entry and you may want to
U
Design View.
manually change it. For example, you may want to modify the tab order so that the
ALto
address, city, state, and Zip Code fields are together. Here’s how to manually change a 2. Select View → Tab
field’s position in the tab order. Order from the menu.
7. Click the City row selector in the Custom Order list. 3. Click the row
EVot
Drag the State row below the City row and drag the ZipCode row below change the order of
the State row. additional controls.
You’re finished changing the tab order for the frmFirstForm form. To Automatically Change
tFio
10. Click OK to close the Tab Order dialog box. the Tab Order:
Let’s test the new tab order. 1. Display the form in
11. Switch to Form View by clicking the View button on the Form Design Design View.
ua
toolbar. Press the <Tab> key several times and notice the order in which 2. Select View → Tab
the cursor moves from field to field. Order from the menu.
You’ve finished this lesson so… 3. Click the Auto Order
al
12. Save your changes and then close the frmFirstForm form. button to automatically
reorder the form controls,
based on their position in
Ev
the form.
g
in
Lesson 7-6: Working with Control
Properties
in
E tra
Figure 7-12
Here the Properties dialog
box displays the
properties for the
UfSor
LastName text box
control.
Properties
dialog box
Nd
LY IOse
T u
ON Ae
Figure 7-12
b
Every control on a form—every text box, every label, and every check box—has a set of
properties that you can modify. A property is an attribute that defines an object’s appearance,
behavior, or characteristics. For example, the properties of a house would be its color, square
footage, and shape. A property for a field on a form might be the number of decimal places
EVot
displayed or the default value for the field. Because you can almost always change an object’s
properties, you can think of them as the object’s settings.
N
Different types of controls have different properties. For example, label controls have a
Caption property that determines the text that is displayed in the label, while text box controls
have a Control Source property that determines which field is displayed in the control. Most
OnR:
controls have several dozen different properties or settings. Fortunately, Access organizes
these properties into different categories, as shown in Table 7-3: Tabs in the Properties Dialog
Box.
tFio
There are several ways to view the properties for any object:
• Right-click the control and select Properties from the shortcut menu.
• Select the control and click the Properties button on the toolbar.
ua
• Select the control and select View → Properties from the menu.
This lesson explains how to view and change a control’s properties.
al
g
2. Select the LastName text box control and display its properties by
clicking the Properties button on the Form Design toolbar.
in
Properties button
The Properties dialog box appears and displays the properties for the LastName text
box control, as shown in Figure 7-12. To change a property, simply find and click the Other Ways to View a
Control’s Properties:
in
appropriate property box and make the changes. Some property boxes will display one
of the following buttons when clicked: • Right-click the control
and select Properties
• Click to display a list of options to change the settings for the selected
E tra
from the shortcut menu.
property.
• Select the control and
• Click to invoke a Wizard or display a dialog box that you use to change the
select View →
settings for the selected property.
Properties from the
Move on to the next step and we’ll try changing one of the LastName text box control’s menu.
UfSor
properties.
3. Click the Format tab, if necessary, then find and click in the Back Style
box, click its down arrow, and select Transparent.
NOTE: Most controls have dozens and dozens of properties. You will often have to
Nd
click the appropriate tab and then do some scrolling to find the property box
that you’re looking for.
LY IOse
The back of the LastName text box control becomes transparent and displays the gray
background of the underlying form. The transparent Back Style property of the
LastName text box control looks out of place, so let’s change it back.
4. u
Change the Back Style property of the LastName text box control
back to Normal.
T
Once the Properties dialog box is open, you can simply click any control to display its
ON Ae
properties.
5.
b
tell which control’s properties are being displayed by looking at the Title bar of the
ALto
Table 7-3: Tabs in the Properties Dialog Box To Display the Properties
Tab Description for Any Control:
N
Format Properties that determine the object’s appearance, such as color, text formatting, line 1. Display the form in
and border color/thickness, and special effects. The purpose of many Formatting Design View.
properties should be pretty obvious—for example, Font Size determines the font size 2. Select the control and
OnR:
Or…
Other Miscellaneous but important properties, such as the name of the control, if tabbing to
Select the control and
the control is allowed, and if a message should appear in the Status bar when the
select View →
control is selected.
Properties from the
al
g
in
Lesson 7-7: Control Property
Reference
in
E tra
Every control on a form or report has dozens of different control properties or settings—so
how do you keep them all straight? Here’s how—this lesson is really a cheat sheet that you
can use whenever you’re not sure what exactly a particular control property is or does. The
most important properties are marked with a .
UfSor
Table 7-4: Common Form and Report Control Properties
Property Tab Description
Caption Format Displays a descriptive caption for a form or text label.
Nd
Format Format Customizes the way numbers, dates, times, and text are displayed
and printed.
LY IOse
Decimal Places Format Determines the number of decimal places displayed.
Visible Format Show or hides a control. Useful if you want to use information on
T u the form without it being visible. For example, you could use the
value in a hidden control as the criteria for a query.
ON Ae
Display When Format Determines whether a section or control always appears or only
appears when it is displayed on screen or printed.
b
Scroll Bars Format Determines whether scroll bars appear in the control.
U
Back Color Format Determines the color of a control. Click the button to select a
color from a palette.
OnR:
Border Color Format Determines the color of a control’s border. Click the button to
select a color from a palette.
ua
Border Width Format Determines the width of a control’s border (in points).
Fore Color Format Determines the color of text in a control or the fill color of an
object. Click the button to select a color from a palette.
al
Font Name Format Determines the font used in a control (such as Arial or Times New
Roman).
Ev
g
Property Tab Description
Font Italic Format Determines whether the text in a control appears in italics.
in
Font Underline Format Determines whether the text in a control is underlined.
in
Text Align Format Determines how text should be aligned in a control.
Control Source Data Determines the data that appears in the control.
E tra
Input Mask Data Limits the amount and type of information that can be entered in a
field, such as ( ___ ) ____-______ for a phone number. Click the
button to create an input mask using the Input Mask Wizard.
Default Value Data Specifies a value that is automatically entered in this field for new
UfSor
records.
Validation Rule Data Allows you to enter an expression that is evaluated when data in
the field is added or changed.
Validation Text Data Allows you to enter a message that is displayed when data doesn’t
Nd
meet the Validation Rule property.
LY IOse
Locked Data Determines whether changes can be made to a field’s data.
Event Tab Event Allows you to assign a macro or Visual Basic procedure to a
specific event, such as when you click or update a control.
Name Other
u
Specifies the name of the control that identifies it in expressions,
macros, and Visual Basic procedures.
T
ON Ae
Status Bar Text Other Specifies a message to display in the Status bar when the control
is selected.
b
Enter Key Behavior Other Determines if pressing the <Enter> key adds a new line of text in a
U
Allow AutoCorrect Other Determines if AutoCorrect (i.e., “teh” → “the”) is used in a control.
AutoTab Other Used with the Input Mask property. Determines whether an
automatic tab to the next field occurs when the last character
EVot
control is right-clicked.
ControlTip Message Other Specifies a brief message that appears when a user points at the
tFio
g
in
Lesson 7-8: Working with Form
Properties
in
E tra
Figure 7-13
The Form Selector is the
key to selecting a form
and displaying its
UfSor
properties. Double-click the
Form Selector…
Nd
LY IOse
Figure 7-13
T u
ON Ae b
In the previous few lessons, you’ve been learning how to view and change the properties for
form controls. In this lesson you will learn how to view and change the properties and settings
U
of the form itself. That’s right—just like controls, forms also have their own set of properties
ALto
that you can view and manipulate. So why would you want to change a form’s properties?
Form Selector Modifying a form’s properties can be especially important if you are creating a database that
will be used by novice users. For example, by modifying a form’s properties you can:
• Allow users to edit exiting records in a table or query—but not add any additional
EVot
records.
• Display one record at a time on each form or display many records at once.
N
Selected To view the properties for a form or report, simply double-click the Form Selector, as
shown in Figure 7-13. In this lesson you will learn how to work with a form’s properties.
OnR:
In its current state, the frmCustomers form displays one record at a time and has a
rather confusing caption in the title bar: “frmCustomers.” These are form properties
that you can change. You must be in Design View in order to view and change a form’s
properties.
ua
g
4. Click the Format tab, if necessary, click in the Caption box, and replace
its text with Customers.
in
One of the most important form properties is the Default View property, which
determines how many records a form can display at once. Let’s take a closer look at
in
this property…
5. Click the Format tab, click the Default View box, and click the down
arrow.
E tra
You have five options. They are:
• Single Form: Displays one record at a time on a form.
• Continuous Forms: Displays multiple records on a form. The main
difference between Datasheet and Continuous Forms is that a continuous form
UfSor
can be customized.
• Datasheet: Displays multiple records in a table, using one line per record.
Tables and queries display information in datasheets.
• PivotTable: Dynamically analyzes information and summarizes it into a
Nd
datasheet-like table.
• PivotChart: Dynamically analyzes information and summarizes it into a chart.
LY IOse
6. Select Datasheet from the list.
That’s enough changes for now.
7. Close the Properties dialog box. u
Let’s see how the form looks with its new properties.
8.
T
Click the View button on the toolbar to display the form.
ON Ae
Access now displays the frmCustomers form in Datasheet View, and it has a new
b
You’re probably wondering how you are going to get a handle on all these form properties.
Don’t worry—you will probably never touch 95 percent of them. And when you actually do
have to roll up your sleeves and tackle form properties, you’ll find the cheat sheet in the next
lesson invaluable. Quick Reference
EVot
Selector.
3. Click the appropriate
property tab and property
tFio
g
in
Lesson 7-9: Form and Report
Property Reference
in
E tra
If you thought controls had lots of properties, wait until you see how many properties forms
and reports have! Here’s another “cheat sheet” that lists the various form properties. Some of
the most important properties are marked with a .
UfSor
Property Tab Description
Caption Format Displays a descriptive caption in the form’s title bar.
Default View Format Determines the view the form is in when opened.
Nd
Single Form: Displays one record at a time.
Continuous Forms: Displays multiple records in a form.
LY IOse
Datasheet: Displays multiple records in a Datasheet.
PivotTable: Dynamically analyzes data, summarizes into a
table. PivotChart: Dynamically analyzes data, summarizes into
u a chart.
Allow Form View Format Determines if users can switch to this view.
T
Allow Datasheet View
ON Ae
Allow PivotTable View
Allow PivotChart View
b
Scroll Bars Format Determines whether scroll bars appear on the form.
U
Auto Resize Format Resizes the form automatically to display a complete record.
Border Style Format Determines the type of window the form appears in: None, Thin,
N
Sizable, or Dialog.
Control Box Format Determines if a control menu appears in the form.
OnR:
Min Max Buttons Format Determines if minimize and/or maximize buttons appear in the
form.
tFio
Picture Format Adds a graphic or picture for the form or report background. Click
the Build button to browse for the folder and file.
Picture Type Format Determines if the picture is embedded or linked.
al
Picture Size Mode Format Determines how the contents of a picture frame are displayed:
Clip, Stretch, or Zoom.
Ev
g
Property Tab Description
Picture Tiling Format Determines whether a picture is tiled within a frame.
in
Grid X Format Determines the number of subdivisions (horizontal) in a grid.
in
Grid Y Format Determines the number of subdivisions (vertical) in a grid.
Layout for Print Format Determines whether the form uses printer fonts.
E tra
Palette Source Format Specifies the path and file name for the graphic file used as a
palette.
Record Source Data Specifies the table or query whose data will be used in the form.
Filter Data Specifies a filter that is loaded automatically with the
UfSor
Form/Report.
Order By Data Specifies a sort order that is loaded automatically with the
Form/Report.
Allow Filters Data Determines whether filters may be applied to the form.
Nd
Allow Edits Data Determines whether records can be modified in the form.
LY IOse
Allow Deletions Data Determines whether records can be deleted in the form.
Allow Additions Data Determines whether records can be added in the form.
Data Entry Data
u
Allows you to select “Yes” if you only want to use the form to add
new records.
T
ON Ae
Event Tab Event Allows you to assign a macro or Visual Basic procedure to a
specific event, such as when you click or update a control.
b
Pop Up Other Determines whether the form appears in a pop-up window that
U
Modal Other Determines whether the form keeps the focus (you can’t switch
to any other windows or forms) until it is closed.
Cycle Other Determines how the tab key should cycle.
EVot
Menu Bar Other Allows you to select a custom menu bar that you created that
should appear when the form is active.
N
Toolbar Other Allows you to select a custom toolbar that you created that
should appear when the form is active.
OnR:
Shortcut Menu Other Determines if right mouse button shortcut menus are permitted in
the form.
tFio
Shortcut Menu Bar Other Specifies a user-created shortcut menu that appears when a
user clicks the right-mouse button.
Fast Laser Printing Other Print the form using optimized laser-printer formatting.
ua
Help File Other Specifies the name of the custom Help file for the form.
Help Context Id Other Specifies an identifier number for a user-created Help file that
appears when the user selects the control and presses <F1>.
al
Has Module Other Specifies if the form has Visual Basic code behind it.
g
in
Lesson 7-10: Working with
Multiple Controls
in
E tra
Figure 7-14
One way of selecting
multiple controls is by
pressing and holding
UfSor
down the <Shift> key as
you click each control that
you want to select. Figure 7-14 Figure 7-15
Figure 7-15
Nd
Another way to select The advantage of selecting multiple controls in a form or report is that you can edit, delete,
move, format, or resize a whole bunch of controls at once, instead of having to edit each
LY IOse
multiple controls is by
drawing a box around the control individually. In this lesson you will learn how to select multiple controls on a form.
controls that you want to
select. 1. Open the frmCustomers form in Design View.
u
To delete a control you have to select it and press the <Delete> key. Sometimes you
will want to delete several controls; instead of selecting and deleting each individual
T
control, you can select and delete several controls at the same time. There are several
ON Ae
ways to can select more than one control:
b
• Press and hold down the <Shift> key as you click each control that you want to
select.
U
•
ALto
If necessary, click the Select Objects button on the Toolbox toolbar. Then use
the arrow pointer ( ) to draw a box around the controls that you want to select,
as shown in Figure 7-15. The disadvantage of this method is it’s not as selective
as using the <Shift> + click method.
Quick Reference
EVot
• If the controls you want to select are aligned along a horizontal line, click to the
To Select Multiple left of the objects in the vertical ruler to select every control to the right of the
Controls: ruler.
N
• Press and hold down the 2. Hold down the <Shift> key as you click the Smoker and First Class text
<Shift> key as you click boxes as shown in Figure 7-14.
each control that you Handles () appear around the controls, indicating that they are selected.
OnR:
want to select.
3. Press the <Delete> key to delete the selected controls.
Or…
The Smoker and First Class text box controls are both deleted.
tFio
Or…
• If the controls are aligned
along a horizontal or
al
controls.
g
in
Lesson 7-11: Adding, Cutting,
Copying, and Pasting Controls
in
E tra
Figure 7-16
Add a control to a form by
clicking the control on the
Toolbox and then clicking
UfSor
and dragging on the form.
Nd
Click the control you
want to add… Quick Reference
LY IOse
…then click and drag To Add a Control:
on the form to add the
control. 1. Click the Toolbox
button on the toolbar if
Figure 7-16
T u necessary.
2. Click the button on the
Toolbox for the type of
ON Ae
control you want to add.
In this lesson you will learn how to add a control by clicking and dragging and by copying
b
appear.
NOTE: If the Toolbox isn’t displayed, click the Toolbox button on the Form To Cut a Control:
Design toolbar.
• Select the control and:
EVot
The mouse pointer changes to a , indicating that you can click and drag a check box Click the Cut button on
control on the form. the toolbar or…
2. Place the pointer below the SSN text box. Click and drag the Press <Ctrl> + <X> or…
N
pointer down and to the right and release the mouse button, as shown in Select Edit → Cut from
the menu.
Figure 7-16.
Congratulations! You’ve just added a check box control to your form. To Copy a Control:
OnR:
If your form already has a control that’s similar to the one you want to add, it’s often • Select the control and:
easier to add the new control by copying and pasting the similar control than it is to Click the Copy button
on the toolbar or…
tFio
add a control using the Toolbox. Once you have pasted the control, you can easily
modify its properties, such as its text label data source. Here’s how to copy a control. Press <Ctrl> + <C> or…
Select Edit → Copy from
3. Select the check box control you just added and click the Copy button the menu.
on the Form Design toolbar.
ua
To Paste a Control:
Access copies the selected check box control to the Windows Clipboard. You can also
cut controls on a form by selecting them and clicking the Cut button on the Form • Select the control and:
Design toolbar or by pressing <Ctrl> + <X>. Now let’s paste the copied control. Click the Paste button
4. on the toolbar or…
al
Click the Paste button on the Form Design toolbar. Press <Ctrl> + <V> or…
Access pastes the copied check box onto the form as a new check box with its own Select Edit → Paste from
Ev
name and label. We’ll modify the two new check box controls in the next lesson. the menu.
g
in
Lesson 7-12: Changing a Control’s
Data Source
in
E tra
2"
Figure 7-17
Examples of bound,
unbound, and calculated
controls.
UfSor
Figure 7-18
Setting the Control Source
property.
Nd
Figure 7-19
LY IOse
The steps in modifying a
control’s text label.
Figure 7-17
T u 1. Click the control to select
it.
ON Ae b
There are three types of controls that you can add to your forms, as illustrated in Figure 7-17.
They are:
OnR:
bound controls.
• Unbound Controls: Unbound controls are not bound or connected to an underlying
field in a table or query. You use unbound controls to display information. Labels, text
boxes, and buttons can all be inserted on a form as unbound controls. The two check
ua
boxes you added to the form in the previous lessons are both examples of unbound
controls because they aren’t connected to an underlying field in a table or query.
• Calculated Controls: Calculated controls are based on an expression and are used to
al
g
A control’s Control Source property determines what is displayed in a control – here’s how:
• A bound control’s Control Source property contains the name of the underlying database
in
field to which it is bound.
• An unbound control’s Control Source property does not contain the name of an
in
underlying database field.
Properties button
• A calculated control’s Control Source property contains an expression that calculates the
Other Ways to View a
E tra
values displayed in the control. Control’s Properties:
This lesson explains how you can change a control’s Control Source property. • Right-click the control
and select Properties
1. Select the first check box control you added in the previous lesson, from the shortcut menu.
and display its properties by clicking the Properties button on the Form • Select the control and
UfSor
Design toolbar. select View →
The Properties dialog box appears. You can find the Control Source property on the Properties from the
Data Tab. menu.
2. Click the Data tab.
Nd
The Data tab appears, as shown in Figure 7-18. You can determine what is displayed in
the control by setting the Control Source property. You can bind the control to a field in
LY IOse
the form’s underlying query or table by clicking the button, or you can type text or
an expression directly into the Control Source box. We want to bind the selected check
box to the Smoker field. Quick Reference
3. u
Click in the Control Source box, click the button, and select To Change a Control’s
Smoker from the list. Data Source:
T
The check box is now bound to the Smoker field in the tblCustomers table. Next let’s
ON Ae
1. Display the Form in
bind the other check box control you added to the First Class field. Design View.
4.
b
With the Properties dialog box still open, click the second check box 2. Select the control and
control you added in the previous lesson. click the Properties
U
The Properties dialog box is updated and displays the settings for the selected check button on the toolbar.
ALto
You’re done specifying the data sources for the two check boxes so you can close the the shortcut menu.
Properties dialog box. Or…
6. Select the control and
N
Position the pointer over the first check box text label, until it changes
into a , and then click inside the text label. 3. Click the Data tab.
Now you can edit the check box text label. 4. Click the Control Source
tFio
expression.
5. Close the Properties
dialog box.
Ev
g
in
Lesson 7-13: Creating a
Calculated Control
in
E tra
Arithmetic operator
Figure 7-20
To enter database fields in
=[Number of Tickets]*[Cost]
an expression, type the
field name in brackets. Start expressions Existing field names used
UfSor
with the equal (=) in the calculation must be
Figure 7-21 symbol. enclosed by brackets [ ].
Figure 7-20
If a database field name
exists in more than one
=[tblTours]![Cost]*0.15
Nd
table, you will need to
enter the name of the Name of the table Existing field Value
LY IOse
table that contains the that contains the field name
field in brackets, followed followed by an
exclamation mark (!) Figure 7-22
by an exclamation mark
(!). Figure 7-21
Figure 7-22
u
A calculated control is an unbound control that displays totals and other arithmetic
T
computations on a form. You create calculated controls by entering an expression (or formula)
ON Ae
You create a calculated to perform the calculation in the control’s Control Source property.
field by entering an
b
expression in the Control In forms, expressions start with the equal sign (=), which tells Access that you want to
Source box. perform a calculation. After the equal sign, you must specify two more types of information:
U
the values you want to calculate and the arithmetic operator(s) or function name(s) you want
ALto
to use to calculate the values. Expressions can contain explicit values, such as the numbers
“4” or “5” or can reference the values contained in database fields. For example, the formula
=[Cost]*[Commission] would multiply the values in the Cost and Commissions fields. To
Quick Reference
enter fields in an expression, type the field name in brackets ([Order Total]). If a field name
EVot
To Create a Calculated exists in more than one table, you will need to enter the name of the table that contains the
Control: field in brackets ([Customer Tours]) followed by an exclamation mark (!) and then the field,
1. Display the Form in such as [Order Total].
N
Design View.
2. Select the control and
1. Open the frmTours form in Design View.
click the Properties You want the Total text box to be a calculated control that finds the total cost of each
OnR:
button on the toolbar. tour by multiplying the Number of Tickets field by the Cost field.
3. Click the Data tab and 2. Select the Total text box, click the Properties button on the Form
Design toolbar, and click the Data tab.
tFio
syntax.
Let’s see how our new calculated control works.
Or…
4. Close the Properties dialog box and click the View button on the Form
Click the Build Design toolbar to switch to Form View.
al
Although you worked on a form in this lesson, you can also use expressions to create
calculated controls and fields in queries and reports.
g
in
Lesson 7-14: Changing a Control’s
Default Value
in
E tra
Figure 7-23
Setting the Default Value
property for a control.
UfSor
Enter a control’s
Default Value Figure 7-24
here.
The default value will
appear in the control when
The default you add a new record with
Nd
value appears the form.
when you add a
new record.
LY IOse
Figure 7-23 Figure 7-24
u
You can enter a default value to specify a value that is automatically entered in a field when a
T
new record is created. For example, if most of your clients are from Texas, you could set the
ON Ae
default value for the State field to “TX.” When users add a record using a form, they can
either accept the “TX” default value for the State field or enter their own value.
b
Since the majority of your customers are from Minnesota, you decide to add “MN” as
the default value for the State field.
2. Click the State field, display its properties by clicking the Properties
button on the Form Design toolbar, and click the Data tab. Quick Reference
EVot
Now you can add a default value to the State field. To Set a Control’s Default
3. Click the Default Value box and type MN, as shown in Figure 7-23. Value:
N
Let’s see how the new default-value property works. 1. Display the form in
4. Close the Properties dialog box and click the View button on the Form
Design View.
Design toolbar to switch to Form View. 2. Display the properties for
OnR:
Access adds a new blank record to the form. Notice that the State field already contains box and type the default
the “MN” default value. If the customer is from another state, you can simply replace value you want to appear
the default value with your own data. for new records.
6. Save your changes and close the frmCustomers form.
ua
Default Value property will be passed on to a related State control on a form by default.
Ev
g
in
Lesson 7-15: Using the Control
Wizard
in
E tra
Figure 7-25 The Control Wizard is on
when its button on the
You can turn the Control Toolbox is pressed in.
Wizard on or off by
toggling the Control
UfSor
Wizards button on the
Toolbox.
Figure 7-26
Nd
The Combo Box Wizard.
Figure 7-27 Figure 7-25
LY IOse
Two interactive controls Figure 7-26
added to a form using the
Control Wizard. u This combo-box control
T
finds and displays a
ON Ae
record on the form based
on your selection.
U b
ALto
Figure 7-27
N
The Control Wizard (no relation to Merlin) helps you add powerful, interactive controls to
your form. Some examples include:
OnR:
• List and combo box controls that can look up values in a table and then display the
corresponding record on a form.
• Buttons that can open, print, or close tables, forms, queries, pages, and reports.
tFio
• Subforms, subreports, and charts that display related data from different tables.
Control Wizards When you add a control using the Control Wizard, you are asked a series of questions about
button what you want the control to do. The Control Wizard then creates the control, making the
ua
appropriate property settings and even adding several lines of Visual Basic code to the control
for you.
To use the Control Wizard, simply make sure that the Control Wizards button on the
Toolbox is pressed in, and then add the control. The Control Wizard will appear
Combo Box button
Ev
anytime you try to create a list box, combo box, option group, button, chart, subreport,
or subform.
g
2. Make sure the Control Wizards button on the Toolbox is pressed in.
The Control Wizard is so incredibly cool and useful that you are strongly
in
recommended to always keep it on. Command Button
button
NOTE: If the Toolbox isn’t displayed, click the Toolbox button on the Form
in
Design toolbar.
First let’s add a combo box control to the form. Quick Reference
3.
E tra
Click the Combo Box button on the Toolbox. To Create a List Box or
Combo Box:
The mouse pointer changes to a , indicating that you can click and drag a combo
box control on the form. 1. Display the form in
4. Place the pointer in the form header, about one inch to the right of the
Design View.
UfSor
“Customers” label. Click and drag the pointer to the right about an 2. Click the Toolbox
inch and release the mouse button. button on the toolbar, if
necessary, and make
Because the Control Wizard is on, the Combo Box Wizard dialog box appears, as
sure the Control
shown in Figure 7-26. Each type of control will have its own Control Wizard and its
Wizards button on the
own set of options. For this exercise, you want to select the third option.
Nd
Toolbox is selected.
5. Select the Find a record on my form based on the value I selected in
3. Click the Combo
LY IOse
my combo box option and click Next.
Box or List Box
Next the Control Wizard asks which values you want to add to your combo box control button on the Toolbox.
6. Click the button three times to add the CustomerID, LastName and 4. In the form window, click
u
FirstName fields to the combo box and click Next.
Next the Control Wizard asks how wide you want the columns in your combo box
T and drag where you
want the control to
control and if you want to hide the key column. Everything looks okay here, so… appear.
ON Ae
7. Click Next. 5. Specify whether you
b
Finally, you are asked to give your combo box a name. You can accept the default want the control to get
name provided by the Control Wizard or you can provide your own name. its values from a table or
U
the right of the CustomerID text box by clicking and dragging. want to include in the list
Because the Control Wizard is on, the Command Button Wizard appears. Command and click Next.
Buttons have lots of options that you can choose from, broken down by categories. 7. Select the fields you
N
10. Select Record Operations from the Categories list and select Print want to appear in your
Record from the Actions list. list and click Next.
8. Adjust the column
OnR:
This will make the command button print the current record when clicked.
widths, if necessary, and
11. Click Next. click Next.
tFio
Here you can specify the text or picture that will appear in the button. 9. If necessary, specify
12. Click Finish. which column contains
Access adds the command button to the form. the value that will be
stored and click Next.
13. Click the View button on the Form Design toolbar.
ua
Access finds and displays the record that you select from the combo box.
15. Save your changes and close the frmCustomers form. 11. Enter a label and click
Finish.
Ev
Try experimenting and adding controls to your forms using the Control Wizard. You’ll be
amazed at how much you can accomplish without knowing any programming!
g
in
Lesson 7-16: Creating a Subform
in
Figure 7-28
E tra
Parent field
Subforms are great for
working with data in Main Form
Shows data from
multiple tables with one- the “one” side of
to-many relationships. the relationship.
Here the subform displays
UfSor
all the tours made by each
employee. Child field Subform
Shows data from
Figure 7-29 the “many” side of
the relationship.
Select the table or query
Nd
and fields that you want to Figure 7-28
LY IOse
include on your subform.
Figure 7-30
You need to define which u
fields link the main form
and subform.
T
ON Ae
U b
ALto
A subform is a form within a form. The primary form is called the main form, and the form
within the form is called the subform. Subforms are especially useful when you want to show
EVot
data from tables or queries with a one-to-many relationship. For example, a Customer form
might have a subform that displays each customer’s Orders. Subforms are a great way to
display information from a one-to-many table relationship.
N
The main form and subform are linked so that the subform displays only records that are
related to the current record in the main form. For example, when the main form displays a
particular customer, the subform displays only orders for that customer.
OnR:
Usually you will want to have the Control Wizard assist you when you add a subform.
Control Wizards 2. Make sure the Control Wizards button on the Toolbox is pressed in.
button The Control Wizard is on whenever its button is depressed.
ua
NOTE: If the Toolbox isn’t displayed, click the Toolbox button on the Form
Design toolbar.
Before you add a subform, make sure that you have enough room for it on the main
al
form.
3. Resize the main-form window as needed, so that you have enough room
to add the subform.
Ev
g
4. Click the Subform/Subreport button on the Toolbox.
in
The mouse pointer changes to a , indicating that you can click and drag the subform
onto the main form.
5. Place the pointer just below the DOB field. Click and drag the
in
pointer down and to the right, until the subform covers most of the
Subform/
bottom half of the main form.
Subreport button
E tra
The Subform Wizard appears and asks if you want to use an existing form for your
subform or if you want to build a new form, using tables or queries. In this exercise we
will have the Wizard build us a new form using tables and queries to use as our
subform.
6. Click Next.
UfSor
The next step of the Wizard appears. Here you have to select the table or query and
fields that you want to display in your subform. We want our subform to display the
tours that each employee has sold, so we will select the qryCustomerTours query as the
source for our subform.
7. Select Query: qryCustomerTours from the Tables/Queries combo box.
Nd
Quick Reference
Now you need to select the fields you want to appear in the subform. You must select
To Create a Subform:
LY IOse
the related field used to join the main form and subform. This related field must appear
on both the main form (where it is called the parent field) and on the subform (where it 1. Display the form in
is called the child field). In this exercise we will use the EmployeeID field to link the Design View.
two forms. u 2. Click the Toolbox
NOTE: It’s very important that the underlying tables or queries of the main form and button on the toolbar, if
necessary.
T
subform have a related field and that the related field appears somewhere on
ON Ae
both forms. See the “Understanding Table Relationships” lesson in the 3. Make sure the
“Creating Relational Databases” chapter if you’re having trouble Control Wizards
b
Select the EmployeeID field and click the button to add the field to
ALto
Just make sure that you add the fields in the order specified in Steps 8 and 9.
want the subform to
10. Click Next. appear.
The next step in the Wizard is to define the fields that link the main form and the 7. Click Next.
OnR:
subform. The Subform Wizard is often smart enough to recognize the field and use it to
link the two forms—as it is in this exercise. If not, you will have to click the Define my 8. Specify the table or
own option and select the two related fields. query you want to use
tFio
g
in
Lesson 7-17: Modifying and
Working with Subforms
in
E tra
Figure 7-31
Modifying a subform in
Design View.
UfSor
Click and drag the
right or bottom edge
of a form to resize
it.
…to open and
modify the subform
Nd
in Design View.
LY IOse
Double-click a
subform control…
T u
Figure 7-31
ON Ae b
Subforms rarely come out the way you want them to the first time: They may be too small or
too large and must be resized so that the main form and subform fit together nicely. If you’re
U
using an existing form as a subform, you may need to change the subform layout. Subforms
ALto
between datasheets and continuous forms is that you can design and customize
continuous forms.
• Datasheet: Displays multiple records in a table, using one line per record. Tables and
N
The subform you added in the previous lesson has enlarged the main form so that it is
large enough to display the subform contents. You will need to resize the form window
to display the form properly.
2. Select Window → Size to Fit Form from the menu.
al
Next Record Access resizes the window to fit the form. Let’s see how the new subform works.
button 3. Click the Next Record navigation button on the main form.
Ev
Notice that the subform displays tours booked by the current employee.
g
Also, notice that the main form and sub form each have their own set of navigation
buttons that you can use to add and move between records. Try adding a new record to
in
the subform.
4. Click the New Record button on the subform record navigation bar.
New Record
in
The record indicator jumps to the blank row at the end of the subform datasheet and
the blinking insertion point () appears in the EmployeeID field. Notice that Access
button
has automatically filled in the EmployeeID field with the main form’s EmployeeID.
E tra
NOTE: If you have set referential integrity between two or more related fields in a
subform’s underlying table or query, you will have to obey those referential
integrity rules in order to add or edit a record in the subform. For example,
you can’t enter a number in the TourID field unless that number exists in the
UfSor
qryCustomerTours query.
5. Enter a new record in the subform using the following information:
EmployeeID Date TourID CustomerID Number of Tickets
(Current) 9/2/01 China Ali Chien 2
Nd
It’s easy to switch between the main form and subform: simply click a field or control
in the form you want to move to or press <Ctrl> + <Shift> + <Tab>.
LY IOse
6. Click any field in the main form to move to the main form.
Here’s how to modify a subform:
7. Switch to Design View. u
First get rid of that annoying subform label.
8.
T
Select the label for the subform and press <Delete>.
ON Ae
In Access 2003 you can directly modify subforms from the main form. (Previously,
b
9. In the subform, resize the text fields and corresponding text labels for the
ALto
Resize the subform window as needed, then click and drag the right edge
To Modify a Subform:
of the subform to the left to eliminate the wasted, empty space.
1. Display the main form in
Here’s how to change the layout of a subform:
N
Design View.
11. Double-click the subform’s form selector in the upper left corner of the 2. Double-click the subform.
subform.
3. Edit the subform as
OnR:
Now you need to resize the subform control and the main form.
13. Resize the subform control so that it fits nicely in the main form, and then
drag the right edge of the main form to resize it as well.
ua
15. Save your changes to the form and close the Lesson 7 database.
Whew! We just covered a lot of ground in this chapter. Try moving on to the Chapter Review
Ev
g
in
Chapter Seven Review
in
Lesson Summary
E tra
Creating a Form with AutoForm
UfSor
• To Create a Form with AutoForm: From the Database window, click the Forms icon in the
Objects bar and click the New button. Select the type of form you want to create: Columnar,
Tabular, Datasheet, PivotTable, or PivotChart. Click the table or query you want to use for the form
from the drop-down list and Click OK.
Nd
Modifying a Form
LY IOse
• To Modify a Form: From the Database window, click the Forms icon in the Objects bar, click the
form you want to modify and click Design, or open the form and click the View button on the
toolbar.
u
Adding and Deleting Fields
T
ON Ae
• To Add a Field to a Form: Display the form in Design View and click the Field List button on
the toolbar if necessary, find the field you want to add to the form in the Field List, then click and
b
• To Delete a Field or Control: Click the field or control to select it and then press <Delete>.
ALto
release the mouse button when the control reaches the desired size. Hold down the <Shift> key
while dragging to maintain the control’s proportions while resizing it.
N
• To Move a Control: Click the control and hold down the mouse button, drag the control to a new
location and then release the mouse button to drop the control.
• To Move a Text Box or Text Label Independently of Each Other: Position the pointer over the
OnR:
upper left sizing handle of the control until it changes to a , then click and drag the control.
• To Change a Form’s Tab Order: Display the form in Design View and select View → Tab Order
from the menu. Click the row selector for the control you want to move and click and drag the
row selector to the desired location. Repeat as needed to change the tab order of additional
ua
controls.
• To Automatically Change the Tab Order: Display the form in Design View and select View →
Tab Order from the menu. Click the Auto Order button to automatically reorder the form controls,
al
g
Working with Control Properties
in
• To Display the Properties for Any Control: Display the form in Design View and do any of the
following:
- Select the control and click the Properties button on the toolbar.
in
- Right-click the control and select Properties from the shortcut menu.
- Select the control and select View → Properties from the menu.
E tra
Working with Form Properties
• To View and Change Form Properties: Display the form in Design View and double-click the
Form Selector. Click the appropriate property tab and property box and make the desired
UfSor
changes.
Nd
- Press and hold down the <Shift> key as you click each control that you want to select.
- Use the arrow pointer ( ) to draw a box around the control that you want to select.
LY IOse
- If the controls are aligned along a horizontal or vertical line, click the horizontal or vertical ruler
above or to the left of the controls.
• To Change a Control’s Data Source: Display the Form in Design View, select the control and
click the Properties button on the toolbar, or right-click the control and select Properties from
the shortcut menu, or select the control and select View → Properties from the menu. Click the
ua
Data tab, click the Control Source box, and then either click the arrow and select the field
that you want to bind the control to or enter an expression. Close the Properties dialog box when
you’re finished.
al
Ev
g
Creating a Calculated Control
in
• To Create a Calculated Control: Display the form in Design View, select the control and click the
Properties button on the toolbar. Click the Data tab and click in the Control Source box, type
the expression or use the Expression Builder to create the expression, and then close the
in
Properties dialog box.
E tra
Changing a Control’s Default Value
• To Set a Control’s Default Value: Display the form in Design View, display the properties for the
desired control, and click the Data tab. Click the Default Value box and type the default value you
want to appear for new records. Close the Properties dialog box when you’re finished.
UfSor
Using the Control Wizard
• To Create a List Box or Combo Box: Display the form in Design View, click the Toolbox
button on the toolbar if necessary and make sure the Control Wizards button on the Toolbox
Nd
is selected. Click the Combo Box or List Box button on the Toolbox. In the form window,
click and drag where you want the control to appear. Specify whether you want the control to get its
LY IOse
values from a table or query, or if you want the control to find a record on the form. Select the table
that contains the fields you want to include in the list, click Next, select the fields you want to
appear in your list and click Next. Adjust the column widths if necessary, click Next. If necessary,
u
specify which column contains the value that will be stored and click Next. Specify whether Access
should merely display the value or display it in a field. Enter a label and click Finish.
T
ON Ae
Creating a Subform
b
• To Create a Subform: Display the form in Design View, click the Toolbox button on the
toolbar if necessary and make sure the Control Wizards button on the Toolbox is selected.
U
ALto
Resize the form if necessary, then click the Subform/ Subreport button on the Toolbox and
click and drag where you want the subform to appear in the form. Click Next and specify the table
or query you want to use for the subform and select the fields you want to appear in the subform.
Click Next, specify the parent and child fields that link the main form and subform if necessary, and
EVot
click Finish.
• To Modify a Subform: Display the main form in Design View and click inside the subform. Edit
the subform as needed. Save your changes to both the main form and the subform.
OnR:
Quiz
tFio
1. Which of the following statements about the AutoForm Wizard is NOT true?
A. The AutoForm Wizard is the fastest and easiest way to create a form in Microsoft
ua
Access.
B. The AutoForm Wizard can only create five types of forms: Datasheet, Columnar,
Tabular, PivotTable, or PivotChart.
al
C. Forms created with the AutoForm Wizard usually come out looking sharp and
professional and don’t require any further clean-up work.
D. The AutoForm Wizard can only create forms based on a single table or query .
Ev
g
2. Which of the following statements is NOT true?
in
A. The Field List displays all the fields from a form’s underlying table or query.
B. Click the Field List button on the Toolbar to display the Field List.
C. You can add fields to a form by dragging them from the Field List onto the form.
in
D. The Field List displays all the fields from every table in a database.
E tra
independently of one another. (True or False?)
4. If you move a control on a form, the Tab Order, in which you advance from
one field to the next when you press the <Tab> key, is automatically
UfSor
updated. (True or False?)
5. A form that has a Datasheet Default View property would display one
record at a time in the form. (True or False?)
Nd
6. A calculated field… (Select all that apply.)
LY IOse
A. …is a bound control.
B. …is a control that contains an expression.
C. …can perform calculations on fields values, such as =[Cost]*[Commission].
D. u
…can perform calculations on explicit values, such as =2+4.
T
7. Which of the following set of tables would benefit from a subform? (Select
ON Ae
all that apply.)
b
8. When you add a subform to a main form, Access always recognizes how
the two forms are related (True or False?)
EVot
Homework
N
2. Use AutoForm to create and save a columnar form named “Customers,” using the
Customers table as the underlying data source.
tFio
3. Add a text box control with today’s date in the bottom-right corner of the Customers
form.
Hint: You will need to change the text box control’s data source to the expression
=Today()
ua
4. Rearrange the control fields on the form, so that the LastName and FirstName fields
appear before the SSN field.
al
5. Change the Customer form’s tab order to reflect the new field order.
6. Delete the DOB field control from the form.
Ev
7. Resize the Customers form as necessary, then use the SubForm Wizard to create a
subform based on the Insurance Claims table.
g
8. Modify the Insurance Claims subform so that its Default View property is Single
Form View.
in
9. Save your changes to the main form and the subform. Then close the form and the
Homework database.
in
Quiz Answers
E tra
1. C. The AutoForm Wizard can create forms in record time, but they aren’t usually
well-organized or professional looking.
2. D. The Field List only displays fields from a form’s underlying table or query.
UfSor
3. False. You can click and drag the upper left sizing handle to move a label or control
independently of one another.
4. False. If you add or move a control on a form, you would have to change the form’s
tab order yourself—Microsoft Access won’t do it for you.
Nd
5. False. A form whose Default View property was set to Datasheet would display
LY IOse
multiple records. A form whose Default View property was set to Single Form would
display one record on the form at a time.
6. B, C, and D. All of these statements are true.
u
7. A and D. Because subforms are great at displaying information from one-to-many
relationships, both of these tables would benefit from being displayed in a subform.
T
ON Ae
8. False. If you include the field that links the two tables, Access will automatically
recognize it, if you have already joined the two tables. If the tables aren’t related, you
b
may have to manually join the tables by connecting their related fields.
U
ALto
EVot
N
OnR:
tFio
ua
al
Ev
E tra
Working with Reports
UfSor
Chapter Objectives: ; Prerequisites
Nd
• Create and modify a report • How to use menus,
LY IOse
toolbars, dialog boxes,
• Add, delete, move, and size controls and shortcut
keystrokes.
• Adjust page margins and orientation
u • How to open and
• Add page numbers and dates modify database
objects.
T
Work with report sections
ON Ae
•
• How to add and edit
• Use reports to group and sort records database records.
b
It’s easy to print a simple list of records in a table or query—just click the Print button on the
toolbar. But if you want your printed hard copies to look professional and include
N
calculations, graphics, or a customized header or footer, you’ll need to create a report. Reports
present information from tables and queries in a format that looks great when printed.
Reports can also summarize and analyze the information in your database. For example, a
OnR:
report might tell you which of your employees had used the most sick days for the past year.
Here are just a few examples of how reports work well for presenting information:
• Attractive Formatting Options: You can change the type, size, and color of the fonts
tFio
used in a report to make it easier to read. You can also add lines, boxes, and graphics to
your reports.
• Sorting and Grouping Options: Reports are great for summarizing and organizing
ua
information. For example, you could create a report to total sales by day, week, or month.
• Combine Data from Linked Tables: One report can display data from several related
tables or queries.
al
This chapter explains all the ins and outs of creating and working with reports.
Ev
256 Microsoft Access 2003
g
in
Lesson 8-1: Creating a Report
with AutoReport
in
E tra
Figure 8-1
The New Report dialog
box. AutoReports
UfSor
Figure 8-2
A Tabular report created
by the AutoReport Wizard.
Nd
Select the table or query you want to
use for your report.
LY IOse
Figure 8-1
T u
ON Ae
U b
ALto
EVot
N
OnR:
Figure 8-2
tFio
The fastest and easiest way to create a simple report in Access is with the AutoReport Wizard.
The AutoReport Wizard can automatically create a report by arranging all the fields from a
table or query into a neatly formatted report.
ua
The AutoReport Wizard is easy to use but limited—it only works with one table or query and
there are only two types of reports that it can create, as shown in Figure 8-1. Of course, you
can always modify a report created by using the AutoReport Wizard.
al
In this lesson you will learn how to create a report using an AutoReport Wizard.
1.
Ev
g
2. Click the Reports icon in the Objects bar, then click the New button.
The New Report dialog box appears, as shown in Figure 8-1. You create a report with
in
the AutoReport Wizard by selecting one of the two AutoReport Wizards… New button
3. Select AutoReport: Tabular from the list.
in
… and the table or query you want to use for your report.
4. Click the Choose the table or query where the object’s data comes
E tra
from: arrow and select qryCustomers from the list.
That’s all the information the AutoReport Wizard needs to create your report.
5. Click OK to create the tabular report.
Access takes all the fields in the qryCustomers query, arranges them, and creates a
UfSor
report similar to the one shown in Figure 8-2. Yuck! Ugly-looking report, isn’t it?
6. Close the report without saving your changes.
The reports created by the AutoForm Wizards aren’t very pretty to look at, but they’re fast and
easy to create. If you want to have more control over what appears on your report, use the
Report Wizard. Either way you will probably want to do some clean-up work, such as
Nd
renaming the report’s column headings and moving/resizing its controls.
LY IOse
Table 8-1: Available AutoReport Layouts
Report Layout Description
T u Displays each record’s data vertically. Each field
of each record appears on a single line by itself.
ON Ae
U b
ALto
Columnar
Quick Reference
EVot
AutoReport: Columnar
Tabular AutoReport: Tabular
3. Click the table or query
you want to use for the
ua
g
in
Lesson 8-2: Modifying a Report
in
Report Selector Field List button Toolbox button Properties button
Figure 8-3 Click to select the Click to display/hide Click to display/hide Click to display properties
E tra
entire report. the Field List. the Toolbox. for the selected object.
A report in Design View. Double-click to
display the
report’s
properties.
UfSor
Report Header
Appears at the Field List
top (first page) of Drag and drop
the report. Drag to place fields
down divider to on the report.
create.
Nd
Toolbox
Page Header Click to create
Appears at the controls on the
LY IOse
top of each report. See
page. Drag down Table 8-2:
divider to create. Toolbox
Buttons and
Report Footer
Divider
Drag down to
T u Controls for
more about
each of these
create a footer that Figure 8-3 Detail Page Footer controls.
ON Ae
will appear at the Appears for each record. Appears at the bottom of each
very end (last page. Drag down divider to
b
After you create a report (from scratch, using the Report Wizard, or using the AutoReport
ALto
Wizard), you may decide to modify it to make it easier to read and understand. For example,
you might want to add or delete a field, change a column heading, or change the locations of
the fields in the report. You modify a report in Design View, which you can get to from:
• The database window: Click the Reports icon in the Objects bar to list the reports in
EVot
the database. Click on the report you want to modify and click the Design button.
• Any report window: Click the View button on the toolbar or select View → Design
N
1. From the Database window, click the Reports icon in the Objects bar if it
Design button isn’t already selected, then select the rptCustomers form and click the
Design button.
tFio
Design View is similar to many Paint programs: Think of the report as your canvas and the
Toolbox and Field List as the paintbrushes you use to add fields, headings, and lines to the
report.
al
Any object that appears on a report is called a control. A text box used to display record
information (usually fields from a table or query) or a column heading are both examples of
controls. You add controls to a report by clicking the control you want to use and then clicking
Ev
g
Table 8-2: Toolbox Buttons and Controls
in
Toolbox Button Description
Click this button and then click the control you want to select. To
select multiple controls, click this button and hold down the <Shift>
in
Select Objects key as you click each control, or drag a rectangle shape around all
the controls you want to select.
E tra
Control Wizards Click to use Control Wizards when you add controls to your report.
Creates a text label that appears the same for every record, such as
Label a heading. Most controls already include a text label.
UfSor
Creates a text box that displays information from tables and queries
Text Box in a report.
Creates a box around a group of option buttons so that the user is
Option Group only allowed to make one selection from the group box. Normally
used in forms, not reports.
Nd
Toggle Button Creates a toggle button. Normally used in forms, not reports.
LY IOse
Creates an option button (or radio button) that displays data from
Option Button two or more options. Normally used in forms, not reports.
Check Box
u
Creates a box that is empty or contains a checkmark. Use to display
data from a Yes/No field.
T
Creates a combo box. Normally used in forms, not reports.
ON Ae
Combo Box
b
List Box Creates a list box. Normally used in forms, not reports.
U
Inserts an OLE object that is not bound to a field in the current Quick Reference
EVot
Tab Control Creates a tab control. Normally used in forms, not reports. Open the report and click
the View button on
Inserts another report within the main report. Use when you want to the toolbar.
Subform/Subreport show data from a one-to-many relationship.
ua
Rectangle
g
in
Lesson 8-3: Adding and Deleting
Fields
in
E tra
Figure 8-4
Add a field to a report by
clicking and dragging it
from the Field List onto the
UfSor
report. Field List
Figure 8-5
Adding a field or control to
a report often produces
Nd
unwanted results: Here
the ZipCode field is the
LY IOse
wrong size, has an
unneeded text label, and
shoves the bottom edge of
the details section down.
Figure 8-6
T u
ON Ae
The steps in modifying a Figure 8-4
text label.
b
Figure 8-7
U
ALto
Figure 8-7
Once you have created a report, you can delete a field that you don’t need or make a report
more comprehensive by adding more fields to display additional information.
al
In this lesson you will modify an existing report by adding and deleting fields.
Ev
g
1. Make sure you have the rptCustomers report open in Design View.
Maximize the report window.
in
First, click the control you want to delete.
2. Click the DOB text box to select it.
in
Handles () appear around the control, indicating that the control is selected.
3. Press the <Delete> key to delete the DOB text box.
E tra
The DOB text box disappears from the report screen.
Unfortunately, adding fields to a report isn’t quite as easy…
4. If the Field List isn’t displayed, click the Field List button on the toolbar.
The Field List displays all the fields from the table or query you used to create the Field List button
UfSor
report—though you will often have to scroll down the Field List to find the field that Other Ways to Display
you want. Once the Field List is displayed, you can click and drag the field you want to the Field List:
add from the Field List onto the report, as shown in Figure 8-4
• Select View → Field
5. Scroll down the Field List until you find the ZipCode field. Click and List from the menu.
drag the ZipCode field to the right of the State field, as shown in Figure
Nd
8-5, then release the mouse button.
LY IOse
The ZipCode field appears on the report with less than desirable results, as shown in
Figure 8-5. An annoyance with adding controls to a report is that you almost always
have to do some clean-up work afterwards. For example, the ZipCode field has an
unneeded text label, isn’t positioned correctly, and has enlarged the Detail section of
u
the report. Don’t worry about the positioning for now—you’ll learn how to move
controls in the next lesson. We can fix some of the other problems, however, starting
T
with getting rid of the text label.
ON Ae
6. Click the ZipCode text label (NOT the actual ZipCode field or text box!)
b
8. Position the pointer over the DOB text label until it changes into a ,
Quick Reference
EVot
report.
To Delete a Field or
Control:
al
2. Press <Delete>.
g
in
Lesson 8-4: Moving and Sizing
Controls
in
E tra
Figure 8-8
To move a control,
position the mouse over a
border of the control, until
UfSor
the pointer changes to a
, and then drag and
drop the control to a new
location on the report.
Nd
LY IOse
Figure 8-8
u
It’s easy to change the location and size of a control on a report—and it’s something you will
T
ON Ae
usually have to do whenever you add a control, since Access rarely places things exactly right
in the first place. When you size a control, you increase or decrease the amount of information
b
Move a control by the control can display. When you select a control on a report, sizing handles appear around
clicking and dragging the edges of the control. Once you have selected a control, you can drag its sizing handles to
U
the control to a new adjust the size of the control or move the control to a new location on the report.
ALto
location.
This lesson will give you some experience moving and sizing the controls on the report you
created in the previous lesson.
1.
EVot
and its label. Sizing handles appear around the selected ZipCode field. Here’s how to move a
control:
4. Position the pointer on any border of the ZipCode text box (but not over
tFio
or control NOTE: It takes a good deal of precision to position the pointer over the tiny border of
independently. a field. Move the pointer very slowly and wait until you see it turn into a
before you try to move the control.
al
Ev
g
5. Click and hold down the mouse button while the pointer is still over the
border of the ZipCode text box. Drag the field directly to the right of the
in
State text box, as shown in Figure 8-8, then release the mouse button.
By simply dragging and dropping with the mouse, you can move any object on a
in
report—any shapes, lines, pictures, or text boxes.
Sometimes, after moving an object, you’ll find you want to move the object just a Resize a control by
smidgen. You can use the keyboard to move or nudge controls with greater precision. clicking it to select it
E tra
Simply hold down the <Ctrl> key as you press any of the arrow keys on the keyboard. and grabbing one of its
6. With the ZipCode text box still selected, hold down the <Ctrl> key and sizing handles,
press the <←> (left arrow) key. dragging, and then
releasing the mouse
The ZipCode text box moves to the left a smidgen.
button when the
UfSor
7. Make sure the ZipCode text box is still selected. Position the pointer over control reaches the
the middle-right sizing handle until it changes to a . Click and hold desired size.
down the mouse button and drag to the left until the label is about two-
thirds of its original size, then release the mouse button.
As you drag a control’s sizing handle, a dotted outline appears to help you resize it.
Nd
That’s all there is to moving and sizing controls on a report.
8.
LY IOse
Click the Save button on the toolbar to save your changes.
T u Quick Reference
ON Ae
To Resize a Control:
• Click the control to select
b
it.
To Move a Control:
OnR:
g
in
Lesson 8-5: Adjusting Page
Margins and Orientation
in
E tra
Figure 8-9
The Margins tab of the Top margin
Page Setup dialog box.
UfSor
Figure 8-10
Left margin Right margin
Margins on a page.
Figure 8-11
Bottom margin
Nd
The Page tab of the Page Figure 8-10
Setup dialog box.
LY IOse
Figure 8-12
Comparison of portrait and Figure 8-9
landscape page
orientations.
T u
ON Ae b
Portrait
U
ALto
EVot
Landscape
N
Figure 8-12
Figure 8-11
The default margins
OnR:
You’re probably already aware that margins are the empty space between the text and the left,
are one inch at the
right, top, and bottom edges of a printed page. The default margins for a report are one inch at
top, bottom, left, and
the top, bottom, left, and right. There are many reasons to change a report’s margins: To make
right.
tFio
room for more data, to add some extra space if you’re binding a document, or to leave a blank
space to write in notes. If you don’t already know how to adjust a page's margins, you will
after this lesson.
This lesson also explains how to change the page orientation. Everything you print uses one
ua
of two different types of paper orientations: portrait and landscape. In Portrait orientation, the
paper is taller than it is wide—like a painting of a person’s portrait. In Landscape orientation,
the paper is wider than it is tall—like a painting of a landscape.
al
1. Make sure that you have the rptCustomers report open in Design View.
Here’s how to modify the page setup for a report:
Ev
g
2. Click File → Page Setup from the menu and click the Margins tab if it is
not already in front.
in
The Margins tab of the Page Setup dialog box appears, as shown in Figure 8-9. Here
you can view and adjust the margin sizes for the current worksheet. Notice that there
in
are margins settings in the Top, Bottom, Left, and Right boxes.
3. Click the Top Margin box and type .5.
This will change the size of the top margin from 1.0″ to 0.5″.
E tra
4. Repeat Step 2 and change the Bottom, Left, and Right margins to 0.5
inches.
Do you think you have a handle on changing a report’s margins? Good, because
without further ado, we’ll move on to page orientation.
UfSor
5. Click the Page tab.
Resize a report by
The Page tab appears, as shown in Figure 8-11. clicking and dragging
6. In the Orientation area, click the Landscape option button. the right edge of the
This will change the worksheet’s orientation to Landscape when it is printed. report.
Nd
7. Click OK.
LY IOse
The Page Setup dialog box closes, and the report’s margins and page orientation
settings are changed.
When you change a report’s margins, you will usually want to resize the report itself—
8.
here’s how: u
If necessary, scroll to the right edge of the report. Click and drag the right
T
edge of the report to the right to the 7.5 inch mark on the ruler.
ON Ae
Let’s see how the newly formatted report looks.
9.
b
orientation. You can reduce or enlarge the display by clicking the area of the report you
ALto
margins.
To Change a Page’s
Orientation:
tFio
g
in
Lesson 8-6: Adding Page Numbers
and Dates
in
E tra
Figure 8-13
Select one of the following:
The Page Numbers dialog • Page N: Inserts a page number with
box. the format “Page 5.”
UfSor
• Page N of M: Inserts a page number
Figure 8-14 with the format “Page 5 of 10.”
The Date and Time dialog Specify where you want the page
box. numbers to appear on the report.
Nd
be aligned on the page. Select Left,
Center, or Right or, for duplex printing,
LY IOse
Inside or Outside.
Figure 8-14
OnR:
Reports that are several pages long often have information such as the page number or the
date located at the top (header) or bottom (footer) of every page. In this fast and easy lesson
tFio
you will learn how to use the Page Number command and Date and Time command to add
page numbers and/or the current date to your report.
1. Make sure that you have the rptCustomers report open in Design View.
ua
dialog box gives you several choices for how the page numbers can be formatted:
• Page N: Prints only the page number (for example, “Page 5.”)
Ev
• Page N of M: Prints the page number and the total number of pages (for
example, “Page 5 of 15.”)
g
3. Select the Page N of M option.
Next you need to specify where on the page you want the page number to appear—at
in
the top or bottom of the page—and how you want the page numbers aligned.
4. Select the Bottom of Page option and select Right from the Alignment
in
list.
That’s all there is to adding page numbers to a report.
5.
E tra
Click OK to close the Page Numbers dialog box.
The Page Numbers dialog box closes, and Access adds a text box with a page number
expression (="Page " & [Page] & " of " & [Pages]) to the Page Footer.
Here’s how to add the date and time to your reports:
6.
UfSor
Select Insert → Date and Time from the menu.
The Date and Time dialog box appears, as shown in Figure 8-14. You can specify to
add the date, time, or both to your reports. For this exercise, you only want the current
date to appear on your report.
7. Click the Include Time check box to remove its check mark.
Nd
Just like the Page Number dialog box, the Date and Time dialog box gives you several
choices for how the date and/or time can be formatted. The currently selected date
LY IOse
format (the first option) will work fine here so you can close the Date and Time dialog
box.
8. Click OK to close the Date and Time dialog box.
u
The Date and Time dialog box closes and Access adds a text box with a date number
expression [=Date()] to the Report Header.
T
ON Ae
Microsoft Access isn’t particularly bright and may place the date, time, or page
numbers on top of an existing control, as has happened here. To correct the problem
b
you will have to move the new control to a different location on the report. Quick Reference
9.
U
Click and drag the Date control [=(Date()] to the far right side of the
To Add Page Numbers:
ALto
report header.
Let’s see how our modified report looks. 1. Display the report in
Design View.
10. Click the View button on the Form Design toolbar.
2. Select Insert → Page
EVot
The report is previewed on the screen, and you can see the date and, if you scroll down, Numbers from the menu.
the page numbering.
3. Select the page-number
11. Save the changes you’ve made and close the rptCustomers report. format, position, and
N
alignment options.
4. Click OK.
OnR:
Design View.
2. Select Insert → Date
and Time from the menu.
ua
5. Click OK.
g
in
Lesson 8-7: Understanding Report
Sections
in
E tra
Figure 8-15
A report’s sections
displayed in Design View.
UfSor
Figure 8-16 Report Header
Section Header
Notice how the placement
of the “Detail” and “Group Page Header
Footer” text labels in Group Header
Nd
different report sections Detail Section
affects how and where Group Footer
LY IOse
they appear in the report. Page Footer
Report Footer
u Figure 8-15
T
ON Ae
U b
ALto
Figure 8-16
EVot
As if reports weren’t confusing enough as a whole, Access breaks them up into separate parts
called sections. Each section has its own specific purpose and always prints in the same order
on a report. Take a look at Table 8-3: Report Sections to familiarize yourself with these
N
sections. If you’ve ever used a word-processing program to create a report for school or work,
you’re familiar with the section concept—you can add headers and footers to your documents
that contain such information as the report name or page number.
OnR:
• Next take a look at the column headings (“Tour,” “Date,” etc.). These column
headings are in the Page Header section and will appear on top of each page.
• Next come the tour names, which appear in the Group Header section. You use
group header and group footer sections to group related records together.
al
Reports may have more than one group section to create subgroups.
• Here’s what the report’s all about: the Detail section. The Detail section contains
Ev
g
• After the Detail section come the report’s footer sections. You don’t need a
guided tour of the report’s footer sections, as they are really just the same as the
in
report’s header sections, only in reverse.
It’s difficult to see and appreciate report sections in Print Preview, so move on to the
in
next step and we’ll get a “behind the scenes look” at the report.
2. Click the View button on the toolbar to switch to Design View.
Access displays the rptAnnualSales report in Design View, as shown in Figure 8-15.
E tra
Now it’s easy to see the report sections—what a difference a change in perspective
makes! To better illustrate how information is displayed in report sections, we will add
a couple of identifying text boxes to the report.
3. Click the Label button on the Toolbox.
UfSor
The pointer changes to the label tool. Click and drag where you want the label. Label button
4. Position the pointer in the far-left side of the Detail section (to the
left of the Date field). Click and drag the text label and type Detail.
Since you added the text label to the report’s Detail section, it will appear with each
Nd
record. Move on to the next step and we’ll add an identifying text label to another
report section. It’s often easier to copy an existing control and then modify it than it is
LY IOse
to create a new control from scratch. Here’s how to do it:
5. Select the Detail label, click the Copy button on the toolbar, click the
TourName Footer section line and click the Paste button on the
toolbar. u
Access pastes the Detail label in the report’s TourName Group Footer.
6.
T
Change the copied label’s text to Group Footer.
ON Ae
Let’s see where these text labels will appear on the report.
b
Scroll down the report and notice where the Detail and Group Footer
labels appear. Close the report without saving your changes when you
finish.
Quick Reference
EVot
Report Header Contains text that appears at the top of the first page of a report, such as the 1. Display the report in
name of the report. Design View.
2. Click and drag the
OnR:
Page Header Contains text that appears at the top of each page of a report, such as the section line up or down.
Printed from Top to Bottom
records.
• Be familiar with the
Detail Contains text and the actual fields that are displayed for each record. This various report sections
would be equivalent to the main body in a word-processing document. described in Table 8-3:
ua
Report Sections.
Group Footer Used to place text and numeric summaries, such as totals or averages, at the
end of each group of records.
Page Footer Contains text that appears at the bottom of each page of a report, such as
al
page numbers.
Report Footer Contains text that appears at the end of the last page of a report. Often also
Ev
g
in
Lesson 8-8: Grouping and Sorting
Records
in
E tra
Figure 8-17
This report isn’t This report is
Grouping records by a grouped by fields; grouped by the
specific field makes them information runs Date fields;
easier to read. Compare
UfSor
together, making information is
the report that is grouped the report difficult to grouped and
read. organized by the
by date with the report that
month.
isn’t.
Figure 8-18
Nd
The Sorting and Grouping
Figure 8-17
LY IOse
dialog box. You can learn
more about its details in
Sorting and
Grouping Properties
ALto
Figure 8-18
EVot
Organizing records into logical groups often makes them easier to read and understand. For
example, the second report in Figure 8-17 is grouped by the date field, so that you can quickly
see how many sales occurred in a particular month. If you create a report using the Report
N
Wizard (the preferred method), you specify which fields you want to use to group and/or sort
your report by. If you’re modifying an existing report or creating a report from scratch, you
can use the Sorting and Grouping dialog box to create your groups. More importantly, if you
use a Wizard to create a report for you, you can use the Sorting and Grouping dialog box to
OnR:
Sorting and
In its current state the rptEmployeeSales report has Report Header, Page Header, Page
Grouping button Footer, and Report Footer sections, but it doesn’t have any grouping sections. To add a
Other Ways to Sort and Group Section to a report you need to summon the Sorting and Grouping dialog box.
ua
Group: 2. Click the Sorting and Grouping button on the Report Design toolbar.
• Select View → Sorting Access displays the Sorting and Grouping dialog box, which displays any fields that
and Grouping from the are currently being used for sorting or grouping your report, as shown in Figure 8-18.
al
menu. To add a section to group and/or sort by, select a blank row and select a field from the
Field/Expression drop-down list. In this exercise you will use the Employee field to
group and sort the report.
Ev
g
3. Click inside the first blank row and select Employee from the
Field/Expression drop-down list.
in
You can also specify the order in which Access sorts the records by selecting the order
you want to sort by (Ascending or Descending) from the Sort Order list. Since you
in
want to sort the Employee field in Ascending order, you can leave the Sort Order alone.
To make a Group Header or Group Footer, use the Group Properties settings at the
bottom of the dialog box. You want to add a Group Header for the Employee field—
E tra
here’s how to add one:
Change the field
4. With the Employee Field/Expression still selected, click the Group group/sort order by
Header list near the bottom of the dialog box and select Yes from the clicking and dragging
drop-down list. the field’s row
UfSor
Access adds an Employee Group Header to the report. selector to the
The order of the fields in the Sorting and Grouping dialog box is very important. The desired location.
field in the first row is the first sorting/grouping level, the second row is the second
sorting/grouping level, and so on. You want to group and sort your report by the
Employee field, then by the Date field, so you will have to rearrange the field order.
Nd
5. Click the Employee row selector, drag it above the Date row, and
release the mouse button. Then close the Sorting and Grouping dialog
LY IOse
box.
Now that you have created the Group Header, you need to specify what you want to
appear in it—usually the field the Group Header is based on. In this report you will
u
want to move the Employee text box control field from the Detail section to the Quick Reference
Employee Group Header section.
T
6. To Group Records:
ON Ae
Cut the Employee field from the Detail section and paste it in the
Employee Header section. 1. Display the report in
b
Click the View button to switch to Print Preview. 2. Click the Sorting and
Grouping button on the
ALto
Group Footer Specify whether you want the report to contain a footer section for this group. 4. Click the corresponding
Group On Allows you to choose the size of the group. For example, if you’re using a date Sort Order box, click the
field to group a section, you can group each value by day, week, month, or year. drop-down list, and
OnR:
Keep Together No: Prints the group without keeping the group header, detail section, and Properties you want to
group footer on the same page. use in the Group
Properties area.
Whole Page: Prints the group header, detail section, and group footer on the
ua
you’re finished.
g
in
Lesson 8-9: Creating Calculated
Controls
in
E tra
Figure 8-19 Function
UfSor
Start expressions Field names
with the equal (=) used in the
Figure 8-20 symbol. calculation must
be enclosed by
Calculated controls brackets [ ].
usually appear in the
Figure 8-19
Nd
footer sections of a report.
LY IOse
Figure 8-20 Calculated
controls
u
Footers are most often used to summarize report information. For example, a Group Footer
could total the number of harassing phone calls each telemarketer made and the Report Footer
T
ON Ae
could calculate the number of harassing phone calls made by all telemarketers.
If you create a report using the Report Wizard (the preferred method), you specify which
b
fields you want to summarize and the calculation you want to use to summarize them. Of
course, you can always add your calculated control or calculated field to summarize
U
information on an existing report. A calculated control displays totals and other arithmetic
ALto
computations on a form or report. Table 8-5: Common Summary Functions describes the
functions you will use most often to summarize your reports.
1.
EVot
Make sure you have the modified rptEmployeeSales report you worked
on in the previous lesson open in Design View.
The section footer in which you place a calculated control is very important, as each
N
sales for all records. First though, you will need to resize the Report Footer so that
there is enough room to add such a control. Here’s how to change the size of a section.
2. Click and drag the Report Footer section divider down a half-inch.
ua
Now that you have enough room in the Report Footer you can add the calculated
control. There are two ways to add a calculated control to a form or report:
• Click the Text Box control on the Toolbox and click and drag where you
want to add the control.
al
• Copy an existing text box control, select the desired location, and paste the
copied text box control.
Ev
You can use either method, but the copy and paste method is a little faster and easier
because it copies formatting options and gives the new control a consistent look.
g
3. Select the Total text box control in the Detail section and click the
Copy button on the toolbar. Click the Report Footer section divider
in
and click the Paste button on the toolbar. Sorting and
Grouping button
Access pastes the copied control. Next you have to add an expression to the control.
4.
in
With the new Total text box in the Report Footer still selected, click the Other Ways to Sort and
Group:
Properties button on the toolbar.
• Select View → Sorting
E tra
The Properties dialog box appears. You need to enter the expression in the Control
and Grouping from the
Source property, which you can find on the Data tab.
menu.
5. Click the Data tab, click in the Control Source box, type
=SUM([Total]), and close the Properties dialog box.
You’re finished adding a calculated control that will total the Total fields on the report.
UfSor
Next you want to add another footer and calculated control that will total the total sales
by employee. First you need to add an Employee Group Footer section to your report.
6. Click the Sorting and Grouping button on the toolbar.
The Sorting and Grouping dialog box appears. Quick Reference
Nd
7. Click in the Employee Field/Expression box, click the Group Footer
To Create a Calculated
box, select Yes, and then close the Sorting and Grouping dialog box.
LY IOse
Control:
Because the Total text box control you created in Steps 3–5 already contains the SUM 1. Display the report in
expression you need, you can simply copy and paste the control in the Group Footer. Design View.
8. Copy the Total text box control in the Report Footer section, click the
u 2. Select the control and
Employee Footer section divider, and paste the control.
click the Properties
T
You need to add some meaningful labels to your report. Often, it’s useful to add a button on the toolbar.
ON Ae
calculated control that mixes some text with the current value of a field to produce an
Or…
informative notice for the report.
b
paste it in same section. Change the Data Source property of the the shortcut menu.
ALto
some examples).
Function Description Example
Or…
Sum Totals all the values listed in a field. Sum([InvoiceTotal])
Click the Build
ua
Maximum Finds and displays the largest value listed in a field. Max([InvoiceTotal]) button and use the
Expression Builder to
Minimum Finds and displays the smallest value listed in a field. Min([InvoiceTotal]) create the expression,
Average Calculates the average of all the values listed in a field. Avg([InvoiceTotal]) then click OK when you’re
al
finished.
Count Counts how many values are listed in a field. Count([InvoiceTotal]) 5. Close the Properties
Ev
dialog box.
New Row Or Col Works the same as the Force New Page property when you’re printing a report To Modify a Report’s
in columns. Section and Grouping
Options:
Keep Together Used to specify whether you want to allow Access to put breaks when they 1. Display the report in
occur naturally (No) or forces Access to keep the entire section on one page Design View.
when possible (Yes).
2. Click the Sorting and
Visible Used to specify if you want to see the section (Yes) or not (No). Hiding a Grouping button on the
report’s Detail Section is useful when you want to create a summary report that Report Design toolbar.
uses a Group Footer to total database information without displaying the
individual records. To Modify a Section’s
Properties:
Can Grow Used to specify whether the section can grow larger to accommodate more data
1. Display the report in
in the last field in the section (the field control Can Grow property must also be
Design View.
set to Yes).
2. Double-click the section
Can Shrink Enables the section to grow smaller if the extra space is not needed. (Used in line for the section whose
conjunction with the Can Shrink property for a field control.) properties you want to
view/modify.
Repeat Section When a group is split across several pages use the Repeat Sections property to
specify if Access should repeat the heading on the new page.
Property Description
Height Access automatically sets this property as you drag the section divider up or
down on the screen. You can specify an exact size (for example, if you want the
section to be precisely three inches tall) by entering it here.
Back Color Used to specify the color of the section. Click the button to select the color.
Special Effect Adjusts the visual effects for the section. Your choices are limited to Flat (the
default setting), Raised, or Sunken.
Figure 8-23
Figure 8-24
You already know what a chart is—charts illustrate data, relationships, or trends graphically. Other Ways to Create a
Chart Report:
Like the saying “a picture is worth a thousand words,” charts are often better at presenting
information than hard-to-read numbers in a datasheet. Microsoft Access comes with a great • Display the report in
built-in program for creating charts called Microsoft Graph. You can insert charts and graphs Design View, select
on forms and reports, and this lesson will show you how. Insert → Chart from
the menu, and then
1. Click the Reports icon in the Objects bar of the Database window and drag and drop a chart
click the New button. on the report, which
The New Report dialog box appears. opens the Chart
Wizard. Click the drop-
2. Select Chart Wizard from the list, select qryCustomerTours from the
down list and select
Table or Query drop-down list, and click OK.
the table or query
The first screen of the Chart Wizard appears. Here you have to tell the Wizard which whose data you want to
fields you want to display on the chart. plot. Follow the
3. Double-click the TourName field in the Available Fields list. onscreen instructions to
The TourName field appears in the Fields for Chart list. create the chart report.
4. Click Next.
The Chart Wizard asks what type of chart you want to use to display your data, as
shown in Figure 8-23. Table 8-7: Types of Charts and Graphs shows the more
common charts and gives an explanation on how and when they are used.
5. Select the Pie Chart as shown in Figure 8-23 and click Next.
Next the Chart Wizard asks how you want to lay out the data in your chart. You do this
by dragging and dropping the data fields to the appropriate areas on the chart. Since we
chose a simple pie chart, everything is already correctly laid out for us.
6. Click Next.
You can specify a chart title if you’re not thrilled with Microsoft Access’ imaginative
suggestions. You can also specify if you want to include a legend with your chart.
7. Click in the What title would you like for your chart? box and type
Total Tours. Click Finish to create the pie chart.
Access creates the pie chart, shown in Figure 8-24.
NOTE: The Microsoft Graph program seems to have some bugs, so the legend of your
chart may be missing some items.
8. Exit Microsoft Access without saving any changes.
Column charts are used when you want to compare different values To Insert a C
vertically side by side. Each value is represented in the chart by a vertical Report:
bar. If there are several values in an item, each value is represented by a 1. Display the
Column
different color. Design Vie
2. Select Inse
Bar charts are just like column charts, except they display information in from the me
horizontal bars rather than vertical columns. drag and dr
the report, w
Bar the Chart W
3. Select the t
Line charts are used to illustrate trends. Each value is plotted as a point you want to
on the chart and is connected to other values by a line. Multiple items are Table or Q
plotted using different lines. down list.
Line continue.
4. Double-click
Area charts are the same as line charts, except the area beneath the
you want to
lines is filled with color.
chart. Click
continue.
Area
5. Click the ch
Pie charts are useful for showing values as a percentage of a whole. The want and cl
values for each item are represented by different colors. continue.
6. Make any la
Pie modification
Click Next t
Scatter charts are used to plot clusters of values using single points. 7. If you want
Multiple items can be plotted by using different colored points or different change from
point symbols. record, sele
Scatter that link the
and the cha
Combination charts combine two different types of charts together (for to continue.
example, a combination chart might contain both a column chart and a 8. Enter a cha
line chart). click Finish
Combination
Lesson Summary
Creating a Report with AutoReport
• To Create a Report with AutoReport: From the Database window, click the Reports icon in the
Objects bar, click the New button, and select either AutoReport: Columnar or AutoReport:
Tabular. Click the table or query you want to use for the report from the drop-down list and Click
OK.
Modifying a Report
• To Modify a Report: From the Database window, click the Reports icon in the Objects bar, click
the report you want to modify and click Design, or open the form and click the View button
on the toolbar.
• To Insert the Date and/or Time: Display the report in Design View, select Insert → Date and
Time from the menu, check or uncheck the Include Date box and select a formatting option.
Check or uncheck the Include Time box, select a formatting option, and click OK.
Quiz
1. Which of the following statements about the AutoReport Wizard is NOT
true?
A. The AutoReport Wizard is the fastest and easiest way to create a report in Microsoft
Access.
B. The AutoReport Wizard can only create two types of reports: Columnar and Tabular.
C. Reports created with the AutoReport Wizard usually come out looking sharp and
professional and don’t require further clean-up work.
D. The AutoReport Wizard can only create reports based on a single table or query .
5. You want a report to group and total sales by month. Where would you
place a calculated control containing the following expression
=SUM([Sales]) to calculate the totals for each month?
A. In the Month Group Footer section.
B. In the Page Footer section.
C. In the Report Footer section.
D. In the Summary section.
7. The only way to sort a report’s records is to base the report on a query,
which actually does the work of sorting the records. (True or False?)
9. You want to track the progress of the stock market on a daily basis. Which
type of chart should you use?
A. Line chart.
B. Column chart.
C. Row chart.
D. Pie chart.
11. How can you view a report’s sorting and grouping options?
A. Select Format → Sorting and Grouping from the menu.
B. By double-clicking the Report Selector box in the upper left corner of the report.
C. Select File → Page Setup from the menu and click the Sorting and Grouping tab.
D. Click the Sorting and Grouping button on the toolbar.
Homework
1. Start Microsoft Access, if necessary, and then open the Homework database.
2. Use AutoReport to create and save a tabular report named “Customers,” using the
Customers table as the underlying data source.
3. Delete the DOB field from the report.
4. Change all of the report’s margins to a half-inch.
5. Sort the information on the report by DOB.
6. Save your changes and close the Homework database.
Quiz Answers
1. C. The AutoReport Wizard can create reports in record time, but they aren’t usually
well-organized or professional looking.
2. D. The Field List only displays fields from a report’s underlying table or query.
3. False. You can click and drag the upper left sizing handle to move a label or control
independently of one another.
4. B. This procedure will let you add page numbers in Microsoft Word, but not in
Microsoft Access.
5. A. You would want the calculated control in the Month Group Footer section to total
monthly sales.
6. C. Although you can summarize information in a report section, there isn’t actually a
section called a “Summary section.”
7. False. Although you can sort a report using a query, you can also simply click the
Sorting and Grouping button on the toolbar and specify the field you want to use to
sort the report.
8. A. This expression is missing the quotation marks (") and the ampersand (&) symbol.
The corrected expression would be ="Total for: "&[Employee].
9. A. Line charts are used to illustrate trends. If you used the other three chart types to
track the stock market, there would be too many data points.
10. C. You adjust a page’s margins by selecting File → Page Setup from the menu,
clicking the Margins tab, and adjusting the margins.
11. D. Click the Sorting and Grouping button on the toolbar to view a report’s sorting
and grouping options.
12. D. All of these are procedures for selecting multiple controls on a report.
Forms and reports created with a Microsoft Access Wizard are informative and functional—
but they are rarely well designed. Some of the forms and reports set up by the Form Wizard or
Report Wizard are even downright ugly. Don’t worry—this chapter will help you fix the
design of your forms and reports.
This chapter guides you through the process of creating sharp-looking forms and reports that
have colorful fonts, neat-looking borders, even controls with 3-D effects. This chapter
explains how to format your forms and reports to make them more visually attractive and
easier to read. You will learn how to change the appearance, size, and color of fonts and how
to align text inside a control. This chapter also describes how you can add pictures and
graphics to your forms and reports.
286 Microsoft Access 2003
1. Select the control you 2. Click the Font Size list The size of the fonts in
want to format. arrow ( ) and select the selected cell(s) is
the font size. changed.
Figure 9-2
You can emphasize text on a form or report by making the text darker and heavier (bold),
slanted (italics), larger, or in a different typeface (or font.) The Formatting toolbar
makes it easy to apply character formatting. The Formatting toolbar includes buttons for
applying the most common formatting options.
1. Start Microsoft Access, open the Lesson 9 database, click the Reports
icon in the Objects bar, and double-click the rptTourSales report.
Access displays the rptTourSales report in Print Preview. A quick look at this report is
all you need to realize that the Report Wizard could use a few remedial graphical
design classes. Fortunately, a little moving, resizing, and formatting will fix all of the
report’s design problems.
2. Click the View button on the Print Preview toolbar to switch to Design
View.
In order to format a control, you must first select it. The TourName text box in the
TourName Header needs to stand out a little more from the rest of the report.
3. Click the TourName text box control in the TourName Header to select
Font list it.
Handles () appear around the text box control, indicating that the control is selected.
Once you have selected a control, you can format it.
4. Click the Font list arrow ( ) on the Formatting toolbar, then scroll to
and select Arial from the list of fonts.
Font Size list
The text in the TourName text box control appears in Arial font. Arial and Times New
Roman are two of the most commonly used fonts in Windows.
You can also use the Formatting toolbar to change the size of a font. Font sizes are
measured in points (pt.), which are 1/72 of an inch. The larger the number of points, the
larger the font.
5. With the TourName text box still selected, click the Font Size list
arrow ( ) on the Formatting toolbar and select 14, as shown in Figure
9-2.
The TourName text box appears in a larger font size (14-point type instead of the Bold button
previous 11-point type). Wow! That font formatting really makes the title stand out
from the rest of the report, doesn’t it?
NOTE: When you change a control’s font size, you will often have to resize the
control so that it can properly display its contents.
All the column-heading labels in the Page Header section need to be emphasized as
well. You could select and format each label individually, but it’s much faster to select
Clicking in the vertical
and format all of them at the same time. If the controls you want to format are arranged
ruler selects every
along a horizontal line, you can click to the left of the controls, in the vertical ruler, to
select all of them. control to the right of
where you clicked.
6. Select all the labels in the Page Header section by clicking in the
vertical ruler to the left of the TourName label.
Access selects everything to the right of where you clicked the mouse. Let’s apply
boldface formatting to the selected text labels.
7. Click the Bold button on the Formatting toolbar.
The selected controls appear in bold.
8. Click the Save button to save your changes to the report.
This lesson explains how to align a control’s text to the left, center, or right. Figure 9-3 gives a
better idea of what the various alignments look like. Alignment only affects what’s inside of a
control: If you apply center formatting to a text box, Access will center the text inside the text
Center button box—it won’t center the text box control on the form or report. If you want to align a control
to the left, center, or right of a form or report, you’ll have to do it the old-fashioned way—by
clicking and dragging the control.
Align Right button 1. Make sure that the rptTourSales report is open in Design View.
Again, you first need to select the control you want to format.
2. Select the Date text label in the Page Header and click the Center
button on the Formatting toolbar.
Quick Reference
Access centers the text inside the Date text label. Easy, isn’t it? Let’s try aligning one
To Change Text more control.
Alignment: 3. Click the TourName text label in the Page Header and click the Align
• Select the control and Right button on the Formatting toolbar.
click the Align Left, Access right-aligns the text inside the TourName text label.
Center, or Align 4. Click the Save button to save your changes to the report.
Right button
on the Formatting toolbar.
Table 9-2: Alignment Formatting Buttons on the Formatting Toolbar
Button Name Example Formatting
Align Left Left Aligns text to the left side of the control.
Align Right Right Aligns text to the right side of the control.
You’ve just finished creating a report using the Report Wizard when you suddenly realize that
you hate how it looks! Don’t worry—you can apply a new design to your forms and templates
at any time with the AutoFormat command. AutoFormat is a built-in collection of formats
such as font sizes, patterns, and alignments you can quickly apply to a form or report.
AutoFormat is a great feature if you want your forms and reports to look sharp and
AutoFormat
professional but don’t have the time to format them yourself. button
1. Make sure the rptTourSales report is open in Design View.
Here’s how to format a report using AutoFormat:
2. Click the AutoFormat button on the Report Design toolbar.
The AutoFormat dialog box appears, as shown in Figure 9-5. The present formats are
listed in the AutoFormat list. Yep, they’re the same choices as you get in the Report or
Form Wizard. You can see what a format looks like by selecting it and looking at the
Quick Reference
sample area in the dialog box. To Format a Form or
3. Click the Options button. Report with AutoFormat:
The AutoFormat dialog box expands to show three check boxes. You can control the 1. Display the form or report
type of formatting that is applied by checking or unchecking any of the boxes. If you you want to format in
want AutoFormat to skip one of the formatting categories, simply uncheck the Design View.
appropriate box. 2. Click the
4. Select the default Compact option from the Report AutoFormats list and AutoFormat button on
click OK. the Report Design toolbar.
The dialog box closes, and the report is formatted with the Compact formatting option. 3. Select one of the
5. Click the Save button to save your changes and then close the AutoFormats from the list
rptTourSales report. and click OK.
In this day of color, laser, and inkjet printers, and high-resolution 21-inch monitors, choosing
an appropriate color for your report or form is an important formatting decision. If used
tastefully, colors can make your forms and reports look more visually attractive. You can add
color to lines, text, rectangles—even to the background of your headers and footers!
In this lesson, you will learn how to use the color buttons on the Formatting toolbar to apply
color to your reports and forms.
1. Click the Forms icon in the Objects bar and open the frmCustomers
form in Design View.
There are three color buttons on the Formatting toolbar—each color button applies
color to a different element. It can be a little confusing to figure out which color button
to use at first, so you’ll want to refer to Table 9-3: Color Buttons on the Formatting
Toolbar until you get the hang of it.
Quick Reference 2. Click the Customers text label in the Form Header, click the Font/Fore
Color button arrow on the Formatting toolbar, and select a yellow
To Change a Control’s color.
Colors:
You can also apply color to the sections of a report or form.
• Select the control and
click one of the following
3. Click the Form Header section divider, click the Fill/Back Color
buttons on the Formatting
button arrow on the Formatting toolbar, and select a dark blue color.
toolbar:
Fill/Back Color Table 9-3: Color Buttons on the Formatting Toolbar
Font/Fore Color Color Button Example Description
Line/Border Color Applies color to the background of the
Fill/Back Color selected control(s).
Applies color to the text in the selected
Font/Fore Color control(s).
Applies a color or makes transparent the
Line/Border Color line or border of the selected control(s).
Figure 9-7
You can apply special-effect formatting to the controls in your forms and reports to give them
a polished, high-tech appearance. For example, you can give a form a three-dimensional look Special Effect
by applying a sunken or raised effect to its controls. Applying special-effect formatting is button
pretty straightforward: Simply select the controls you want to format and then select one of
the six special-effect options (listed in Table 9-4: Available Special-Effect Options) from the
Special Effect button list.
Sunken Etched
Shadowed Chiseled
Figure 9-8
If you find yourself applying exactly the same formatting to several controls repeatedly, the
Format Painter is the tool for you. The Format Painter allows you to copy the formatting
attributes from one control and then apply them to another. Sound confusing? It won’t once
you have finished this lesson.
Figure 9-9
Select Preview
from the list to
Select the display a preview of
graphic file you the selected graphic
want to insert. file.
A preview of the
selected graphic file
appears here.
Figure 9-10
Pictures, graphics, and illustrations can make your reports more professional looking. This
Image button lesson explains how to insert clip art and graphics in your reports. You can insert graphics and
pictures created with graphics programs such as Microsoft Paint (which comes with
Other Ways to Insert a
Picture: Windows), scanned pictures, or graphics from a clip-art library.
• Select Insert →
Picture from the menu.
1. Make sure that you have the rptCustomers report open in Design View.
Here’s how to insert a picture or graphic onto a report (this works for forms too!).
2. Click the Image button on the Toolbox.
The pointer changes to a . You use this pointer to determine where you want to
place the image.
3. Click and drag the pointer in the Report Header section down and to
the right about an inch and a half, as shown in Figure 9-9.
As soon as you finish clicking and dragging, the Insert Picture dialog box appears, as
shown in Figure 9-10. You need to specify the name and location of the graphic file
you want to insert. Line button
4. Browse to your Practice folder.
All the graphic files located in your Practice folder appear in the file window.
5. Select the Plane file.
You can display a preview of the graphic in the right side of the Insert Picture dialog If you want to add a
control, such as a line,
box by clicking the list and selecting Preview.
that is larger than the
6. Click OK to insert the Plane graphic. current screen width,
Access inserts the plane picture on the report. simply click and drag
Reports with lots of information can sometimes be difficult to read. You can add the pointer past the
vertical and/or horizontal lines to make your reports more organized. edge of the screen.
7. Click the Line button on the Toolbox.
The pointer changes to a line-draw tool. Unless you actually want to draw a
diagonal line, hold down the <Shift> key as you click and drag to draw a straight line.
8. Position the pointer in the far left side of the top of the Detail section
(just above the LastName text box). Click and hold down the <Shift> key
as you drag the pointer to the far right edge of the report.
More than likely your screen will not be wide enough to display the entire report—
don’t worry, simply drag the pointer past the right edge of the screen to
automatically scroll to the right.
Let’s see how our report looks.
Quick Reference
9. Click the View button to view the report in Print Preview.
Notice that the line you added appears not once but under every record! That’s because To Insert a Graphic:
you added the line to the report’s Detail section, which prints for every record in the 1. Click the Image
report. button on the Toolbox.
10. Save your changes and close the report.
2. Move the pointer
You can also use this technique to add pictures to your forms. Here’s a list of some of the onto the form or report,
types of graphic formats that you can use in Access: then click and drag to
draw a rectangle
placeholder for the
Table 9-5: Common Graphic File Formats
graphic.
Format File Size Description 3. Select the graphic file you
BMP Large Also known as a bitmap, this is a generic graphics format used by want to insert and click
Paintbrush and many other programs. OK.
CGM Small Clip-art pictures often come in Computer Graphics Metafile format. To Draw a Line:
GIF Small Picture file format commonly used on the Internet. 1. Click the Line button
on the Toolbox.
JPG Small Digital photographs are usually saved as JPEG files. Because of their small
2. Move the pointer onto
size, JPEG files are also commonly used on the Internet.
the form or report, then
WMF Small Another file format used for clip-art pictures click and drag to draw the
line.
TIF Large A file format used by scanners, fax programs, and some drawing programs.
• Hold down the <Shift>
key as you drag to draw a
straight line.
Figure 9-11
Forms and reports that have controls scattered randomly about them look terrible. The Align
command, located under the Format menu, aligns controls relative to one another. You can
align controls so that they are lined up with one another or spaced equally apart from one
another. This lesson will give you some practice aligning controls with the Align command.
1. Open the rptEmployeeSales report in Design View. Select more than one
Someone sure was sloppy when creating this report—its controls are all over the place! control by holding
You could manually move the controls and align them with one another by using the down the <Shift> key
mouse and eyeballing it, but that would require a lot of time, and (unless you have eyes …oras
byyou click
using each
the
like a hawk) it would be difficult to align the controls perfectly. Instead, we’ll align the object…
pointer to draw a box
controls using the Align command.
around the controls
First you need to select the controls you want to align with one another. There are three
you want to select…
ways to select more than one control:
• Press and hold down the <Shift> key as you click each control that you want to
select.
• Use the arrow pointer ( ) to draw a box around the controls that you want to
select. Point to a location above and to the left of the controls that you want to
select, and click and drag the mouse down and to the right until the box …or by clicking in the
surrounds all the controls. When you release the mouse button, all the controls in vertical ruler to select
the box will be selected. The disadvantage of this method is that it’s not as every control to the
selective as using the <Shift> + click method. right of the ruler.
• If the controls you want to select are aligned along a horizontal line, click to the
left of the object in the vertical ruler to select every control to the right of the
ruler.
2. Hold down the <Shift> key as you select the Employee text label and
Employee text box control as shown in Figure 9-11.
Now you can align the selected controls with each another. Here’s how:
3. Select Format → Align → Left from the menu.
The Employee text box control is left-aligned with the Employee text label.
Next let’s try vertically aligning two controls—the procedure is almost the same.
4. Hold down the <Shift> key as you select the Employee text box
control and Date text box control.
Now let’s vertically align the controls with each other.
5. Select Format → Align → Top from the menu.
Access vertically aligns the two controls with each other.
You can also quickly adjust the amount of horizontal or vertical space between controls
by selecting the controls and then selecting a command from either the Horizontal
Spacing or Vertical Spacing submenu under the Format menu.
Move on to the next step and we’ll adjust the amount of space between the controls on
the report.
6. Hold down the <Shift> key as you click the vertical ruler to the left of
the text labels in the Page Header. Keep holding the <Shift> key and
click the vertical ruler to the left of the fields in the Detail section.
You’ve selected all the text labels in the Page Header and all the fields in the Detail
section. Here’s how to adjust the spacing between the selected controls with just a few
quick clicks of the mouse.
7. Select Format → Horizontal Spacing → Make Equal from the menu.
Access evenly distributes the selected controls.
8. Click and drag the Page Footer divider up to reduce the amount of
empty space in the Detail section.
You’re finished!
9. Save your changes and close the form.
Quick
To Select Mu
Controls:
• Press and h
<Shift> key
each object
to select.
Or…
• Use the arro
to draw a bo
objects that
select.
Or…
• If the contro
along a hor
vertical line
horizontal o
above or to
controls.
To Align Obje
Each Other:
1. Follow the a
select the o
want to alig
2. Select Form
and select a
option from
Figure 9-12
The Formatting toolbar is great for quickly applying the most common formatting options to
the controls on your forms and reports, but it doesn’t offer every formatting option available.
To see and/or use every possible formatting option, you need to view the control’s Formatting
Properties. Each type of control has its own set of formatting properties—for example, a line
control has a Border Style property, which determines if the line should be solid, dashed, or
dotted.
To display the Formatting Properties for a control, do one of the following:
• Select the control and click the Properties button on the toolbar.
• Right-click the control and select Properties from the shortcut menu.
• Double-click the control.
• Select the control and select View → Properties from the menu.
…and then click the Format tab if necessary. The more common Formatting Properties are
listed in Table 9-6: Common Formatting Properties. You might want to review the Working
with Tables and Fields chapter as well, which contains information on formatting fields.
This lesson will give you some practice working with a control’s Formatting Properties.
1. Make sure that you have the rptTourSales report open in Design View.
For this exercise, we’ll view and change the Formatting Properties of the dark red line
in the report’s Page Header.
2. Click the dark red line in the Page Header to select it, then click the
Properties button on the toolbar. Click the Format tab if necessary.
The Formatting Properties for the red line appear, as shown in Figure 9-12. There’s not
much to an ordinary line, so its Formatting Properties are rather limited. One
Formatting Property that we can change is the line’s Border Style property.
3. Click in the Border Style box, click the arrow, and select Dashes from
the list.
The line changes from a solid line to a dashed line. Let’s make one more formatting
change while the Properties dialog box is still open.
4. With the line still selected and the Properties dialog box still open, click
the Border Width button arrow and select 5 pt from the list.
The width of the line changes to three five points.
5. Exit Microsoft Access without saving any of your changes.
Lesson Summary
Formatting Fonts with the Formatting Toolbar
• To Change Font Size: Select the control and select the pt. size from the Font Size list on
the Formatting toolbar.
• To Change Font Type: Select the control and select the font from the Font list on
the Formatting toolbar.
• To Format Text with Bold, Italics, or Underlining: Select the control and click the Bold,
Italic, or Underline button on the Formatting toolbar.
Using AutoFormat
• To Format a Form or Report with AutoFormat: Display the form or report you want to format in
Design View, click the AutoFormat button on the Report Design toolbar, select one of the
AutoFormats from the list, and click OK.
Changing Colors
• To Change a Control’s Colors: Select the control and click one of the following buttons on the
Formatting toolbar:
Fill/Back Color
Font/Fore Color
Line/Border Color.
• To Copy Selected Formatting to Several Locations: Select the control with the formatting
options you want to copy, double-click the Format Painter button, select the controls where
you want to apply the copied formatting. Click the Format Painter button when you’re
finished.
• To Draw a Line: Click the Line button on the Toolbox, move the pointer onto the form or
report, then click and drag to draw the line. Hold down the <Shift> key as you drag to draw a
straight line.
Quiz
1. Fonts are measured in points. The larger the number of points, the smaller
the size of the font. (True or False?)
2. You select a control and then click the Align Left button on the Formatting
toolbar. What happens?
A. The control is aligned to the left side of the form or report.
B. Nothing – the alignment buttons on the Formatting toolbar are used to determine the
position of the form or report on the screen.
C. The text inside the control is aligned to the left side of the control.
D. Nothing – you must also select the control that you want to use to align the selected
control with.
4. The Fill/Back Color button on the Formatting toolbar applies color to:
A. The text in the selected control.
B. The background of the selected control.
C. The border of the selected control.
D. All aspects of the control.
5. What does the Special Effect button on the Formatting toolbar do?
A. It applies a 3-D effect to a selected control.
B. It lets you select a transitional effect for how a form opens and closes.
C. It lets you add animation to your forms and reports to make them more entertaining
and amusing.
D. None of the above.
6. Which of the following are reasons why you might want to format a control
using the Properties dialog box instead of the Formatting toolbar? (Select
all that apply.)
A. You want to show off your Microsoft Access expertise to do things the hard way.
B. The Properties dialog box offers every formatting option available for the control—
something the Formatting toolbar doesn’t have.
C. The Properties dialog box gives you greater control over how a control is formatted.
D. You can change the language used in a control using the Properties dialog box. For
example, you could select Spanish or French instead of English.
7. You want to insert a graphic of your company’s logo on a report. How can
you do this? (Select all that apply.)
A. You can’t—Microsoft Access won’t let you insert graphic files.
B. Click the Image button on the Toolbox and drag on the report to draw a placeholder
for the graphic.
C. Select Insert → Picture from the menu.
D. Select Tools → Insert Picture from the menu.
Homework
1. Start Microsoft Access, open the Homework database, and open the Test Answers
form in Design View.
2. Use AutoFormat to apply the International preset formatting style to the Test
Answers form.
Quiz Answers
1. False. It’s true that fonts are measured in points; however, the larger the number of
points, the larger the size of the font.
2. C. The text inside the control is aligned to the left side of the control.
3. False. AutoFormat lets you quickly format a form or report using a set of predefined
formatting options.
4. B. The Fill/Back Color button on the Formatting toolbar applies color to the
background of a selected control.
5. A. The Special Effect button applies a 3-D effect to a selected control.
6. B and C. The Properties dialog box gives you more control and options over how a
control is formatted.
7. B and C. To insert a picture on a form or report, click the Image button on the
Toolbox, and drag on the report to draw a placeholder for the graphic, or select Insert
→ Picture from the menu.
8. A. To align several controls with each other, select the controls by holding down the
<Shift> key as you click each object, then select Format → Align and select an
alignment option from the menu.
If you find yourself doing the same routine task over and over again, you might want to
consider creating a macro to complete the task for you. A macro helps you perform routine
tasks by automating them. Instead of manually performing a series of time-consuming,
repetitive actions, you can record a single macro that does the entire task all at once for you.
For example, instead of clicking the Reports icon in the Objects bar in the database window,
finding and opening a specific report, printing it, and then closing it, you could create a macro
to print the report with the click of a single button.
A macro is a set of one or more actions that perform a particular operation, such as opening a
form or printing a report. Macros can help you to automate common tasks. For example, you
can run a macro that prints a report when a user clicks a command button.
In a way, you can think of macros as a very simple introduction to programming because you
can use them to create automated tasks and somewhat complex procedures. Best of all, you
don’t have to know a single line of code—Access provides you with everything you need to
write a macro.
306 Microsoft Access 2003
Action Arguments
Give Access
information about
how to carry out the Help Area
action. For Provides you
example, if you use with help and
the OpenForm feedback.
action you need to
specify the form you
want the macro to Figure 10-1
open.
In some programs, such as Microsoft Excel or Word, you can create macros with a “macro
recorder” to record your commands, keystrokes, and mouse clicks. Unfortunately, there isn’t a
“macro recorder” or Macro Wizard to help you create a macro in Microsoft Access. Instead,
you create macros by entering the actions and arguments directly in Macro Design View,
shown in Figure 10-1. Don’t worry—it’s not as difficult as it sounds. Working in Macro
Design View really isn’t all that different from working in Table Design View—it’s where you
define and edit your macro objects.
Simple macros that automate a single task, such as opening a form or report, are incredibly
simple to create—we’ll create such a macro in this lesson. More complicated macros with
several steps or procedures may require a little bit of planning. Before you create a
complicated macro, think about what you want the macro to do and the individual actions that
are required to complete this operation. Practice the steps needed to carry out the operation
and write them down as you go—it will make writing the macro a lot easier.
And so, without any further ado, let’s create our first macro.
Macros icon
1. Start Microsoft Access, open the Lesson 10 database, click the Macros
icon in the Objects bar, and click New.
The Macro1: Macro window appears, as shown in Figure 10-1. The Action cell is
where you tell Access what you want the macro to do.
2. Click the Action list arrow.
New button A list of Actions appear. An Action, or command, is the basic building block of a
macro—it’s an instruction that tells Access what you want the macro to do. There are
more than 50 different Actions you can choose from. When you start creating your own
macros you will almost certainly want to refer to this chapter’s Macro Action Reference
on page 318 to help find the right Action.
Figure 10-2
Figure 10-3
Some Microsoft Access tasks require several steps. For example, a particular task might
require you to (1) open a form, (2) select a specific record, (3) select a specific field in that
record, and then (4) copy the information in that field to the Windows clipboard. Macros can
contain as many actions as necessary to automate even the most complicated tasks. Each
action appears in its own row and is evaluated and executed in the order in which it appears in
the Macro window, from top to bottom.
In this lesson you will edit the macro you created in the previous lesson to change its
arguments and add some more steps or actions.
3. Click the Action cell just below the Maximize action, click the Action
list arrow, scroll down, and select MsgBox.
The MsgBox action displays a message box that contains a warning or an informational
message. The Message argument is the most important argument for the MsgBox
action because it determines the text that is displayed in the message box.
4. Click the Message argument box and type Please make sure that
you remember to add the employee's phone number!.
There are several other arguments you may want to specify for the MsgBox action,
such as the type of icon that is displayed in the message box (None, Critical, Warning?,
Warning!, and Information) and the text that is displayed in the title bar of the message
box.
5. Click the Type argument box, click the Type argument list arrow,
and select Information. Click the Title argument box and type Notice.
Your macro should look like the one shown in Figure 10-2. Remember that actions are
evaluated and/or executed in the order in which they appear, so the mcrEmployees
macro will (1) open the frmEmployees form, (2) maximize the form window, and (3)
display the message box.
6. Click the Save button on the toolbar.
That’s all the editing we need to do for this lesson.
7. Close the macro window.
Let’s test the macro.
8. Double-click the mcrEmployees macro.
Sure enough, the mcrEmployees macro (1) opens the frmEmployees form,
(2) maximizes the form window, and (3) displays the message box.
9. Click OK to close the message box and close the frmEmployees form.
Quick Reference
To Modify a Macro:
• In the Database window,
click the Macros icon in
the Objects bar, select the
macro you want to edit,
and click Design.
Figure 10-4
Figure 10-5
If you are creating lots of macros, you might want to consider organizing them into a macro
group to help you manage them. A macro group stores several related macros together in a
single macro object. When you create a macro group, you must give each macro in the macro
group its own unique name to identify where each macro starts and ends. You do this by
entering the macro names in the Macro Name column, which you display by clicking the
Macro Names button on the toolbar.
When you combine two or more macros within the same macro group, you must run them
separately, by referring to the macro group name, followed by the macro name. For example,
mcrEmployees. mcrEmployees frmEmployees refers to the Open frmEmployees macro in the
mcrEmployees macro group.
In this lesson you will learn how to group several related macros together in a macro group.
3. Type Open frmEmployees in the first blank cell in the Macro Name
column.
The macro name “Open frmEmployees” identifies the macro you created in the
previous two lessons. To create another macro in the same macro group, type its name
in the Macro Name column next to the first action of the new macro.
4. Press the <↓> key three times.
The cursor should be positioned in the Macro Name column next to the first blank
Action row. This is where you can add another macro to the macro group.
5. Type Print rptEmployeeSales.
Print rptEmployeeSales is the name of the new macro we will create.
6. Click the Action cell to the right of the Print rptEmployeeSales name,
click the Action list arrow, scroll down, and select OpenReport.
Similar to the OpenForm action, which opens a form, the OpenReport action opens a
report. Next, you need to specify the arguments for the OpenReport action.
7. Click the Report Name text box in the Action Arguments panel, click the
Report Name list arrow, and select rptEmployeeSales.
This macro will open the rptEmployeeSales report. Notice Print appears in the View
argument—this will send the rptEmployeeSales report directly to the printer. Let’s add
a comment to this new macro.
8. Click the blank Comment box in the Print rptEmployeeSales macro row
and type This macro prints the rptEmployeeSales report.
You want to add one more action to the Print rptEmployeeSales macro.
9. Click the Action cell just below the OpenReport action, click the
Quick Reference
Action list arrow, scroll down, and select MsgBox.
You need to tell Access what you want the message box to say. To Create a Macro Group:
10. Click the Message argument box and type The Employee Sales 1. Create a new macro or
report has been sent to the printer. edit an existing macro.
You can specify additional arguments for the MsgBox action, such as the type of icon 2. Click the Macro
that is displayed in the message box. Names button on the
11. Click the Type argument box, click the Type list arrow, and select toolbar.
Information. Click the Title argument box and type Notice. 3. Type the macro name in
Your macro should look like the one shown in Figure 10-4. the Macro Name column
next to the Action where
12. Click the Save button on the toolbar and close the macro window. the macro starts.
Let’s test our new macro. When you combine several macros within the same macro 4. If necessary, add the
group you must run them separately using the Tools command on the Access menu. macro actions or edit the
NOTE: Don’t run a macro group by double-clicking it or selecting it and clicking existing macro actions.
Run. Doing so will run every macro in the macro group—often with 5. Save the macro and close
disastrous results! the macro window.
13. Select Tools → Macro → Run Macro from the menu. To Run a Macro in a Macro
The Run Macro dialog box appears, as shown in Figure 10-5. Here’s where you select Group:
the specific macro you want to run. 1. Select Tools → Macro
14. Click the Macro Name list arrow, select mcrEmployees.Open → Run Macro from the
frmEmployees, and click OK. menu.
Access runs the Open frmEmployees macro. 2. Click the Macro Name
15. Click OK to close the message box and close the frmEmployees form. list arrow, select the
macro you want to run,
If you want, go ahead and repeat Step 13 and run the Print rptEmployeeSales macro. Make and click OK.
sure your computer is connected to a printer, as this macro will send a copy of the
rptEmployeeSales to the printer.
New command
button
Figure 10-6
Click:
to select the macro you want to assign to the event.
to edit the macro in Macro Design View.
Figure 10-7
Running macros from the Database window or menu is a pain in the neck. That’s why most
database developers assign macros to controls—particularly, buttons—so that when a user
clicks the button or control, a macro is activated.
4. Make sure that the command button is still selected, then click its text
label and replace its text with Sales Report. Click anywhere outside of
the command button when you’re finished.
We’re ready to assign a macro to the button—to do this you will need to display the
command button’s Properties.
Properties button
5. Select the command button, click the Properties button on the toolbar,
and click the Event tab.
The Event tab lists all the events to which you can assign a macro—most of them you
will never use, as you can see in Table 10-7: Event Properties That Can Trigger
Macros.
6. Click the On Click box, click the list arrow, and select the mcrSales
macro. Close the Properties dialog box when you’re finished.
Let’s see how our new command button works.
7. Click the View button on the toolbar to switch to Form View then click
the new Sales Report button.
Microsoft Access runs the mcrSales macro and displays the Employee Commission
Report for the current employee.
8. Save your changes, and close the Employee Commission Report.
A conditional expression.
Figure 10-10 Figure 10-8 If the city is not
“Minneapolis,”
The updated mcrSales Access will
macro. Enter the execute these
conditions in actions…
the Condition …otherwise, if
column. the city is
“Minneapolis,”
Access will
execute this
action.
Figure 10-10
A condition takes action based on a certain condition. For example, if an employee’s weekly
sales are more than $2,500, then a condition could calculate a 5-percent commission bonus for
the employee; otherwise, it wouldn’t calculate a bonus. If you’re at all familiar with
programming, a condition is similar to an If…Then statement.
You enter conditions in the Condition column in the Macro window. If a condition is true,
Access executes the action in that row. If a condition isn’t true, Access skips the action in that
row and moves to the next row. Conditions often compare values in a specific control on a
form or report to a number, date, or constant. For example, the expression in Figure 10-9
evaluates if the value in a City field is not equal to “Minneapolis.” Make sure that you use the
proper Microsoft Access syntax when referring to controls in forms or reports.
1. Make sure you have the frmEmployees form from the previous lesson
open. Click the View button on the toolbar to switch to Design View.
We want to add a conditional expression to the mcrEmployees macro. If a macro is
assigned to a control on a form or report, you can open and edit the macro directly
from the form or report without having to access it through the Database window.
2. Select the command button, click the Properties button on the toolbar,
click the Event tab, and click the On Click box.
A Build button appears in every event property. Click this button to create or
modify the macro or Visual Basic procedure assigned to the event.
Figure 10-11
Sometimes, instead of assigning a macro to a command button, you may want to assign it to a
specific keystroke combination, such as <Ctrl> + <D>. Assigning a keystroke combination to
a macro makes it fast and easy to access—you can execute the macro at any time by pressing
its assigned keystroke combination.
Assigning a keystroke combination to macro can be a somewhat complicated process. There
are two things you need to know about assigning a macro to a keystroke combination:
• You must create a special macro group, named AutoKeys, which contains all your
keystroke-combination macros.
• You type the keystroke combination to which you want to assign the macro in the Macro
Name column of the AutoKeys macro window. Enter the keystroke combinations using
the examples in Table 10-8: The SendKey Syntax. For example, to assign a macro to the
keystroke combination <Ctrl> + <D>, you would name the macro ^D.
In this lesson you will learn how to create an AutoKeys macro to assign a macro to a
keystroke combination.
1. Click the Macros icon in the Objects bar, if necessary, and click New.
The Macro window appears, as shown in Figure 10-11. You need to display the Macro
Name Column in order to tell Access which keystroke combination you want to assign
to the macro.
2. Click the Macro Names button on the toolbar if necessary.
Macro Names Now you need to type the keystroke combination to which you want to assign the
button macro. Table 10-8: The SendKey Syntax shows the key combinations you can use to
make key assignments in an AutoKeys macro group. We want to assign a macro to the
keystroke combination <Ctrl> + <L>. Here’s what you need to enter:
Action Description
PrintOut Prints the active database object. You can print datasheets, reports, forms,
and modules.
Quit Quits Microsoft Access.
Rename Renames the specified object.
RepaintObject Completes any pending screen updates or pending recalculations of controls
on the specified object or on the active object if none is specified.
Requery Forces a requery of a specific control on the active database object.
Restore Restores a maximized or minimized window to its previous size.
RunApp Starts another program, such as Microsoft Excel or Word.
RunCode Runs a Visual Basic Function procedure.
RunCommand Runs a command from Microsoft Access’s menus—for example, File →
Save.
RunMacro Runs a macro.
RunSQL Runs the specified SQL statement for an action query.
Save Saves the specified object or the active object if none is specified.
SelectObject Selects a specified database object. You can then run an action that applies
to that object.
SendKeys Sends keystrokes to Microsoft Access or another active application. These
keystrokes are processed as if you had typed them yourself on the keyboard.
SendObject Sends the specified database objects as an attachment in an e-mail.
SetMenuItem Sets the state of menu items (enabled or disabled, checked or unchecked)
on custom menus. Works only on custom menus created using menu bar
macros.
SetValue Sets the value for a control, field, or property on a form or report.
SetWarnings Turns all system messages on or off. This has the same effect as clicking OK
or Yes in each message box.
ShowAllRecords Removes any applied filter from the active table, query, or form.
ShowToolbar Shows or hides a built-in toolbar or a custom toolbar.
StopAllMacros Stops all currently running macros.
StopMacro Stops the currently running macro. Use to stop a macro when a certain
condition is met.
TransferDatabase Imports or exports data to or from the current database from or to another
database.
TransferSpreadsheet Imports data from a spreadsheet file into the current database or exports
data from the current database into a spreadsheet file.
TransferText Imports data from a text file into the current database or exports data from
the current database into a text file.
Lesson Summary
Creating and Running a Macro
• To Create a Macro: From the database window click the Macros icon in the Objects bar and click
New. Click the first blank Action box, click the Action list arrow and select the action you want
the macro to perform. Specify any required arguments for the action in the Action Arguments
area. Repeat for each additional action you want the macro to execute. Click the Save button
on the toolbar, give your new macro a name, and click OK.
• To Run a Macro: Click the Macros icon in the Objects bar and double-click the macro you want to
run.
Editing a Macro
• To Modify a Macro: In the Database window, click the Macros icon in the Objects bar, select the
macro you want to edit, and click Design.
Quiz
1. The fastest and easiest way to create a macro in Microsoft Access is with
the Macro Recorder. (True or False?)
3. Macros may contain more than one action to perform several steps in
sequence. (True or False?)
6. You can assign a macro to a button, so that when a user clicks the button
or control, a macro is activated. The procedure for doing this is:
A. (1) Open the form in Design View, (2) select the button and display its properties,
(3) click the Event tab and click the On Click box, (4) click the down arrow and
select the macro you want to assign to the button.
B. (1) Open the macro in Design View, (2) select the form and button you want to
assign the macro to from the Assign box, (3) click Event box, click the down arrow
and select On Click from the list.
C. (1) Open the form in Design View, (2) select the button, and (3) select the macro
from the Macro List on the toolbar.
D. Too lengthy and complicated to be described in a brief quiz question.
Homework
1. Open the Homework database.
2. Create a macro named “OpenReport” that opens the Insurance Claims by Date report
in Print Preview. Try running this macro.
3. Modify the OpenReport macro—add a conditional expression so that the
OpenReport action won’t execute if the Score field in the Test Answers form equals
an “F.”
Hint: Use the Expression Builder if you need help creating the conditional
expression.
4. Add another conditional action to the OpenReport macro—one that displays a
message box that says “Sorry, you failed!” if the Score field in the Test Answers
form equals an “F.”
5. Open the Test Answers form in Design View.
6. Add a command button to the form whose On Click event property runs the
OpenReport macro.
7. Save the Test Answers form, display it in Form View, and test the command button.
8. Close the Homework database.
Quiz Answers
1. False. Microsoft Excel and Word both have macro recorders you can use to create
macros, but with Microsoft Access, you create macros in the Macro Design window.
2. B. An action is the basic building block of a macro.
3. True. Macros can contain multiple actions to automate several steps in a sequence.
4. D. Double-clicking a macro group will run every named macro in the group, often
with disastrous results.
5. B. This was a trick question. Macro actions do have arguments; however, they can be
found in the Action Arguments panel—not in a column.
6. A. The correct procedure for assigning a macro to a button is:
(1) Open the form in Design View, (2) select the button and display its properties,
(3) click the Event tab and click the On Click box, (4) click the down arrow and
select the macro you want to assign to the button.
7. True. Conditions only effect the corresponding Action row in the macro. If you want
to evaluate the other actions, they must each have their own statement in the
Condition column.
One of the great benefits of working with Windows is that you can share information between
different programs. Nowhere is this truer than with Microsoft Access. This chapter explains
how you can use Access with other programs. You’ll learn how to import and export databases
in other file formats. You’ll also learn the difference between importing objects from another
database versus linking to objects in another database. And you’ll learn how to create a
Microsoft Excel worksheet based on an Access query, transfer an Access table to Microsoft
Word, or use Word with Access to create mail-merge letters.
324 Microsoft Access 2003
Figure 11-7
When you export an Access table, you save its information in a different format so that it can
be understood and opened by different programs. For example, you might export an Access
table to an Excel worksheet.
In this lesson you will learn how to export an Access table to a comma-delimited text file.
1. Make sure the Database window is displayed and click the Tables icon in
the Objects bar, if necessary.
You want to export the tblCustomers table to a comma-delimited text file so that it can
be opened by other programs.
2. Right-click the tblCustomers table and select Export from the shortcut
Other Ways to Export a menu.
Table:
A dialog box appears, and Access asks where you want to export the table. You need to
• Select the table and specify a file name and file format.
select File → Export
from the menu.
3. If necessary, browse to your Practice folder. Type Customers File Name
box. Click the Save as type list and select Text Files. Click the Export
button when you’re finished.
The Export Text Wizard dialog box appears, as shown in Figure 11-5. You must specify
how the information is stored in the text file. There are two options:
Other Ways to Import a Not only does the Import command insert information from other file formats, it also lets you
Database Object:
import objects from other Microsoft Access databases. You can import tables, forms, reports,
• Right-click any empty pages, queries, macros, and VBA modules from one Access database into another Access
area of the Database database. Inserting objects from another Access database saves you lots of time: Instead of
window and select creating a new object (such as a form) from scratch, you can import an object from another
Import from the database and then modify it as needed.
shortcut menu.
In this lesson you will learn how to import an object from another Microsoft Access database.
Figure 11-9
Another way that you can access information in another database is by creating a linked table.
A linked table may sound a lot like an imported table, but there are some very important
differences between the two:
• Imported: When you import a table, you copy data from a table in one Access database
and place it in a new table in your database.
• Linked: When you link a table, the data stays in its original location. You can add,
delete, and edit records in a linked table from within Access, but you can’t change the A linked table
table’s structure. If the data in the original database changes, the changes will appear in
your database too.
Many databases often use a front-end database file, which contains the forms, reports, and
queries and is linked to a back-end database file, which contains the actual tables. Such
designs work great when you want several users on several front-end databases to be able to
access the same information in a single back-end database.
1. Select File → Get External Data → Link Tables from the menu. Quick Reference
The Link dialog box appears. Here you need to specify the database that contains the
table you want to link. To Link to a Table in
Another Database:
2. Browse to your Practice folder and double-click the Promotions
1. From the Database
database file.
window, select File →
The Link Tables dialog box appears, as shown in Figure 11-9. All you have to do here Get External Data →
is select the table(s) that you want to link to. Link Tables from the
3. Click the tblPromotions table and click OK. menu.
The dialog box closes and Access creates a link to the tblPromotions table. You can 2. Browse to the appropriate
identify linked tables by their arrow. Let’s try opening the linked table. drive and/or folder and
4. Click the Tables icon in the Objects bar, if necessary, and double-click double-click the database
the tblPromotions table. that contains the table
you wish to link to.
Access opens the tblPromotions table. Though you can view, add, edit, and delete the
records in the tblPromotions table, it remains in the Promotions database. 3. Click the table you wish to
link and click OK.
5. Close the tblPromotions table.
You can also create linked tables that access external information from such sources as dBase,
Paradox, FoxPro, and SQL databases.
Fig
The Office Links
button
Other Ways to Export an Access is capable of performing calculations on groups of records, but it can’t hold a candle
Object to Excel: to its Microsoft Office 2003 counterpart, Microsoft Excel, when it comes to number
crunching. An Excel spreadsheet is similar to an Access datasheet in many ways, with one
• Select Tools → Office
important difference. Not only can you enter information in an Excel spreadsheet, but you can
Links → Analyze It
also easily add formulas directly into the spreadsheet grid—something you can’t do in Access.
with Microsoft Excel It makes sense, then, that more people use Excel together with Access than any other
from the menu. program.
In this lesson you will learn how to create a Microsoft Excel spreadsheet based on an Access
query.
Quick Reference
1. Make sure that the Database window is displayed.
We will be using a query to create our Excel spreadsheet in this exercise, but you can
To Export Access Data to also create spreadsheets based on tables and reports.
Microsoft Excel: 2. Click the Queries icon in the Objects bar and select the qrySales
1. Open or select the table, query.
query, or report you want
Here’s how to export the selected database object to Microsoft Excel.
to export.
2. Click the Office Links
3. Click the Office Links button arrow on the toolbar and select Analyze
button arrow on the
It with Microsoft Office Excel from the list.
toolbar and select Microsoft Access sends the results of the qrySales query to Microsoft Excel, as shown
in Figure 11-10. We won’t spend much time working in Excel—this is a book about
Analyze It with Access—but let’s at least try adding a formula to the spreadsheet.
Microsoft Office Excel
from the list. 4. Scroll to the right if necessary, click in cell H2, type =G2*.9 and press
<Enter>.
Excel multiplies the value in cell G2 by 0.9 (90 percent) and displays the results.
5. Close Microsoft Excel without saving any changes.
Figure 11-11
The Office Links
button
If Microsoft Excel is the best tool for number crunching, Microsoft Word is definitely the best Other Ways to Export an
program to use for formatting and presenting large amounts of text. You can easily transfer Object to Word:
records from a table or query using simple copy and paste commands or by using the Publish • Select Tools → Office
It with Microsoft Word command, found under the Office Links button on the toolbar. When
Links → Publish It
records are transferred from Access to Word, they are formatted within the document as a
with Microsoft Office
Word table. This makes it easy to edit, sort, and format.
Word from the menu.
In this lesson you will learn how to transfer an Access table to a Microsoft Word document.
2. Click the Tables icon in the Objects bar and select the tblCustomers To Export Access Data to
table. Microsoft Word:
Here’s how to export the selected database object to Microsoft Word. 1. Open or select the table,
query, or report you want
3. Click the Office Links button arrow on the toolbar and select Publish to export.
It with Microsoft Office Word from the list.
2. Click the Office Links
Microsoft Access sends the tblCustomers table to Microsoft Word, as shown in Figure button arrow on the
11-11. The results usually aren’t pretty—but it’s easy to fix this problem with some toolbar and select
formatting and editing..
Publish It with
4. Close Microsoft Word without saving any changes. Microsoft Office Word
from the list.
Figure 11-13
Select and insert Go to first Go to last Find a
special information record record. Merge to record
fields Go to previous Go to next Check for the printer
record record errors
Ever wondered who at Publisher’s Clearing House Sweepstakes types your name on the
letters you receive on a weekly basis? Well, thanks to a process known as mail merge, creating
these “personalized” letters requires no more effort than a few keystrokes. Mail-merge letters
The Office Links are used to send the same or similar documents to many different people at once.
button
Other Ways to Merge an To perform a mail merge you need two files:
Object with Word: • A Main Document: a Microsoft Word document that contains the text that is the same
• Select Tools → Office in all of the merged documents (also known as boiler-plate text).
Links → Merge It with • A Data Source: which contains the records that you want to insert into the merged
Microsoft Word from documents. A Microsoft Access database makes a great data source.
the menu.
In this lesson you will learn to merge information from Access into Microsoft Word.
1. From the Database window, click the Tables icon in the Objects bar,
select the tblCompanies table, click the Office Links button arrow,
and select Merge It with Microsoft Word from the list.
The Microsoft Word Mail Merge Wizard appears and asks if you want to link the data
to an existing Microsoft Word document or create a new Word document and then link
the data to it. For this exercise you will use an existing Word document.
2. Click OK to link your data to an existing Word document.
The Wizard prompts you for the name and location of the existing Word document.
3. Browse to your Practice folder, then find and double-click the Cover
Letter document.
The Cover Letter document opens in Microsoft Word.
Now comes the most important part of the mail-merge process: You have to specify
where you want to insert the information from the data source (or Access database) into
your main document. You do this by inserting merge fields. Merge fields are where the Insert Merge
information from your data source gets inserted into the main document. Field button
4. Place the insertion point at the end of the date line and press <Enter>
twice.
This is where you will place your first merge field.
5. Click the Insert Merge Fields button on the Mail Merge toolbar and
select Name from the field list, click Insert, and click Close.
The Name field (from the Microsoft Access database) is inserted in the document. You
may have noticed chevrons surround the field («»). The chevrons differentiate the
merge fields from other text in the document.
6. Press <Enter>, click the Insert Merge Fields button, select Company
from the field list, click Insert, and click Close. Press <Enter>, click the
Insert Merge Fields button, select Address from the field list, click Merge to New
Document button
Insert, and click Close.
Move on to the next step and finish the address.
7. Press <Enter>, click the Insert Merge Fields button, select City from
the field list, click Insert, and click Close. Type a , (comma) and press
the <Spacebar>. Click the Insert Merge Fields button, select State
from the field list, click Insert, and click Close. Press the <Spacebar>,
click the Insert Merge Fields button again, select PostalCode from the
field list, click Insert, and click Close.
Getting the hang of it? If you’re feeling ambitious, feel free to replace every instance of
the word “PRODUCT” with a <<Product>> merge field, “NAME” with a <<Name>>
field, and “COMPANY” with a <<Company>> field.
You can merge the information in the data source with the main document in one of Quick Reference
four ways: To Mail Merge Records
• New Document: Merges the data source with the main document and places with Microsoft Word:
the results in a single, new document. Each record in the data source will appear 1. Open or select the table,
on a separate page. You can then save the new merged document. query, or report you want
• Printer: Merges the data source with the document and prints the results. to use for the mail merge.
• E-mail: Merges the data source with the document and e-mails the results. 2. Click the Office Links
button arrow on the
• Fax: Merges the data source with the document and faxes the results.
toolbar and select
For this lesson, we’ll merge to a new document.
Merge It with
8. Click the Merge to New Document button on the Mail Merge toolbar. Microsoft Word from the
Word merges the main document “Mail Merge Letter” and the data source “Mail list.
Merge Letter Data” into a new document called “Letters1.” The new merged document 3. Specify whether you wish
contains four letters—one letter for each record in the data source—that are separated to merge to an existing
with a page break. Word document or if you
9. Press <Page Down> several times to move to the next page of the want to create a new
document to view the second letter. Word document.
Notice that this letter uses data from the second record in the data source. 4. Perform the mail merge
10. Close Microsoft Word without saving any of your changes.
using Microsoft Word.
Congratulations, you’ve performed a mail merge—a task many people consider to be one of
the most difficult procedures in word processing.
Figure 11-14
Figure 11-15
In this lesson, you will learn about how to use hyperlinks in Microsoft Access. A hyperlink
can point to any file on your computer, on the network, or even on a Web page on the Internet.
Whenever you click on a hyperlink, you jump to the hyperlink’s destination (if it’s available).
A hyperlink is usually indicated by colored and underlined text. If you have ever been on the
World Wide Web, you’ve used hyperlinks all the time to move between different Web pages.
Microsoft recognized the importance of the Internet and thus introduced the new hyperlink
field type in Access 2003. You can use the hyperlink field to store clickable links to files on
your computer or network or to Web pages on the Internet.
In this lesson you will learn how to use hyperlink fields to create links that point to files on
your network or on the Internet.
Hyperlink
1. Open the tblTours table in Design View.
First we need to add a hyperlink field to this table.
2. Click in the first blank row and type Link. Click the Data Type arrow
and select Hyperlink from the list.
You’ve created a hyperlink field!
3. Save your changes and then click the View button on the toolbar to
display the table in Datasheet View.
Let’s try adding a hyperlink to the Western Canada record.
4. Click in the Link field for the Western Canada record and click the
Insert Hyperlink button on the toolbar.
Insert Hyperlink
The Insert Hyperlink dialog box appears, as shown in Figure 11-14. This is where you button
specify the name and location of the file or Web page you want to add as a hyperlink. If Other Ways to Insert a
you know the location and name of the file or Web address, you can type it directly in Hyperlink:
the dialog box; otherwise, you can use the Browse button to locate the file.
• Select Insert →
5. Click the Browse to File button next to the Look in list. Hyperlink from the
The Link to File dialog box appears and displays a list of files that you can use as the menu.
destination for your hyperlink.
6. Browse to your Practice folder, find and double-click the Canada Memo
document.
The Link to File dialog box closes, and the name and location of the Canada Memo is Quick Reference
added to the Address text box.
To Create a Hyperlink
7. Click OK. Field:
The dialog box closes and you return to the datasheet. Notice that the text “Canada 1. Display the table in
Memo.doc” appears blue and underlined, signifying that it’s a hyperlink. Let’s see how Design View.
our new hyperlink works.
2. Create a new field to
8. Click the Canada Memo.doc hyperlink. store the hyperlinks.
You immediately jump to the hyperlink’s destination—in this case, the Canada Memo 3. Click the new hyperlink
document. field’s Data Type box,
9. Close Microsoft Word without saving any changes. click the Data Type
You should be back in Microsoft Access, looking at the tblTours datasheet. list arrow, and select
Hyperlink.
Once you create a hyperlink, you can easily edit it to change its title or target, copy it,
or delete it by right-clicking the hyperlink. 4. Save the table.
10. Right-click the Canada Memo.doc hyperlink and select Hyperlink from To Insert a Hyperlink:
the shortcut menu. 1. Select the hyperlink field
A shortcut menu with the most frequently used hyperlink commands appears, as shown and click the Insert
in Figure 11-15. Here you could select Edit Hyperlink to change the hyperlink’s target Hyperlink button on the
or Display Text to edit the hyperlink’s title. Your hyperlink is fine the way it is, so close toolbar.
the shortcut menu. Or…
11. Click anywhere in the datasheet to close the shortcut menu. Close the Select the hyperlink field
tblTours table without saving any changes. and select Insert →
Hyperlink from the menu.
2. Either select a file you
want (use the Browse
button to help you locate
the file) or type a Web
address for the
hyperlink’s destination
and click OK.
To Edit a Hyperlink:
• Right-click the hyperlink
and select Hyperlink →
Edit Hyperlink from the
shortcut menu.
Figure 11-19
Perhaps the least understood of all fields, the OLE Object data type lets you store files created
in other programs such as graphics, Excel spreadsheets, or Word documents. This lesson will
give you some practice working with OLE object fields.
Lesson Summary
Importing Information
• To Import Information from Another File into Access: From the Database window, select File
→ Get External Data → Import from the menu. Select the type of file you want to import from the
Files of type list, browse to the appropriate drive and/or folder and double-click the file you want
to import. Follow the onscreen instructions of the Import Text Wizard to import the data.
Exporting Information
• To Export a Table to an External File: From the Database window, right-click the table and select
Export from the shortcut menu or select the table and select File → Export from the menu. Select
a format from the Save as type list and then, if necessary, type a new file name in the File name
text box. Click Export and follow the onscreen instructions of the Export Text Wizard to export the
data.
• To Insert a Hyperlink: Select the hyperlink field and then click the Insert Hyperlink button
on the toolbar or select Insert → Hyperlink from the menu. Either select a file you want (use the
Browse button to help you locate the file) or type a Web address for the hyperlink’s destination and
click OK.
• To Edit a Hyperlink: Right-click the hyperlink and select Hyperlink → Edit Hyperlink from the
shortcut menu.
Quiz
1. One of the most common and basic file formats used to import, export, and
exchange information between different programs is:
A. A JPEG file.
B. A GIF file.
C. A tab- or comma-delimited text file.
D. A Microsoft Exchange-It file.
2. When you export a Microsoft Access table to an external data file, Access
automatically includes the field names in the first row of the data file. (True
or False?)
3. Which of the following database objects can you import from one Microsoft
Access database to another? (Select all that apply.)
A. Tables.
B. Queries.
C. Forms.
D. Reports.
6. When you use the Publish It with Microsoft Word command to send
information to Microsoft Word, the data appears in:
A. A frightening dialog box that says “General Protection Fault.”
B. A comma-delimited text format.
C. A tab-delimited text format.
D. A table.
8. Microsoft Access can import information from which of the following file
formats?
A. Excel workbooks.
B. Comma-delimited text files.
C. dBase database files.
D. All of these.
9. You’re building a database for your mail-order bride company. You want
your table to include a field that stores the picture of your prospective
brides. What field type would you need to use?
A. Memo.
B. OLE Object.
C. Hyperlink.
D. Access can’t store graphics.
Homework
1. Open Microsoft Access, if necessary, and then open the Homework database.
2. Export the Insurance Claims table to a comma-delimited text file.
3. Create a link to the Employees table in the Lesson 1 database.
4. Create a Microsoft Excel spreadsheet based on the Science Test Answers table.
5. Transfer the Insurance Claims table to a Microsoft Word document. (If you’re really
inspired, change the document’s Page Orientation in Word to Landscape so that the
table fits on the page.)
6. Create a hyperlink in the Products table to the Maria.bmp file.
Hint: You must first add a hyperlink field to the table.
7. Exit Microsoft Word, Microsoft Excel, and Microsoft Access.
Quiz Answers
1. C. Tab- and comma-delimited text files are the most common and basic type of file
formats used to exchange information between different types of programs.
2. False. To include the field names, you must check the First Row Contains Field
Names box (for an imported file) or the Include Field Names on First Row box (for
an exported file) on the delimiter option screen of the Import/Export Text Wizard.
3. A, B, C, and D. Any of these Microsoft Access objects can be imported from one
Access database to another Access database.
4. False. When you link to a table, the data stays in its original location.
5. False. You can export information to Excel by saving it to an external file—but you
can also export it directly to Excel by clicking the Office Links list arrow and
selecting Analyze It with Microsoft Excel.
6. D. When you use the Publish It with Microsoft Word command, information sent to
Word appears in a table.
7. D. Hyperlinks can point to any of these items.
8. D. Access can import information from all of these file formats.
9. B. OLE Object fields can store objects created in other programs, such as pictures
and graphics.
Index
bold ......................................................286
A
bound object frame tool ...............223, 259
Access buttons
exiting ............................................... 57 adding to forms ................................244
Access 2000 macros, assign to..............................312
starting .............................................. 16
C
Access 97, converting from .................. 97
action queries ...................................... 183 calculated controls
append queries ................................ 206 forms................................................242
delete queries .................................. 204 queries, in.........................................186
make-table queries .......................... 208 reports, on ........................................272
update queries ................................. 210 caption property ...................................141
action reference, macros ..................... 318 center alignment...................................288
actions charts, adding to reports.......................277
arguments........................................ 306 check box tool..............................223, 259
conditional ...................................... 314 check spelling ........................................50
description of .................................. 306 chiseled, special effect format..............291
adding ClipArt, inserting .................................294
controls to a form............................ 239 close button............................................57
fields to a form................................ 224 color, changing.....................................290
pictures and graphics....................... 294 columnar
subforms to a form .......................... 246 forms..........................................87, 221
advanced filter......................................114 reports ..............................................257
aligning columns
controls ........................................... 297 adjusting width of ............................116
text .................................................. 288 freezing ............................................120
AND criteria ......................................... 84 hiding ...............................................121
append queries .............................183, 206 combo box tool ............................223, 259
arguments, actions............................... 306 command button tool ...................223, 259
ascending sort order ............................ 108 compact, database ..................................96
AutoForm Wizard ............................... 220 conditions
AutoFormat......................................... 289 macros, assigning to.........................314
AutoKeys macro ................................. 316 queries, using the IIF function .........190
AutoReport Wizard ............................. 256 Control Wizard ....................................244
avg function ........................................ 193 control wizard tool.......................223, 259
controls
B
adding to forms ................................239
between, criteria.................................. 182 aligning with one another ................297
blank moving .....................................226, 262
databases ........................................... 72 resizing.....................................226, 262
tables ................................................. 78 selecting multiple.............................238
title bar V
caption, changing ............................ 234
validation rule property........................152
description of .................................... 19
value lists
toggle button tool .........................223, 259
creating ............................................158
toolbars, using....................................... 22
modifying.........................................160
Toolbox ........................................222, 258
var function..........................................193
top and bottom values ......................... 194
totals W
crosstab queries, finding with ......... 202
what is this button..................................54
queries, finding with ....................... 192
reports, adding to ............................ 272 width, column ......................................116
windows, working with .........................30
U Word
exporting records to .........................331
unbound object frame tool ...........223, 259
mail merge, performing ...................332
underline ............................................. 286
undo ...................................................... 48 Z
union queries....................................... 183
unmatched records, finding................. 200 Zoom dialog box....................................56
update queries ..............................183, 210