Académique Documents
Professionnel Documents
Culture Documents
Intermediate Skills
(C) 2013, BJC HealthCare (St Louis, Missouri). All Rights Reserved.
TABLE OF CONTENTS
OBJECTIVES ................................................................................................................................................................................. 3
UNDERSTANDING RELATIONSHIPS ...................................................................................................................................... 4
WHAT IS A RELATIONSHIP? ............................................................................................................................................................. 4
CREATING RELATIONSHIPS .............................................................................................................................................................. 7
EDITING TABLE RELATIONSHIPS USING JOIN PROPERTIES .................................................................................................................... 11
EDITING RELATIONSHIPS USING REFERENTIAL INTEGRITY .................................................................................................................... 14
CONTROLLING DATA ENTRY .............................................................................................................................................. 16
THE IMPORTANCE OF FIELD PROPERTIES .......................................................................................................................................... 16
SETTING UP DEFAULT VALUES AND REQUIRED FIELDS ........................................................................................................................ 19
DEVELOPING INPUT MASKS .......................................................................................................................................................... 22
DEFINING VALIDATION RULES........................................................................................................................................................ 27
CONTROLLING DATA ENTRY: LOOKUPS............................................................................................................................................ 32
PROPERTY SHEETS....................................................................................................................................................................... 38
USING EXPRESSIONS IN OBJECTS ....................................................................................................................................... 39
WHAT IS AN EXPRESSION? ............................................................................................................................................................ 39
USING EXPRESSIONS IN QUERIES.................................................................................................................................................... 40
USING EXPRESSIONS IN FORMS...................................................................................................................................................... 43
USING EXPRESSIONS IN REPORTS ................................................................................................................................................... 45
OTHER TYPES OF QUERIES ................................................................................................................................................. 49
QUERY OPTIONS......................................................................................................................................................................... 49
UPDATE QUERIES........................................................................................................................................................................ 49
MAKE TABLE QUERIES ................................................................................................................................................................. 51
APPEND QUERIES........................................................................................................................................................................ 53
DELETE QUERIES......................................................................................................................................................................... 55
PARAMETER QUERIES .................................................................................................................................................................. 57
OBJECTIVES
Upon completion of this course, participants will:
UNDERSTANDING RELATIONSHIPS
WHAT IS A RELATIONSHIP?
Newcomers to the database world have a hard time seeing the difference between an Excel spreadsheet and a database
table. They see the table grid structure and recognize that databases allow you better organize and query the data in new
ways, but many dont notice the power of the relationship function that gives this software its true power.
Relationships allow you describe the connections between different database tables. These connections allow you to
perform powerful cross-table queries called Joins.
RELATIONSHIP TYPES
There are three types of relationships in Access. These are named according to the number of table rows that may
be involved in the relationship.
ONE-TO-ONE RELATIONSHIP
These relationships occur when each entry in the first table has one, and only one counterpart or match in the
second table. A One-to-One relationship is created if both the related fields are primary keys or have unique
indexes. An index helps find and sort records faster. One-to-One relationships are rare because most of the time a
more efficient way is to just store both fields in the same table.
An example of a One-to-One relationship can be found in our class file between the Employee Data and Employee
Salary. One record that includes the employee basic name and address info in the Employee Data table matches
one record that contains the employees salary info in the Employee Salary table. The information is stored in
separate tables for confidentiality reasons.
ONE-TO-MANY RELATIONSHIP
These relationships are the most common type of database relationship. They occur when each record in the first
table corresponds to one or more records in the second table. A One-to-Many relationship is created if only one
of the related fields is a primary key or has a unique index.
An example of a One-to-Many relationship can be found with our class file between the Patient List and the Visits
table. A patient name record found in the Patient List table can be matches several times with visit information on
the Visits table. This means that the one patient can visit many times!
MANY-TO-MANY RELATIONSHIP
These relationships occur when each record in the first table matches one or more records in the second table and
each record in the second table also matches one or more records in the first table. Access cannot resolve manyto-many relationships. The application will produce an error immediately, as it cannot determine in which order to
match the records.
An example of a Many-to-Many relationship can be found with our class file between the Patient and the Doctor
List tables. A patient can see several doctors in the Doctor table and a doctor can see multiple patients in the
Patient table. This means there is no easy way to join the two tables because there are too many matches for
Access to try to resolve.
One-to-Many
CREATING RELATIONSHIPS
It is best to create the relationships before beginning to add data to your tables. Consider drawing your relationships on
paper before trying to create the links in your database. When you create a relationship between two tables, Access will
determine what type of relationship exists between the tables.
3.
Instructions
1. Open the Access Intermediate Class database.
2. Double-click the Employee Payroll Query.
3. Click the Home tab.
4. Under the Views group, click Design View.
5.
6.
Comments
Note how many records return when the query is run.
Note that no link exists between the Employee Data
table and the Employee Salary table.
Your mouse will turn into a rectangle. Make sure your
mouse is positioned on the correct field before
releasing it.
Note the number of records is greatly reduced. Access
is no longer matching each record in the Employee
Data table with every record in the Employee Salary
table.
Closes the
Relationship
window.
Creates a printable
map of joined tables
within the database.
STEPS
NOTE!
Relationships are automatically saved as you click the Create button. If you are asked to save, you are saving
the layout (the position of the tables on the screen) and not the relationships you have created.
note
STEPS
Linking Two Tables at the Database Level (within the Relationships Window)
1.
2.
3.
4.
5.
6.
7.
Select the table(s) you want to join and click Add. (Use the Ctrl key to select more than one table.)
Click Close.
Arrange the tables within the Relationships window.
Drag the linking (common) field from one table to the same data type field in the other table.
Verify the information in the Edit Relationships dialog box.
Instructions
1. Click the Database Tools tab.
2. Under the Show/Hide group, click Relationships.
3. Under the Relationships group, click Show Table.
4.
5.
6.
7.
8.
Comments
Opens the Relationship window.
Allows you to choose which tables you
want to display in the window.
10
JOIN TYPES
There are three join types that Access supports. The primary table is determined by the way you create the links
(from left to right or from right to left).
EQUAL JOIN
An equal join, which is the default join type, will return only those records where there is a match
between both tables.
LEFT OUTER JOIN
A left outer join will return all records of the table designated to be the primary (or left) table, and
matching records, if any, from the linked table.
RIGHT OUTER JOIN
A right outer join will return all records of the table to be the primary (or right) table, and matching
records, if any, from the linked table.
Patients
Left Outer
Equal
Visits
Right Outer
JOIN PROPERTIES
You can control the output of your queries by changing the properties of the links between the tables. This is called
Join Properties. Most often, you will want to do this at the query level.
The default show only
matched fields.
You can right-click on the join line and choose Join Properties from the short-cut menu.
NOTE!
note
11
STEPS
3. Click OK.
4. Run the query.
Instructions
1. In the Navigation Pane, find the Tables category.
2. Open the Patient List table.
3. Close the table.
4. Open the Visits table.
5. Close the table.
6. In the Navigation Pane, find the Queries category.
7. Open the Patients and Visits query.
8. Switch to Design View.
9. Double-click on the join line between the Patient List
and Visits tables.
10. Select the Include All Records from Patient List and
only those records from Visits where the joined
fields are equal option.
11. Click OK.
Comments
There are 50 patient records.
There are 40 visit records.
Note that the join line now shows which table is the
one and which table is the many in the
relationship.
Note the number of records has increased as all
patients are now listed.
12
STEPS
STEPS
6. Click OK.
7. Close the Relationships window.
When you make a change in the Relationships window, the new setting will be applied
to all subsequent queries created that use those tables.
NOTE!
note
13
STEPS
1.
2.
3.
4.
Comments
Notice how many employees there are.
14
Instructions
11. Click the Enforce Referential Integrity checkbox.
12. Click OK.
13. Close the Relationships window.
14. Reopen the Employee Salary table.
15. Add a record using the same information in step 4.
16. Click elsewhere in the table to attempt to save the
record.
17. Click OK to close the error message.
Comments
STEPS
4. Activate the Enforce Referential Integrity checkbox. The Cascade options will become available.
5. Select the desired option.
6. Click OK.
7. Close the Relationships window.
15
STEPS
A Text field can store from 1 to 255 characters but a memo field can store up to 65,535 characters.
NOTE!
note
16
NOTE!
note
Instructions
1. Open the Gourmet Lunch for Data Properties
database.
2. Open the Employees table.
3. Switch to the Design View.
4. Select the State field.
5. In the Field Properties area, click in the Field Size
line.
6. Change the value to 2.
7.
8.
9.
10.
11.
17
Comments
Number
Field Size
Decimal info
allowed?
Disk space
in bytes
No
No
No
Single
Yes
Double
Yes
12
Decimal
Yes
16
Byte
Integer
Long Integer
Description
STEPS
3. From the Field Size drop down list, select the size based on the number of decimal places you need
stored.
18
Instructions
1. Open the Entrees table.
2. Click in the Cost field for the first record.
3. Change the price to 9.75
4. Move off the record.
5. Switch to the Design View.
6. Click in the Cost field.
7.
8.
9.
10.
11.
12.
Comments
The current price is $10.00
The price changes to $10.00.
The fields data type is Number. The Field Size is set
to Long Integer.
This setting will allow decimal info to be stored.
STEPS
4. Enter a value.
5. Save the table.
The default value for the field will display in the new record line at the bottom of the table.
NOTE!
note
19
Instructions
1. Open the Lunch Orders table.
2. Switch to the Design View.
3. Select the Order Date field.
4. In the Field Properties area, click in the Default Value
line.
5. Type =NOW()
6.
7.
Comments
STEPS
1.
2.
3.
4.
20
NOTE!
If there is an issue with the data, Access will present another message. At this point, you should cancel the
action, and go back and address the issues in your data.
note
Instructions
1. Open the Lunch Orders table.
2. Switch to the Design View.
3. Select the Main field.
4. In the Field Properties area, click in the Required line.
5. Select Yes from the drop-down list.
Adjust the following fields to be required as well:
Side
Sweet
Drink
7. Save the table.
8. Click Yes to test the changes to the data integrity
rules.
9. Switch to the Datasheet View.
10. Add a New Order but skip the Main field.
Comments
6.
21
Series of characters
00000\-9999;0;_
Each section is separated by a semi-colon (;).
Placeholder character
The first section is the series of characters that makes up the mask. Use F1 within the Input Mask
property to see a complete set of characters.
The second section is used to define whether literal characters (such as parentheses and hyphens) used
within the mask are stored with the value.
The third section is used to identify the placeholder character used to format the field for the data entry
user. The default character used is the underscore (_).
STEPS
22
6. Click Next.
7. Select a different placeholder character to display when the user clicks in the field, if desired.
8. Click Next.
9. Choose to store the literal characters in the mask (hyphens, etc.) in the field or to store the data only.
23
Make sure your field size is large enough to store any literal characters you choose to store with the data.
NOTE!
note
Instructions
1. Open the Employees table.
2. Switch to the Design View.
3. Click within the Phone field.
4. In the Field Properties area, click in the Input Mask
line.
5. Click the Build button.
6. Click the Phone Number mask.
7. Click in the Try It Line to see how the mask would
appear to data entry users.
8. Click Next.
9. Click Next to accept the underscore character as the
placeholder displayed to the users.
10. Click the With the symbols in the mask option.
11.
12.
13.
14.
NOTE!
Click Next.
Click Finish.
Save the table.
Click the Datasheet View.
Comments
Setting the InputMask property to the word "Password" creates a password-entry control. Any character typed
in the control is stored as the character but is displayed as an asterisk (*). You use the Password input mask to
prevent displaying the typed characters on the screen.
note
24
Character
Description
Digit (0 to 9, entry required, plus [+] and minus [-] signs not allowed)
9
#
Digit or space (entry not required, plus and minus signs not allowed)
Digit or space (entry not required; spaces are displayed as blanks while in Edit mode, but
blanks are removed when data is saved; plus and minus signs allowed)
&
.,:;-/
<
>
!
\
Input mask
Sample values
(000) 000-0000
(206) 555-0248
(999) 999-9999
(206) 555-0248
( ) 555-0248
(000) AAA-AAAA
(206) 555-TELE
#999
-20 or 2000
>L????L?000L0
GREENGR339M3
MAY R 452B7
25
>L0L 0L0
T2F 8M4
00000-9999
98115- or 98115-3007
>L<??????????????
Maria
SSN 000-00-0000
SSN 555-55-5555
>LL00000-0000
DB51392-0493
STEPS
4. Type the appropriate syntax for each section of the mask. Separate the sections with a semi-colon.
Instructions
1. In the Employee tables Datasheet view,
click within the first records E ID field.
2. Type 003456 in the E ID field.
3. Press Tab.
4. Click Undo to undo the ID change.
5. Switch to the Design View.
6. In the Field Properties area, click in the Input
Mask line.
7. Press F1.
8. Close the Help screen.
9. Type >LLL - 000000000;1;X in the Input Mask
line.
10. Save the table.
11. Switch to the Datasheet View.
12. Add a new record.
13. Type 00.
14. Type BJC.
15. Type BJC 009873457.
16. Press Tab to move to the next field.
17. Press Esc to cancel the record.
Comments
? : How could you change the mask to automatically include BJC without typing it?
26
STEPS
4. Type the rule you want use. (For example: >100 And <1000 or F OR M)
5. Save the table.
Instructions
1. Open the Employees table.
2. Switch to the Design View.
3. Select the Gender field.
4. Under the Field Properties, click within the
Validation Rule row.
5. Type F Or M
6. Switch to Datasheet View and save the
changes.
7. Click Yes to test the existing data.
Click Yes to continue to test and keep the
rule.
9. Click within the first records Gender field.
10. Type Female and press TAB.
Comments
Allows you to test to see if the existing data fits the new
rule.
8.
27
Expression Box
Folders
Definition of the
selected value
Categories
28
STEPS
Click to see a
list of built-in
functions
6. Click OK.
7. Save the table.
29
Instructions
1. Open the Lunch Orders table.
2.
3.
4.
8.
9.
10.
11.
12.
13.
14.
15.
16.
5.
6.
7.
Comments
You will create a validation rule that ensures that the
order date entered today or in the future.
30
STEPS
1.
2.
3.
4.
31
Comments
STEPS
5. Click Next.
6. Type the number of columns you want in your lookup list.
32
33
Instructions
1. Open the Employees table.
2. Switch to the Design View.
3. Add a new text field named HSO.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
Comments
34
STEPS
1.
2.
3.
4.
5. Click Next.
6. Select the appropriate table.
7. Click Next.
8. Add the appropriate fields from the Available Fields list to the Selected Fields list using the arrow
button.
9. Click Next.
35
10. Adjust the width of the column to display the data, if necessary.
11. Turn on or off the viewing of the key column, as desired.
Double-click on the column
border to auto-fit the column
to the data.
12.
13.
14.
15.
Click Next.
Enter a label for your column.
Click Finish.
Save the table.
STEPS
3. If no tables are displayed, click Show Table command and use the CTRL key to select the tables you
want to display.
4. Click OK.
5. Right-click on the table join you want to delete.
36
Instructions
1. Open the Lunch Orders table.
2. In the first record, click the Employee field.
3. Switch to Design View.
4. Click in the Employee field.
5. Change the data type to Lookup Wizard.
6. Accept the option to look up the values in a table or
query.
7. Click Next.
8. Select the Employees table.
9. Click Next.
10. Add the Employee Last Name field.
11. Click the Selection Arrow.
12. Add the Employee First Name field.
13. Click the Selection Arrow.
14. Sort by Employee Last Name.
15. Click Next.
16. Adjust how wide you want to display the column
and accept the default option to hide the key
column.
17. Click Next.
18. Select Employee Last Name.
19. Accept the Employee Last Name and click Finish.
20. Click Yes to save the table.
21. Switch to Datasheet View.
22. In the first record, click the Employee Name drop
down list.
23. Select an Employee.
24. Close the table.
25. Close the database.
37
Comments
Note the data is simply a number.
PROPERTY SHEETS
In Access, use properties to determine the characteristics of tables, queries, fields, forms, and reports. You can view
properties in a separate display called a Property Sheet.
STEPS
1.
2.
3.
4.
5.
6.
7. For Forms and Reports, within the Tools group, click Property Sheet.
TIME
SAVER
38
Existing field
New Field Name
COST W/TAX:[COST]*1.06
Operator
Example of an
expression located
in an unbound text
box.
Table and field names must be referred to exactly but case is not considered.
TIME
SAVER
39
Field names in formulas must be spelled correctly but are not case sensitive.
STEPS
1.
2.
3.
4.
5. Click in the Total line for the field you want to summarize.
6. Select a function from the drop-down list.
40
To get the best results with aggregate functions, use the fewest number of fields possible.
NOTE!
note
Instructions
1. Open the Gourmet Lunch for Expressions database.
2. Create a new query in Design View.
3. Add the Employees, Lunch Orders, and Entrees tables to
the query.
4. Add the Employee Last Name field from the Employees
table to the query.
5. Add the Main field from the Lunch Orders table to the
query.
6. Sort the Employee Last Name field in Ascending order.
7. Click the Totals button.
8. In the Total line for the Main field, choose Count from
the drop-down menu.
9. Run the query.
Comments
Q?: What is another way to get a count of how many orders per employee?
COST W/TAX:[COST]*1.06
Operator
41
STEPS
4.
5.
6.
7.
8.
9.
Comments
Note that there are many items that have quantities
ordered greater than one.
Be sure to spell the fields correctly and use the bracket
symbol not the brace.
Note that the Cost w/tax field has a general number format.
A short-cut menu will appear.
The Format property is found on the General tab.
Note that the Extended Price field has a general number
format.
42
STEPS
4. Click and drag on the form where you want the text box to appear.
5. Select the unbound object.
6. Click the Form Design Tools Design tab.
7. Under the Tools group, select the Property Sheet.
8. On the All tab, type a name for the object in the Name line.
9. In the Control Source line, type the expression or use the Build button to open the Expression Builder.
10. In the Format line, choose an appropriate format using the drop-down list.
43
TIME
SAVER
You can also right-click on an unbound object to access the Property Sheet.
ADJUSTING THE TEXT BOX AND LABEL BOX LOCATION AND SIZE
The text box and corresponding label box are both attached by default. You can adjust the individual box size by
using the selected boxs size handles. If you need to move both boxes to a new location, simply click and drag one
of the boxes and the other will also move. Use the larger black handle on either the label or text box to move
them individually.
The larger square
handle is to move the
label only
Instructions
1. Open the Gourmet CO Orders form.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
Type = [cost]*1.06.
Click in the Format line.
Select Currency from the drop-down list.
Close the Properties window.
Switch to the Form View.
Save the form.
Close the form.
Comments
Note that the form contains a subform with order
details.
44
Example of an
expression located in
a reports unbound
text box.
STEPS
4. Using the Text Box tool, add an unbound control to the report in the section in which you want the
5.
6.
7.
8.
expression to appear.
Right-click on the unbound object.
Choose Properties from the short-cut menu.
On the All tab, type a name for the object in the Name line.
In the Control Source line, type the expression or use the Build button to open the Expression Builder.
9. In the Format line, choose an appropriate format using the drop-down list.
10. Close the Properties window.
11. Update the label object with descriptive text.
12. View the report to test your expression.
TIME
SAVER
45
You can use the keyboard combination Shift + F2 to open a Zoom window. This window will allow you to
enlarge the font size, making it easier for you to create and edit the expression.
Instructions
1. Open the Orders by Dept report.
2. Switch to the Design View.
3. Click the Report Design Tools Design tab.
4. Under the Control group, click the Text Box tool.
5. Add the unbound control box to the Dept Footer
section below the Summary for text box.
6. Under the Tools group, click the Property Sheet.
7. Under the Property Sheets Data tab, click in the
Control Source line.
8. Press Shift + F2 on the keyboard.
9. Change the Font command button.
10. Change the font size to 12.
11. Click OK.
12. Type=Sum([Cost]*1.06.
13.
14.
15.
16.
17.
18.
Press ENTER.
Select the label and type Sum with Tax.
Press ENTER.
Click OK.
Click in the Format line.
Select Currency from the drop-down list.
Comments
Notice how the report is divided into sections.
46
CONCATENATING TEXT
The word concatenate means to combine. Concatenating text is handy when you need to display fields together
in a report such as a First and Last Name. Access uses the plus sign (+) as the concatenation symbol. All literal
characters, such as spaces and punctuation, must be enclosed in quotation marks.
Concatenation symbol
STEPS
1.
2.
3.
4.
5. Using the Text Box tool, add an unbound control to the report in the section in which you want the
6.
7.
8.
9.
expression to appear.
Right-click on the unbound object.
Choose Properties from the short-cut menu.
On the All tab, type a name for the object in the Name line.
In the Control Source line, type the expression or use the Build button to open the Expression Builder.
47
Instructions
1. Open the Orders by Dept report.
2. Switch to Design View.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
Comments
Note that the report opens in Print Preview.
You can right-click on the open report and choose
Design View.
48
Updates values
Pushes data to a
new table.
Pushes data to
an existing table.
UPDATE QUERIES
An Update query is used to make changes in the data of a table. An Update query might be used if fees are increased (or
reduced) by 5% across a group of services. Rather than calculate the new fee manually and revise the records, an Update
query can calculate the entire fields data within a table. In order to run an Update query, you must use the Run button on
the toolbar. No action takes place when you use the View button.
STEPS
1.
2.
3.
4.
5.
6.
7.
8. Select Update Query. An Update To line will be added to the query grid.
49
NOTE!
Saving an update query can be dangerous! The query will run when someone double-clicks on it, which will
cause the update to occur again.
note
Instructions
1. Open the Entrees table.
2. Close the table.
3. Create a new query in Design View.
4. Add the Entrees table to the query.
5. Add the SW and Cost fields.
6. In the Main criteria line, type *wrap.
7. Run the query.
8.
9.
10.
11.
12.
13.
14.
Comments
Notice the prices of the wraps.
50
STEPS
1.
2.
3.
4.
5.
6.
7.
10.
11.
12.
13.
If you want to the table to be stored in a new database, select the database.
Click OK.
Under the Results group, select Run.
Click Yes to confirm the action.
51
Instructions
1. Open the Employees table.
2. Close the table.
3. Create a new query in Design View.
4. Add the Employees table to the query.
5. Add all the fields individually to the query.
6. In the Inactive criteria line, type Yes.
7. Run the query.
8. Switch to the Design View.
9. Click the Query Tools Design tab.
10. Under the Query Type group, select Make Table
query.
11. Type Inactive Employees as the table name.
12. Under the Results group, click Run.
13. Click OK.
14. Click Yes.
15. Click Yes.
16. Close the query without saving.
17. Open the Inactive Employees table.
18. Close the table.
Comments
Note how many inactive employees display.
52
APPEND QUERIES
An Append query adds records to an existing table. You might receive a report on new patients from another department
and would like to add these patients automatically to the existing Patients table. You must first make sure that all of the
required data is present in the records you wish to append.
STEPS
1.
2.
3.
4.
5.
6.
7.
8.
9. Click the Table Name drop down list and select the table you want to append.
10. If you want to the table to be stored in another database, select the database.
11. Click OK.
12. Under the Results group, select Run.
53
Instructions
1. Open the Employees table.
2. Select two records and mark them Inactive.
3. Close the table.
4. Create a new query in Design View.
5. Add the Employee table to the query.
6. Add all the fields individually to the query.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
Comments
Click in the Yes/No checkbox.
To save time, select all the fields first and then drag and
drop them into the design grid.
Yes or True means checked.
Check the results.
The Append window will open.
54
DELETE QUERIES
When you need to remove a small amount of records from a database its safest to simply open the table or form that
displays the records and use the Delete command. But if you need to delete large amounts of data quickly, use a Delete
query. Delete queries remove all the data in each field, including the key value that makes a record unique.
If you wish to use the Delete query to remove records from multiple tables rather than just a single database table, you will
need to ensure that:
You have relationships defined between related tables in your Microsoft Access database
You have enforced the Referential Integrity for the relationships between your chosen tables.
You have opted to Cascade Delete Related Records for the relationship type
If you are using the Delete query to remove records from multiple tables that are related in a One-To-Many relationship
without having defined the option to Cascade Delete Related records, Microsoft Access will only delete the records from
one table at a time. If this is the case, you must delete the records from the many side of the relationship first (to ensure
against orphaning records), and then delete the records from the one side of the relationship.
Make sure that you have a backup of your database before you delete your data.
NOTE!
note
STEPS
1.
2.
3.
4.
5.
6.
7.
55
Instructions
1. Create a new query in Design View.
2. Add the Employees table to the query.
3. Add all the fields individually to the query.
4. In the Inactive Employee criteria line, type Yes.
5. Run the query.
6. Switch to the Design View.
7. Under the Query Tools Query Type tab, select the
Delete Query.
8. Click Yes.
9. Close the Query and dont save it.
Comments
56
PARAMETER QUERIES
Sometimes we need to use the same basic query on a monthly basis but one variable needs to be adjusted each time.
Instead of recreating a new query each time or changing the design of an existing one, you can build a Parameter query.
This useful query asks for your input to set criteria before the query actually runs.
Instead of typing a value or expression into the criteria cell in Design view like a normal query, you type your question in the
criteria cell and enclose it in square brackets ([ ]).
Adding brackets to the
value or expression
will set it as a
parameter message.
The text you type will appear as a prompt on a dialog box, so you might want it to be in the form of a question to the user.
In this example the user will be prompted to type the name of a department when they run the query. The text the user
types will be used as the criteria for that particular field. The dialog box looks like this
When the message
appears, type in your
criteria.
STEPS
57
1.
2.
3.
4.
5.
6.
7.
Ideally, the prompt you create for your query should make it clear what type of information the search
term should be, and what format it should be entered in. For example, to guarantee that people enter a
search for a date in the format we use in our database, we could write the following in the Criteria: row of
the Date field: [What date? (mm/dd/yy)] .
The simplest parameter query will give you an exact match criteria, meaning that the query will search for
the exact text you enter in the prompt. However, you can turn any type of criteria into variable criteria.
Simply type your prompt text in brackets in the part of the criteria where you would normally put a search
term.
For example, in a normal query, we could find orders that were placed between two dates by using the
criteria Between x AND y, and replacing the x and y with the first and second dates, respectively. To turn
this into a parameter criteria, we would simply replace the x and y with the text we want to appear in the
prompt. Our variable criteria might look like this: Between [Enter the start date:] AND [Enter the ending
date:]. These prompts would appear:
Instructions
1. Open the Orders by Date query.
2. Within the Order Date field criteria line, type [What
Date?]
3. Press Enter.
4. Switch to Datasheet View.
5. Type 5/15/2013 and click OK.
6. Switch to Design View.
7. Within the Order Date field criteria line, remove the
current parameter.
Replace with the following:
Between [Enter Start Date:] and [Enter End Date:]
8. Press Enter.
9. Switch to Datasheet View.
10. Enter a Start Date and click OK.
11. Enter an End Date and click OK.
Comments
58