Microsoft
Access 2003
Module 4
Copyright Notice Copyright 2003 EBook Publishing. All rights reserved. No part of this publication may be reproduced, transmitted, or translated into any language, in any form or by any means, electronically or mechanical, including photocopying, recording, storage in a database or retrieval system, or otherwise, without the prior written permission of EBook Publishing. Disclaimer We take great care to ensure the accuracy of these materials; however, EBook Publishing makes no warranty, express or implies, including without limitation any warranty concerning the adequacy, accuracy or completeness of such information or material or the results to be obtained from using such information or material. EBook Publishing reserves the right to revise this publication and to make changes in its content at any time, without obligation to notify any person or entity of such revisions or changes.
Microsoft
Access 2003
HOW TO USE THIS MANUAL
Module 4
The CompleteVISUALTM step-by-step computer training manual is specially developed and organized based on the Instructional Design concepts, to ensure the effectiveness of the learning process. Most of the tasks in each chapter fit into a single page for easy reference. Most tasks are summarized to less than 10 key steps and accompanied by actual screen illustrations. Every step you go through is practical and relevant. All chapters are independent. No exercise files need to be installed prior to the training, so you can start training from the modules that best suit you or your trainees. However, the module sequence that we suggest is designed to optimize your computer learning process.
Section name. Each section groups related chapters to make sure you learn all the related features and skills in complete details.
Chapter name. Each chapter is an independent learning unit. No exercise files need to be installed prior to the training. This lets you start your training anywhere or anytime you like.
Chapter introduction.
Each chapter begins with a presentation and illustration to prepare you for the concepts you will learn.
Microsoft
Access 2003
HOW TO USE THIS MANUAL
Instructions Click File >> Save. Press <Shift>+<Tab> Type Photo from Kevin Jeff.
Module 4
You are asked to Click File to expand the file menu from the menu bar, then click the Save command from this menu. Hold down the Shift key while pressing the Tab key on the keyboard. Type the phrase Photo from Kevin Jeff.
Handy summary. Each task concludes with a summary that reinforces the key steps in the task. It also serves as a cue card for a specific task.
Microsoft
Access 2003
TABLE OF CONTENTS
Module 4
Microsoft
Access 2003
TABLE OF CONTENTS
Module 4
How To Create A Report From Scratch ............................................................................ 73 How To Insert Header And Footer Sections ..................................................................... 74 How To Insert Group Header And Footer Sections .......................................................... 75 How To Insert Controls And Labels Into Sections ............................................................ 76 How To Customize The Format Of A Control ................................................................... 77 How To Change The Properties Of A Group .................................................................... 78 How To Change The Properties Of A Section .................................................................. 79 How To Insert Analytical Values Into Sections ................................................................. 80 How To Insert Page Numbers........................................................................................... 81 Creating A Chart Report ......................................................................................................... 82 How To Create A Chart Report Using The Wizard ........................................................... 83 How To Select The Chart Type And Layout ..................................................................... 84
2003 ComputerTrainingManual.com
Objectives:
When you have completed these lessons, you will be able to:
Create a form using the wizard Show/hide field lists and the toolbox Customize form designs Insert and delete controls Change controls and form properties Add multiple control types Make a form header/footer visible Create a form from scratch Create a form header and footer Apply special effects Change the background image of a form Add a bound text box control Add an unbound text box control Create a formula in a control Create calculated controls Add an option group Add a combo box Add a list box Add a useful command button Create a main form and subform Integrate the main and subform Hide information in a subform Resize the subform
2003 ComputerTrainingManual.com
Microsoft
Access 2003
CREATING ADVANCED FORMS
Creating And Customizing Effective Forms
Module 4
A form is an interface to let you view information from tables or queries. You also use forms to enter data into tables. Forms make your database easy to use and view. You can arrange all the information in a record to be displayed on a single screen, whereas you have to scroll the screen if you read directly from the table datasheet. You are able to design your form to the way you like so you can view the data quickly and effectively. A form displays OLE object fields like photos but this data is not visible in the table datasheet view. Forms enable you to retrieve data from multiple tables or queries. You can also enter data into multiple tables. Your database users no longer need to search for the tables to view or enter the information.
Form View. Displaying records in the form make your database easier to use and view.
2003 ComputerTrainingManual.com
Microsoft
Access 2003
CREATING ADVANCED FORMS
Module 4
All the information on a form or report is contained in controls. On data access pages, information is contained in controls in the same way as it is on forms and reports. However, information can also be typed directly on the data access page. You are able to change the design of the form. You can delete the existing controls, add more controls, move or resize the controls. In order to customize or change the form design, you have to open the form in design view.
Form Design View Shows you the layout of the form so you can customize it.
Toolbox
Shows tools to design your form.
Control
Object that contains data or runs actions. E.g. Field is known as control on form.
2003 ComputerTrainingManual.com
Microsoft
Access 2003
CREATING ADVANCED FORMS
Module 4
Create a new database. Then, import all the tables from the Northwind.mdb database. Depending on your setup, the Northwind database should be in the C:\Programs Files\Microsoft Office\Office11\Samples folder.
2003 ComputerTrainingManual.com
10
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Create A Form Using The Form Wizard
Module 4
1.
From the Object Bar, click the Forms button. Doubleclick Create form by using wizard.
The Form Wizard dialog box appears.
SUMMARY
1. From the Object Bar, click the Forms button. 2. Double-click Create form by using wizard. 3. In the Table/Queries box, select the table you want to use. 4. Click to set all the fields for the form. 5. Click the Next button and select form layout. 6. Click the Next button and select the form style. 7. Click the Next button and type in the form name. 8. Click the Finish button.
2.
3. 4.
Click
All the fields are sent into the Selected Fields box.
2003 ComputerTrainingManual.com
11
Microsoft
Access 2003
CREATING ADVANCED FORMS
5. 6.
Click the Columnar option button.
Module 4
You can choose other layouts and see the layout preview on the left.
7.
Click the Next button. Type All Employees as the form name.
The default name is the table name: Employees.
8.
Select the Open the form to view or enter information option. Then, click the Finish button. The All Employees form is displayed.
2003 ComputerTrainingManual.com
12
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To View A Form Design
Module 4
1.
2.
SUMMARY
Click the
Design button.
The design of the form is displayed as shown below. 1. Select the form from the Database Window. 2. Click the Design button. 3. Click the Field List button to display the Field List. 4. Click the Toolbox button to display the Toolbox. .
TIPS
If the form is already open in form view, click the Design view button on the Database toolbar to switch to Design View.
3.
Click the
This is a toggle button. Clicking the button again will hide the Field List.
4.
Click the
This is a toggle button. Clicking the button again will hide the Toolbox.
2003 ComputerTrainingManual.com
13
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Resize A Form Control
Module 4
1.
Open the All Employees form in Design View. Click the Notes control.
Handles appear at the edges of the Notes control.
2.
SUMMARY
1. Open the form in Design View. 2. Click the control to select it. 3. Drag the resize handle. The mouse pointer changes to when it is positioned at the resize handle.
3.
2003 ComputerTrainingManual.com
14
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Reposition Controls And Labels
Module 4
1.
Open the All Employees form in Design View. Click the Reports To control.
Make sure you open All Employees form in Design View.
2.
SUMMARY
1. Open the form in Design View. 2. Click the control. 3. Position the mouse pointer over the border of the control. 4. Drag the control to the new location. 5. Release the mouse.
3.
4.
2003 ComputerTrainingManual.com
15
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Move A Control And A Label Separately
Module 4
1.
SUMMARY
1. Open the form in Design View. 2. Click the control. 3. Position the mouse on the upper left handle of the control. 4. Drag the handle. 5. Release the mouse.
2.
3.
1. 2.
Open the All Employees form in Design View. Click the Report To control.
You will delete the Report To control.
SUMMARY
3.
Press <Delete>.
The control is now deleted.
1. Open the form in Design View. 2. Click the control. 3. Press <Delete>.
2003 ComputerTrainingManual.com
16
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Add A Field Control
Module 4
4. 5.
Drag the Reports To field from the Field List to the form.
To drag multiple fields, select the fields using the <Ctrl> key before dragging them into the form.
SUMMARY
1. From the Field List box, drag the control onto the form. 2. Release the mouse.
6.
2003 ComputerTrainingManual.com
17
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Control The Cursor Using The Tab Order Feature
Module 4
The tab order determines the order in which you advance from one field to the next field when you press the <Tab> key. The initial tab order is set according to the order of the creation of the fields on the form, not the position of the fields (controls). If you have rearranged the controls, you should change the tab order so it reflects the order in which the fields appear.
1.
SUMMARY
Switch the positions of the LastName and FirstName controls in the Design view as shown below.
You can switch to form view and press the <Tab> key to observe the cursor movement in the `LastName and `FirstName controls.
1. Click View >> Tab Order. 2. Click the field row selector. 3. Drag and drop the rows to rearrange the tab order. 4. Click the OK button.
2.
3.
2003 ComputerTrainingManual.com
18
Microsoft
Access 2003
CREATING ADVANCED FORMS
4.
TIPS
Module 4
Drag and drop the LastName row below the FirstName row.
Make sure you drag the row selector. The new order is shown below.
You can also click the Auto Order button to automatically reset the order according to the position of the new fields that appear on the form.
5.
2003 ComputerTrainingManual.com
19
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Change the Control Properties
Module 4
1.
Open the All Employees form in Design view. Click the Properties button.
The properties dialog box appears as shown below.
SUMMARY
1. Click the Properties button. 2. Click the control which you want to view the properties of.
TIPS
2.
You can also doubleclick the control to open the related properties dialog box.
Description Determines the appearance of the control on the form. Determines data source, default value and validation rules. Sets actions by assigning macros or visual basic procedures to the control. Like determines controls name, whether tabbing into control is allowed, message on status bar etc. Displays all the properties of the control.
2003 ComputerTrainingManual.com
20
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Change The Properties Of A Form
Module 4
1.
Select the All Employees form from the Database Window. Click the Design button.
The All Employees form opens in Design View.
2.
SUMMARY
3.
1. Open the form in Design View. 2. Click the Design button. 3. Open the Properties dialog box. 4. In the Properties dialog box, click the object down-arrow and click Form. 5. Change the properties settings in the dialog box.
In the Properties dialog box, click the object downarrow and click Form.
The form properties appear in the Form dialog box.
4. 5.
2003 ComputerTrainingManual.com
21
Microsoft
Access 2003
CREATING ADVANCED FORMS
6.
Switch to the Form View.
Module 4
Note that the title of the form has changed and the forms appear continuously, as shown below
2003 ComputerTrainingManual.com
22
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Select Multiple Controls
Module 4
1.
Open the All Employees form in Design View. Click and drag the mouse pointer over the Country, HomePhone and Extension controls.
A thin outline appears while you drag the mouse. All controls falls within the outline are selected automatically. Important: Please drag from the blank area of the form, or else you may end up selecting only the object where you click.
SUMMARY
1. Open the form in Design view. 2. Click and drag the mouse pointer to draw an outline over the controls you want to select.
TIPS
You can also hold the <Shift> key and click the controls to select multiple controls. You can change the control properties simultaneously if you select multiple controls.
2.
3.
2003 ComputerTrainingManual.com
23
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Make The Form Header/Footer Visible
Module 4
1.
Open the All Employees form in Design View. Position the mouse pointer over the borderline below the Form Header bar.
The pointer changes to a double-headed arrow, as shown below.
SUMMARY
1. Open the form in Design View. 2. Drag the borderline below the Form Header bar down to set the height for the Form Header. 3. Type in text or create a control in the Form Header section.
2.
.
TIPS
You can also type in text into the Header section using the label tool or change the header section background color. Use the same technique for your Form Footer.
3.
Drag and Drop the EmployeeID control onto the Form Header area.
The EmployeeID appears on the form header.
4.
2003 ComputerTrainingManual.com
24
Microsoft
Access 2003
CREATING ADVANCED FORMS
Module 4
Label
Text Box
2003 ComputerTrainingManual.com
25
Microsoft
Access 2003
CREATING ADVANCED FORMS
Tools Option Group Description
Module 4
Used along with check boxes, option buttons, or toggle buttons to display a set of alternative values. For example, you can use an option group to specify whether an order is shipped by air, sea, or land. In a data access page, an option group can contain only option buttons. Used as a stand-alone control bound to a Yes/No field in a Microsoft Access database or a Bit column in a Microsoft Access project. The toggle button is an unbound control for accepting user input in a custom dialog box or in part of an option group. Used as a stand-alone control bound to a Yes/No field in a Microsoft Access database or a Bit column in a Microsoft Access project. The option button is an unbound control for accepting user input in a custom dialog box or in part of an option group. Used as a stand-alone control bound to a Yes/No field in a Microsoft Access database or a Bit column in a Microsoft Access project. The check box is an unbound control for accepting user input in a custom dialog box or in part of an option group. Combines the features of a list box and a text box. You can type in the text box or select an entry in the list box to add a value to an underlying field. Displays a scrollable list of values. When a form is open in Form view or when a data access page is open in Page view or Microsoft Internet Explorer, you can select from the list to enter a value into a new record or to change the value in an existing record. Used to perform actions, such as finding a record, printing a record, or applying a form filter. Used for displaying a static picture on a form or report. Because a static picture is not an OLE object, you can't edit the image inside Microsoft Access after you've added it to a form or report. Used to display an unbound OLE object, such as a Microsoft Excel spreadsheet, on a form or report. The object remains constant as you move from record to record. Used to display OLE objects, such as a series of pictures, on a form or report. This control is for objects stored in a field in the form's or report's underlying record source. A different object appears on the form or report as you move from record to record. Used to begin a new screen on a form, a new page on a printed form, or a new page of a report.
Toggle Button
Option Button
Check Box
Combo Box
List Box
Page Break
2003 ComputerTrainingManual.com
26
Microsoft
Access 2003
CREATING ADVANCED FORMS
Tools Tab Control Description
Module 4
Used to create a tabbed form with several pages (such as the employee form in Northwind) or tabbed dialog box (such as the Options dialog box on the Tools menu). You can copy or add other controls onto a tab control. Right-click on the Tab control in the design grid to modify the number of pages, the page order, the selected page's properties, and the selected tab control properties. Used to display data from more than one table on a form or report. Used on a form, report, or data access page to emphasize related or especially important information or to divide a form or page into different sections, for example. Used for graphic effects, such as grouping a set of related controls, or used for emphasizing important data on a form, report, or data access page. Displays other toolboxes and OLE objects.
Subform/Subreport Line
Rectangle
More Controls
2003 ComputerTrainingManual.com
27
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Create A Form From Scratch
Module 4
1.
From the Object bar, click Forms. Click the New button.
The New Form dialog box appears.
2.
SUMMARY
In the list box, click Design View. In the drop-down box, click the Employees table.
This specifies that the record source for the form comes from the Employees table.
1. Click the New form button. 2. In the New Form dialog box, click Design View. 3. Select the record source. 4. Click the OK button.
TIPS
If you have forgotten to select the record source. You can specify the source in Form Properties. (In the Data tab, specify the source in the record source box.)
3.
4.
.
2003 ComputerTrainingManual.com
28
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Create A Header And Footer
Module 4
1.
SUMMARY
1. Open the form in Design View. 2. Click View >> Form Header/Footer.
2.
2003 ComputerTrainingManual.com
29
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Insert A Label
Module 4
1.
Open the New Employee form in Design View. Click the Label button on the toolbox.
This enables you to place text or labels on your form.
2.
SUMMARY
1. Open the form in Design View. 2. Click the Label button on the toolbox. 3. Click where you want to place the text. 4. Type the text.
TIPS
If the toolbox is not visible, click the Toolbox button on the toolbar.
3.
4.
2003 ComputerTrainingManual.com
30
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Format Text Properties
Module 4
1.
Open the New Employee form in Design View. In the Form Header, click the Employee Form label.
The label is selected
SUMMARY
1. Open the form in Design View. 2. Select the object. 3. Click the Properties button on the toolbar. 4. Click the Format tab. 5. Change the properties settings.
2.
Click the
TIPS
You can double-click any object on the form to open its properties dialog box. If you want to enlarge the label object on the form, drag the resize handles around the object, or double-click any resize handle around the object to auto fit the object.
3.
Click the Format tab. Scroll down and change the Fore Color, Font Name and Font Size, as shown below.
The fore color is the text color, represented by a code. Click the fore color box, then click to select the color. Select blue to see the following color code.
4.
2003 ComputerTrainingManual.com
31
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Change The Background Color Of A Form
Module 4
1.
Open the New Employee form in Design View. Double-click the header background.
The Form Header properties dialog box appears.
SUMMARY
1. Open the form in Design View. 2. Double-click the header background. 3. Click the Format tab. 4. In the Back Color box, change the settings. 5. Click the OK button.
2.
Click the Format tab. In the Back Color box, click and then select yellow as the color for the background.
The Color palette dialog box appears for you to select the color.
3.
2003 ComputerTrainingManual.com
32
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Apply Special Effects
Module 4
1.
Open the New Employee form in Design View. In the Form Header, double-click the Employee Form label.
The Label properties dialog box appears.
2.
SUMMARY
Click the Format tab. Click the Special Effect dropdown arrow, and then select Raised.
The effect is applied to the selected label immediately.
1. Open the form in Design View. 2. Double-click the object. 3. Click the Format tab. 4. In the Special Effect box, select the option you want.
TIPS
There are six special effects in Access 2003. Flat Raised Sunken Etched Shadowed Chiseled.
Click
2003 ComputerTrainingManual.com
33
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Change The Background Image Of A Form
Module 4
1.
Open the New Employee form in Design View. Open the Form properties.
In the Form properties dialog box, click the drop-down arrow and select Form from the list, as shown below.
SUMMARY
1. Open the form in Design View. 2. Open the Form properties. 3. Click the Format tab. 4. In the Picture box, select the new image. 5. In the Picture Tiling box, click Yes.
2.
Click the Format tab. In the Picture box, locate the file Santa Fe Stucco.bmp. Click the Picture Tiling dropdown arrow, then select Yes.
The Santa Fe Stucco.bmp image is found in the Windows folder. You will tile the small image to fill the entire form background.
The form appears as below in form view. Delete the image from the Picture box to remove the background picture before you continue.
2003 ComputerTrainingManual.com
34
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Add A Text Box Field Control
Module 4
1.
Open the New Employee form in Design View. Drag the BirthDate field onto the form Detail section.
If you do not see the field list, click the Field list button on the toolbar.
SUMMARY
1. Open the form in Design View. 2. Drag the field from the filed list to the form design.
2.
2003 ComputerTrainingManual.com
35
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Add An Unbound Text Box Control
Module 4
1.
Open the New Employee form in Design View. Click Text Box button in the toolbox. the
Make sure the Text Box button is highlighted.
2.
SUMMARY
Move the mouse below the BirthDate control in the Detail section and click once.
The unbound text box is created as shown below. This control does not retrieve from or enter data to any table.
1. Open the form in Design View. 2. Click the Text Box button in the toolbox. 3. Click the position where you want to place the unbound text box.
TIPS
The label may vary from what you see on your screen. It is just a default name that you can change later.
3.
2003 ComputerTrainingManual.com
36
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Rename A Control And Its Label
Module 4
1.
Open the New Employee form in Design View. Double-click the Unbound text box control.
The Text Box properties dialog box appears.
SUMMARY
2.
1. Open the form in design view. 2. Open the properties dialog box for the control. 3. Click the All tab. 4. In the Name box, type the new name. 5. Double-click the label text. In the Caption box, type the new label text.
3.
4.
Double-click the label text. From the Properties dialog box, in the Caption box, type Current Date:.
This is to change the label for the text box.
5.
2003 ComputerTrainingManual.com
37
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Insert A Function Into A Control
Module 4
1.
Open the New Employees form in Design View. Click the CurrentDate control to select it.
Make sure you click the text box, not the label.
SUMMARY
2.
1. Open the form in Design View. 2. Click the control. 3. Type in the formula.
Open the CurrentDate control properties box; the formula automatically appears in the Control Source box.
TIPS
In the Format box, select the Short Date format, as shown below.
You can also create a formula for the control by typing the formula directly into the Control Source box.
3.
2003 ComputerTrainingManual.com
38
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Insert A Calculated Control
Module 4
1.
Open the New Employee form in Design View. Click Text Box button on the toolbox. the
Make sure the Text Box button is locked.
SUMMARY
1. Open the form in Design View. 2. Click the Text Box button on the toolbox. 3. Click the position you want to place the control. 4. Type in the formula. 5. Press <Enter>.
2.
3.
4.
Change the format and label for the control as shown below.
Tip: Format: Standard, Decimal Places: 0
2003 ComputerTrainingManual.com
39
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Insert An Option Group Control
Module 4
1.
Open the New Employees form in Design View. Click the Option Group button on the toolbox.
This enables you to create a control that provides options for users to select on your form.
2.
SUMMARY
Drag the Country field from the field list onto the form.
The Option Group Wizard dialog box appears.
1. Open the form in Design View. 2. Click the Option Group button on the toolbox. 3. Drag the field from the field list onto the form. 4. Type in the label names. 5. Click the Next button and select default value. 6. Click the Next button and change the option values. 7. Click the Next button and select the data destination. 8. Click the Next button and select the type and style of the option control. 9. Click the Next button, change the label and click the Finish button.
3.
TIPS
Make sure the Control Wizards button on the toolbox is highlighted; otherwise the option group tool will not lead you to the wizard steps shown in this task.
4.
Click the Next button. Click the No, I dont want a default option button.
Choose the default value from the list if you want the value to be set to the country field every time you create a new record using this form.
2003 ComputerTrainingManual.com
40
Microsoft
Access 2003
CREATING ADVANCED FORMS
5.
Click the Next button.
Module 4
The country names are represented by numbers, as shown below. Change the values if necessary.
6.
7.
2003 ComputerTrainingManual.com
41
Microsoft
Access 2003
CREATING ADVANCED FORMS
8.
Module 4
TIPS
You can reposition or format the option group elements in the form design view. You can also change the values by changing the radio button properties.
The option group appears in the Form Design View, as shown below.
2003 ComputerTrainingManual.com
42
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Insert A Combo Box Control
Module 4
1.
Open the New Employees form in Design View. Click the Combo Box button in the toolbox.
You will create a drop-down list box on your form. Make sure the Control Wizards button on the toolbox is highlighted.
2.
SUMMARY
Drag the Country field from the field list onto the form.
The Combo Box Wizard appears.
1. Open the form in Design View. 2. Click the Combo Box button on the toolbox. 3. Drag the field from the field list onto the form. 4. Select where to get the values from. 5. Follow the instructions in the combo Box Wizard and click the Next buttons to go through the process. 6. Click the Finish button.
3.
Click the I will type in the values that I want option button.
The first and the third options are self-explanatory.
TIPS
The wizard dialog boxes may vary when you select different options in the wizards.
4.
Click the Next button and type USA, UK and Canada as shown below.
Press the <Down-Arrow> key to move to the next row.
2003 ComputerTrainingManual.com
43
Microsoft
Access 2003
CREATING ADVANCED FORMS
5.
Click the Next button.
Module 4
Here is where you specify the location you want to store the value.
6.
7.
2003 ComputerTrainingManual.com
44
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Insert A List Box Control
Module 4
1.
Open the New Employees form in Design View. Click the List Box button in the toolbox.
You will create a list box on your form. Make sure the Control Wizards button on the toolbox is highlighted.
SUMMARY
2.
Drag the Country field from the field list onto the form.
The List Box Wizard appears.
1. Open the form in Design View. 2. Click the List Box button in the toolbox. 3. Drag the field from the field list onto the form. 4. Select where to get the values. 5. Follow the instructions in the List Box Wizard and click the Next buttons to proceed through the steps. 6. Click the Finish button.
3.
Click the I will type in the values that I want option button.
The first and the third options are self-explanatory.
TIPS
The wizard dialog boxes may vary when you select different options in the wizards.
4.
Click the Next button and type USA, UK and Canada as shown below.
Press the <Down-Arrow> key to move to the next row.
2003 ComputerTrainingManual.com
45
Microsoft
Access 2003
CREATING ADVANCED FORMS
5.
Click the Next button.
This is where you specify where you want to store the value.
Module 4
6.
7.
2003 ComputerTrainingManual.com
46
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Insert Command Button
Module 4
1.
Open the New Employees form in Design View. Click the Command Button in the toolbox.
You will create a command button on your form. Make sure the Control Wizards button in the toolbox is highlighted.
2.
SUMMARY
Click on the form where you want to place the command button.
The Command Button Wizard appears.
1. Open the form in Design View. 2. Click the Command Button in the toolbox. 3. Click where you want to place the command button. 4. Select the Categories and Actions for the button. 5. Click the Next button and select the buttons appearance. 6. Click the Next button and name the button. 7. Click the Finish button.
3.
4.
2003 ComputerTrainingManual.com
47
Microsoft
Access 2003
CREATING ADVANCED FORMS
5.
Click the Next button. In the text box, type LastRecord.
A meaningful name will help you to refer to the button later.
Module 4
6.
2003 ComputerTrainingManual.com
48
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Use Windows XP Themes
Module 4
1. 2.
Click the Forms/Reports tab. Select the Use Windows Themed Controls on Forms check box.
Access applies the selected Windows Theme to views, dialog boxes and controls.
SUMMARY
1. Click Tools >> Options. 2. Click the Forms/Reports tab. 3. Select the Use Windows Themed Controls on Forms check box. 4. Click the OK button.
3.
2003 ComputerTrainingManual.com
49
Microsoft
Access 2003
CREATING ADVANCED FORMS
Integrating The Main Form And Subforms
Module 4
When a form is inserted in another form, the primary form is called the main form, and the form within the form is called the subform. A form/subform combination is also called a hierarchical form, a master/detail form, or a parent/child form. Subforms are especially effective when you want to show data from tables or queries with a one-to-many relationship. For example, you could create a form with a subform to show data from the Orders table and the Order Details table. The data in the Orders table is the "one" side of the relationship. The data in the Order Details table is the "many" side of the relationship each order can have multiple order details. Form View
Orders Form (main form) The one side of the relationship.
Order Details Form (subform) The many side of the relationship. Contains multiple records.
Design View
2003 ComputerTrainingManual.com
50
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Create A Subform
Module 4
1.
2.
SUMMARY
Select all fields from the Table: Order Details as shown below.
1. Double-click Create form by using wizard in the database window. 2. Select fields from the tables to be shown in the subform. 3. Click Next and select the subform layout. 4. Continue to click the Next button until you reach the end of the wizard.
TIPS
3.
Normally the subform is displayed in the Datasheet Layout; however, you can also select other layouts.
4.
Click the Next button twice and click the Finish button. Then close the form.
The subform is now created. It is just an ordinary form before you integrate it into the main form.
2003 ComputerTrainingManual.com
51
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Create A Main Form
Module 4
1.
2.
SUMMARY
1. Double-click Create form by using wizard in the database window. 2. Select fields from the tables to be shown in the main form. 3. Click the Next button and select the main form layout. 4. Click the Next button and select the main form style. 5. Continue until the end of the wizard.
3.
Click the Next button and select the Columnar layout. Click the Next button and select the Industrial style.
You can select another layout or style if you want.
4.
2003 ComputerTrainingManual.com
52
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Integrate A Subform Into The Main Form
Module 4
1.
Open the Orders form (the main form) in Design View. Subform/Subreport button on the Click the toolbox.
You want to insert a subform into your main form.
2.
SUMMARY
1. Open form in Design View. 2. Click the Subform/Subreport button in the toolbox. 3. Click the position on the form where you want to place the subform. 4. Click the Use an existing form option button and select the subform you want. 5. Click the Next button to go through the remaining steps. 6. Click the Finish button.
3.
Click the Use an existing form option button and click the Order Details form from the list. Then click the Next button.
Select the first option if you have not created the subform.
TIPS
The integrated subform may not look perfect when you first integrate it to the main form. Most of the time you have to adjust and make modifications to the subform manually.
4.
2003 ComputerTrainingManual.com
53
Microsoft
Access 2003
CREATING ADVANCED FORMS
5.
Module 4
Click the Form View to see how it is displayed. You will notice that there are a few things in the subform that need to be improved. 1. The subform area is too small to display the entire subform details. 2. Confusing record navigation buttons, as there are two sets of record navigation buttons, one for the subform and one for the main form. 3. Redundant OrderID information in subform as the main form already shows the OrderID.
2003 ComputerTrainingManual.com
54
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Hide Record Navigation Buttons In A Subform
Module 4
1.
Open the Order Details form (the subform) in Design View. Show the Form properties dialog box.
You can also double-click the form selector button on the upper left corner of the form window to show the Form properties dialog box.
SUMMARY
1. Open the subform in Design View. 2. Show the form properties. 3. In the Navigation Buttons box, select No. 4. Click the Save button.
2.
3.
Click the Save button. Then, click the Datasheet button to see the effects.
The record navigator buttons are hidden.
2003 ComputerTrainingManual.com
55
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Hide Field Information In A Subform
Module 4
1.
SUMMARY
1. Open the subform in Datasheet View. 2. Right-click the column heading of the field you want to hide. 3. Click Hide Columns from the shortcut menu. 4. Click the Save button.
2.
TIPS
You can also use the datasheet view to change column width so that the subform columns fit in the main form.
3.
4.
2003 ComputerTrainingManual.com
56
Microsoft
Access 2003
CREATING ADVANCED FORMS
How To Change The Size Of A Subform
Module 4
1.
Open the Orders form (the main form) in Design View. Click the subform object.
Resize handles appear around the subform object.
2.
SUMMARY
Drag the resize handle circled below to the right to enlarge the width of the subform.
The pointer changes to a double-headed arrow when it is placed on the resize handle.
1. Open the main form in Design View. 2. Click the subform object. 3. Drag the resize handles to adjust the subform object size. 4. Click the Save button.
3.
Switch to the Form View to see if the subform shows all the details in full.
You may have to try adjusting the width a couple of times.
4.
2003 ComputerTrainingManual.com
57
Objectives:
When you have completed these lessons, you will be able to:
Create reports using the wizard Adjust labels and controls in sections Add calculated controls Format controls Create a report from scratch Create header and footer sections in a report Create group header and footer sections Add controls and labels into sections Change group properties Change section properties Add analytical values to sections Add page numbers Create a chart report Select the chart type and layout
2003 ComputerTrainingManual.com
58
Microsoft
Access 2003
CREATING ADVANCED REPORTS
Working With Report Sections
Module 4
A Report is one of the types of output of your database. Although you can print the records directly from a table, a query or a form, reports are used to produce a more flexible and professional hard copy output. You are able to control what should be displayed in the report header/footer, page header/footer, group header/footer and the details of the report.
Report Header Page Header Group Header
Detail
Page Footer
Report Footer
2003 ComputerTrainingManual.com
59
Microsoft
Access 2003
CREATING ADVANCED REPORTS
Sections Report Header Report Footer Description
Module 4
Labels/controls in this section appear only at the beginning of the report. (Top of the first page of the report). E.g. Title of the report. Labels/controls in this section appear only at the beginning of the report. (Right after the last record in the report). Normally this is used to summarize the report data. E.g. Grand Total of the Numeric Data. Labels/controls in this section appear at the top of each page of the report. E.g. Record Column Headings. Labels/controls in this section appear at the bottom of each page of the report. E.g. Page numbering. Used to display Labels/controls to indicate the group name at the beginning of each group of records. Used to display Labels/controls that summarize the group numeric data at the end of each group of records. E.g. Total for each group. Used to display the actual data for each individual record.
The following useful tool, found in the toolbox in the report Design View, allow for you to add controls into the sections and change the appearance of your reports.
Tools Select Objects Control Wizards Description To select a control, section, form, report, or data access page. Click this tool to unlock a toolbox button that you've locked down. Turns control wizards on or off. Use control wizards to help you create a control, such as a list box or command button. In a form, additional wizards are available for a combo box, option group, subreport, and subform. And in a data access page, you can use a wizard to create a drop-down list box or a Microsoft Office chart. To use wizards to create a control, the Control Wizards button must be pressed in. You cannot use any wizards in a stand-alone page, and you cannot use them when you point a page to a database other than the database currently open. A control that displays descriptive text, such as a title, a caption, or instructions on a form, report, or data access page. Labels on forms and reports can contain hyperlinks, but hyperlinks in a report won't work when viewed in Microsoft Access; hyperlinks will work when you output the report to Microsoft Word, Microsoft Excel, or to HTML format. Access automatically attaches labels to the controls you create. Used to display, enter, or edit data in the underlying record source of a form, report, or data access page, display the results of a calculation, or accept input from a user.
Label
Text Box
2003 ComputerTrainingManual.com
60
Microsoft
Access 2003
CREATING ADVANCED REPORTS
Tools Option Group Description
Module 4
Used along with check boxes, option buttons, or toggle buttons to display a set of alternative values. For example, you can use an option group to specify whether an order is shipped by air, sea, or land. In a data access page, an option group can contain only option buttons. Used as a stand-alone control bound to a Yes/No field in a Microsoft Access database or a Bit column in a Microsoft Access project. The toggle button is an unbound control for accepting user input in a custom dialog box or in part of an option group. Used as a stand-alone control bound to a Yes/No field in a Microsoft Access database or a Bit column in a Microsoft Access project. The option button is an unbound control for accepting user input in a custom dialog box or in part of an option group. Used as a stand-alone control bound to a Yes/No field in a Microsoft Access database or a Bit column in a Microsoft Access project. The check box is an unbound control for accepting user input in a custom dialog box or in part of an option group. Combines the features of a list box and a text box. You can type in the text box or select an entry in the list box to add a value to an underlying field. Displays a scrollable list of values. When a form is open in Form view or when a data access page is open in Page view or Microsoft Internet Explorer, you can select from the list to enter a value into a new record or to change the value in an existing record. Used to perform actions, such as finding a record, printing a record, or applying a form filter. Used for displaying a static picture on a form or report. Because a static picture is not an OLE object, you can't edit the image inside Microsoft Access after you've added it to a form or report. Used to display an unbound OLE object, such as a Microsoft Excel spreadsheet, on a form or report. The object remains constant as you move from record to record. Used to display OLE objects, such as a series of pictures, on a form or report. This control is for objects stored in a field in the form's or report's underlying record source. A different object appears on the form or report as you move from record to record. Used to begin a new screen on a form, a new page on a printed form, or a new page of a report.
Toggle Button
Option Button
Check Box
Combo Box
List Box
Page Break
2003 ComputerTrainingManual.com
61
Microsoft
Access 2003
CREATING ADVANCED REPORTS
Tools Tab Control Description
Module 4
Used to create a tabbed form with several pages (such as the employee form in Northwind) or tabbed dialog box (such as the Options dialog box on the Tools menu). You can copy or add other controls onto a tab control. Right-click on the Tab control in the design grid to modify the number of pages, the page order, the selected page's properties, and the selected tab control properties. Used to display data from more than one table on a form or report. Used on a form, report, or data access page to emphasize related or especially important information or to divide a form or page into different sections, for example. Used for graphic effects, such as grouping a set of related controls, or used for emphasizing important data on a form, report, or data access page. Displays other toolboxes and OLE objects.
Subform/Subreport Line
Rectangle
More Controls
2003 ComputerTrainingManual.com
62
Microsoft
Access 2003
CREATING ADVANCED REPORTS
Module 4
Open the previous Training2.mdb database or create a new database. If you create a new database, import all tables from the Northwind database. (Depending on your setup, the Northwind database should be found in C:\Programs Files\Microsoft Office\Office11\Samples folder).
1.
From the Object Bar, click Reports. Click the New button. Click the Report Wizard. Then select Order Details as the record source.
The New Report dialog box appears as shown below.
SUMMARY
1. Click . 2. Click Report Wizard and select the record source. 3. Click the OK button and select the fields to be included in the report. 4. Click the Next button and select the grouping levels. 5. Click the Next button and specify the sort order. 6. Click the Summary Options button and specify the summary options. 7. Click the OK button and specify the report layout. 8. Click the Next button and specify the style. 9. Click the Next button and type the report name. 10. Click the Finish button.
2.
button.
All the fields are selected; they will all be shown in the report.
2003 ComputerTrainingManual.com
63
Microsoft
Access 2003
CREATING ADVANCED REPORTS
3.
Click the Next button.
Module 4
You can specify how to group the records here. By default, the report is grouped by the OrderID and the details of the report are as shown below. If you want to create another grouping level, select the field name, then click the button.
4.
2003 ComputerTrainingManual.com
64
Microsoft
Access 2003
CREATING ADVANCED REPORTS
5.
Module 4
Click the Summary Options button. In the Quantity box, click the Sum check box.
This is where you specify the summary of the report that appears at the footer of the sections. There are four functions listed here. However, you can create your own function in the report design view.
6.
2003 ComputerTrainingManual.com
65
Microsoft
Access 2003
CREATING ADVANCED REPORTS
7.
Click the Next button.
This is where you select the style you want to use for your report.
Module 4
TIPS
8.
You normally have to make some minor adjustments to the appearance of the report after it is created. E.g. The OrderID may appear aligned with the Order ID heading as the ID is aligned to the right of the text box.
2003 ComputerTrainingManual.com
66
Microsoft
Access 2003
CREATING ADVANCED REPORTS
How To Reorganize Labels And Controls In Sections
Module 4
1.
Click the Design view button to switch the Order Details report to Design View.
The report design appears, as shown below.
SUMMARY
1. Open the report in Design View. 2. Adjust the labels and controls in the report sections. 3. Click the Print Preview button.
2.
Adjust the labels in the Page Header section, the OrderID control in the OrderID Header section, controls in the Details section and the OrderID Footer sections.
Resizing and moving the labels and control techniques in report view is similar the process in form design view. Refer to the Creating Advanced Forms section if you have difficulties resizing and moving the controls.
2003 ComputerTrainingManual.com
67
Microsoft
Access 2003
CREATING ADVANCED REPORTS
Module 4
3.
2003 ComputerTrainingManual.com
68
Microsoft
Access 2003
CREATING ADVANCED REPORTS
How To Insert A Calculated Control
Module 4
1.
SUMMARY
1. Open the report in Design View. 2. Click the Text Box tool. 3. Click the position where you want to place the control. 4. Type the formula.
2. 3.
Click the
If you do not see the toolbox, click the toolbox button on the toolbar.
4. 5.
Type =[UnitPrice]*[Quantity]*(1-[Discount]).
The formula is entered into the control.
Delete the existing label and use the Label tool to create a new label Total on the Page Header section.
The default label for the control is no longer needed in the Details section.
The new calculated control in the report appears as shown below if you switch to Print Preview.
2003 ComputerTrainingManual.com
69
Microsoft
Access 2003
CREATING ADVANCED REPORTS
How To Change The Format Of A Control
Module 4
1.
Open the Order Details form in Design View. Doubleclick the Total control.
The Text Box properties dialog box appears. The title of your text box dialog box may vary from the one shown here. Make sure the Format or All tab is selected.
SUMMARY
1. Open the report in Design View. 2. Double-click the control. 3. Click the Format tab. 4. In the Format box, select the format type.
2.
3.
2003 ComputerTrainingManual.com
70
Microsoft
Access 2003
CREATING ADVANCED REPORTS
Customizing Report Sections
Module 4
You can use sections to produce calculations, group data, summarize and produce an analysis of the data in your database. You can group data to better organize the data in your report. This helps you to organize related data for analysis. For example, you may want to group total sales by each sales person so that you can compare their performance. Here is an example of a report without grouping sections.
2003 ComputerTrainingManual.com
71
Microsoft
Access 2003
CREATING ADVANCED REPORTS
An example of a report with grouping sections.
Module 4
2003 ComputerTrainingManual.com
72
Microsoft
Access 2003
CREATING ADVANCED REPORTS
How To Create A Report From Scratch
Module 4
1.
From the Database Window, click Reports. Click the New button.
The New Report dialog box appears.
2.
SUMMARY
Click Design View and select the Orders table as the objects data source.
The report will get data from the Orders table.
1. Click the Reports button from the Database Window. 2. Click the New button. 3. In the New Report dialog box, select Design View and select the record source. 4. Click the OK button. 5. Save the report.
3.
4.
2003 ComputerTrainingManual.com
73
Microsoft
Access 2003
CREATING ADVANCED REPORTS
How To Insert Header And Footer Sections
Module 4
1.
Open the Orders report in Design View. From the menu, click View >> Report Header/Footer.
The Report Header and Report Footer sections are created, as shown below.
SUMMARY
1. Open the report in Design View. 2. Click View >> Report Header/Footer.
TIPS
You can use the same technique to remove the report header and footer sections.
2003 ComputerTrainingManual.com
74
Microsoft
Access 2003
CREATING ADVANCED REPORTS
How To Insert Group Header And Footer Sections
Module 4
1.
Open the Orders report in Design View. Click the Sorting and Grouping button on the toolbar.
The Sorting and Grouping dialog box appears.
2.
In the Field/Expression column, select ShipCountry as the first level of grouping. Under Group Properties, in the Group Header box, click Yes.
The ShipCountry header section is created in the report.
SUMMARY
1. Open the report in Design View. 2. Click the Sorting and Grouping button on the toolbar. 3. In the Field / Expression column, select the field to be grouped. 4. Under Group Properties, in the Group Header and/or Group Footer box, click the Yes option.
3.
TIPS
In the Field/Expression column, select OrderDate as the second level of grouping. Under Group Properties, in the Group Header and Group Footer boxes, click Yes.
The OrderDate header and footer sections are created in the report.
You can use the same technique to remove the group header and footer sections.
The group header and footer sections appear in the report as shown below.
2003 ComputerTrainingManual.com
75
Microsoft
Access 2003
CREATING ADVANCED REPORTS
How To Insert Controls And Labels Into Sections
Module 4
1.
Open the Orders report in Design View. Drag and drop the ShipCountry, OrderDate, OrderID and CustomerID fields from the Field List to the report design. Resize the controls as shown below.
The labels always accompany the controls when you drag the fields onto the report. Delete all the labels.
SUMMARY
1. Open the report in Design View. 2. Add labels to the report using the Label tool.
2. 3.
Set all the records to align to the left. You can hold the <Shift> key to select multiple controls.
TIPS
Click the following buttons on the toolbar if the Field List or the Toolbox is hidden. Shows Field List. Shows Toolbox.
Add labels to the report using the Label tool as below. Format for Report Header: Font Size 12pt, Bold, Red. Format for Page Header: Font Size 10pt, Bold, Blue.
The report design is displayed below.
4.
2003 ComputerTrainingManual.com
76
Microsoft
Access 2003
CREATING ADVANCED REPORTS
How To Customize The Format Of A Control
Module 4
1.
Open the Orders report in Design View. Double-click the OrderDate control.
The Text Box Properties dialog box appears.
SUMMARY
2.
1. Open the report in Design View. 2. Double-click the control. 3. In the Format box, specify the format.
TIPS
3.
4.
2003 ComputerTrainingManual.com
77
Microsoft
Access 2003
CREATING ADVANCED REPORTS
How To Change The Properties Of A Group
Module 4
1.
Open the Orders report in Design View. Click the Sorting and Grouping button.
The Sorting and Grouping properties dialog box appears.
2.
SUMMARY
Click the OrderDate grouping row. Under Group Properties, in the Group On box, click Year.
This is to set the section to group the records by year instead of by day.
1. Open the report in Design View. 2. Click the Sorting and Grouping button. 3. Click the grouping level row. 4. Under Group Properties, change the settings.
3.
Group Properties
Group Header Group Footer Group On Group Interval Keep Together
Description
To display the group header section. To display the group footer section. To group by value or range of values. Interval or no. of characters to group on. To keep parts of a group (the group header, detail and footer section) together on the same page.
2003 ComputerTrainingManual.com
78
Microsoft
Access 2003
CREATING ADVANCED REPORTS
How To Change The Properties Of A Section
Module 4
1.
Open the Orders report in Design View. Double-click the Page Header section divider line.
The Section Properties dialog box appears.
2.
SUMMARY
Click the Back Color box, click the select the Grey color.
The color code appears in the back color box.
button and
1. Open the report in Design View. 2. Double-click the section divider line. 3. In the Section Properties dialog box, change the properties.
3.
2003 ComputerTrainingManual.com
79
Microsoft
Access 2003
CREATING ADVANCED REPORTS
How To Insert Analytical Values Into Sections
Module 4
1.
Open the Orders report in Design View. In the OrderDate Footer section, create a text box. Type =Count([OrderID]) in the text box. Edit the label to Total number of orders:.
This is to calculate the total occurrences of the records for the group.
SUMMARY
1. Open the report in Design View. 2. In the group footer section, create a text box. 3. Type the formula for the text box. 4. Edit the label for the text box.
2.
TIPS
If you place the control at the report footer section, it will calculate the number of orders for the entire report and place it at the end of the report.
Description Calculate the total for the field. Find the maximum value for the field. Find the minimum value for the field. Calculate the average value for the field. Find the number of occurrences of the records.
Note: The first four functions are only for fields that contain values only.
2003 ComputerTrainingManual.com
80
Microsoft
Access 2003
CREATING ADVANCED REPORTS
How To Insert Page Numbers
Module 4
1.
Open the Orders report in Design View. In the Page Footer section, create a text box. Type =Page &[Page] in the text box. Delete the label.
Quotation marks are used to add a text string to the value in the control. &[Page] is the syntax to display the current page.
SUMMARY
1. Open the report in Design View. 2. In the Page Footer section, create a text box. 3. Type the page number formula. 4. Delete the label.
2.
2003 ComputerTrainingManual.com
81
Microsoft
Access 2003
CREATING ADVANCED REPORTS
Creating A Chart Report
You can produce a chart report easily with the chart wizard.
Module 4
Charts are visually appealing and make it easy for users to see comparisons, patterns, and trends in data. In Microsoft Access, you can create charts in a form, report, or data access page. In a form or report, you can use Microsoft Graph to create a chart linked to data from the available tables, queries, or other record sources. The charts can be global (including all data) or record-bound (reflecting data only from the current record, in which case the chart is updated as you move from record to record). Several chart types, including two-dimensional (2-D) and three-dimensional (3-D) types, are available for you to choose from. Formatting options include adding text and graphics to the charts, changing colors, and adding trendlines and error bars.
2003 ComputerTrainingManual.com
82
Microsoft
Access 2003
CREATING ADVANCED REPORTS
How To Create A Chart Report Using The Wizard
Module 4
1.
From the Object Bar, click the Reports button. Click New button. In the New Report dialog box, the click Chart Wizard and select Employees as the source.
The New Report dialog box appears, as shown below.
SUMMARY
1. Click the New button. 2. In the New Report dialog box, select Chart Wizard and the source. 3. Click the OK button. 4. Select the fields and then click the Next button. 5. Select the chart type and then click the Next button. 6. Drag the field button to the Data and Series box. 7. Click the Next button to change the chart title. 8. Click the Finish button.
2.
Click the OK button. Send both the EmployeeID and City fields to the Fields for Chart box.
Select the fields, and then click . Both fields are to be used in the chart.
2003 ComputerTrainingManual.com
83
Microsoft
Access 2003
CREATING ADVANCED REPORTS
How To Select The Chart Type And Layout
Module 4
3.
4.
Click the Next button. Drag the EmployeeID button to the Data box. Drag the City button to the Series box as shown below.
EmployeeID is changed to CountOfEmployeeID because it does not contain a value. Double-click a number or date field in the chart to change how the chart will summarize or group data.
2003 ComputerTrainingManual.com
84
Microsoft
Access 2003
CREATING ADVANCED REPORTS
5.
Module 4
Click the Next button to change the title of the chart. Then click the Finish button.
The pie chart is created and appears in print preview.
2003 ComputerTrainingManual.com
85
Objectives:
When you have completed these lessons, you will be able to:
Create macros Run macros Edit and rename macros Create a macro group Create a button to run macro Pick a record using macro Use a conditional macro Secure a database with Autoexec macro
2003 ComputerTrainingManual.com
86
Microsoft
Access 2003
AUTOMATING A DATABASE WITH MACROS
Working With Macros
Module 4
A macro is a single or series of actions that perform a particular task, like opening a form or printing a report. Macros help you to automate daily tasks such as printing a report when a user clicks a command button that activate the macro. You can organize macros in a macro group. If you have numerous macros, grouping related macros in groups can help you to manage your database more easily. In some cases, you may want to carry out an action or series of actions in a macro only if a particular condition is met. A Conditional expression is used to apply a predetermined condition to a macro. Action arguments vary for each action. They are additional information required by the macro actions. These arguments give Microsoft Access additional information on how to carry out the action.
Macro group contains macros that are separated by blank rows Conditional expression determines the execution of the actions A macro composed of a sequence of actions
Action Arguments let you specify additional information on how to carry out the action
2003 ComputerTrainingManual.com
87
Microsoft
Access 2003
AUTOMATING A DATABASE WITH MACROS
Module 4
To start this lesson, please create a new blank database and save it as Training4. Import the following objects from the Northwind.mdb database. Table: Products, Categories Query: Alphabetical List of Products Form: Products Report: Alphabetical List of Products
1.
From the Object Bar, click Macros. Click the New button.
The macro design window appears.
2.
SUMMARY
1. From the Object Bar, click Macros. Click the New button. 2. In the Action column, select the Action you want. 3. In the Comment column, type the comments. 4. Under Action Arguments, select the suitable action arguments.
In the Action column, click the drop-down arrow at the first row and select OpenReport. Under Action Arguments, in the Report Name box, select Alphabetical List of Products. In the View box, select Print Preview.
This action will open the Alphabetical List of Products report in Print Preview. The Comment column, which is optional, lets you add some remarks to the actions.
TIPS
Different Actions have different sets of Action Arguments. E.g. The OpenForm action has the following arguments:
3.
Click the Save button. In the Macro Name box, type OpenProductList as the macro name.
If you close the macro window without saving, Access will prompt you to save your macro.
4.
2003 ComputerTrainingManual.com
88
Microsoft
Access 2003
AUTOMATING A DATABASE WITH MACROS
How To Run A Macro
Module 4
1.
SUMMARY
1. From the Object Bar, click the Macros button. 2. Double-click the macro you want to run.
TIPS
You can also select the macro and then click the Run button in the Database Window to run the macro.
2.
3.
Click the
Close button.
2003 ComputerTrainingManual.com
89
Microsoft
Access 2003
AUTOMATING A DATABASE WITH MACROS
How To Edit And Rename A Macro
Module 4
1. 2.
SUMMARY
3.
1. From the Object Bar, click the Macros button. 2. Double-click the macro you want to open. 3. Click the Design button. 4. Edit the macro. 5. Close the macro. 6. Right-click the macro name in the database window. 7. Click Rename from the shortcut menu. 8. Type the new name. 9. Press <Enter>.
Under Action Arguments, in the View box, change Print Preview to Print.
The report is sent to the printer immediately when you run the macro.
TIPS
4. 5.
You can also rightclick the macro, and then click Design View from the shortcut menu to edit the macro.
In the Database Window, right-click the macro OpenProductList. Click Rename from the shortcut menu.
You will rename the macro.
6.
2003 ComputerTrainingManual.com
90
Microsoft
Access 2003
AUTOMATING A DATABASE WITH MACROS
How To Group Macros
Module 4
1. 2.
Click the
3.
1. Open the macro in Design View. 2. Click the Macro Name button. 3. In the Macro Name column, type the name of the macro. 4. Insert a blank row as the first row.
4.
Type in the second macro and select the actions as shown below.
You have to leave a blank row to separate the macros in the group. This macro is named Switchboard.DisplayProdut. This macro opens Products form, and then maximizes the form.
5.
Click the PrintProductList macro, then click the Insert Rows button.
A blank row is inserted above the first macro. Since this is a group macro, the first row needs to be blank so that when you double-click the Switchboard macro, it wont run any actions. To run the first macro, you must specify the full macro name, Switchboard.PrintProductList.
2003 ComputerTrainingManual.com
91
Microsoft
Access 2003
AUTOMATING A DATABASE WITH MACROS
How To Insert A Button To Run A Macro
Module 4
1.
Create a new empty form and save it as Switchboard. Add a label Product Switchboard, as shown below.
To create an empty form, do not select a record source. Double-click Create Form in Design View to create the empty form.
SUMMARY
1. Open the form in Design View. 2. Click the Command Button tool on the toolbox. 3. Click the location on the form where you want to create a command button. 4. In the Categories box, click the Miscellaneous category. In the Actions box, click the Run Macro action. 5. Click Next to select the Macro Name. 6. Click Next to select the button appearance. 7. Click the Finish button.
2.
Click the Command Button button on the toolbox. Click the location on the form where you want to create a command button.
In order to go through the Command Button wizard, the wizard button on the toolbox must be selected.
3.
In the Categories box, click the Miscellaneous category. In the Actions box, click the Run Macro action.
This command button will run a macro when clicked.
TIPS
You can still change and reassign another macro to the button after completing the wizard. Open the Command Button properties dialog box. In the On Click box, change the macro name.
2003 ComputerTrainingManual.com
92
Microsoft
Access 2003
AUTOMATING A DATABASE WITH MACROS
4.
Click the Next button. In the box, click the Switchboard.PrintProductList macro.
Module 4
Select the macro that will run when the command button is clicked.
5.
Click the Next button. Click the Text option button. In the box beside the Text option, type Print Product List.
You can also display a picture on the button if you want. Click the Picture option, and then click the Browse button to add the picture to the button.
6.
Click the Next button. Type PrintProductList as the button name. Click the Finish button.
The command button is created on the form. If you click the button in the form view, the report is sent for printing.
2003 ComputerTrainingManual.com
93
Microsoft
Access 2003
AUTOMATING A DATABASE WITH MACROS
How To Filter A Record Using A Macro
Module 4
1.
Create a text box on the Switchboard form. Type Enter Product ID: as the label and change the control name to ProductID.
Make sure the text box properties dialog box appears.
SUMMARY
1. Open the macro in the Design View. 2. Click the OpenForm action. 3. Under Action Arguments, in the Where Condition box, type the syntax.
2.
Create another command button Display Product Details and assign the Switchboard.DisplayProduct macro to the button.
Resize and move the button to the right of the ProductID text box. You are going to edit the Switchboard.DisplayProduct macro so that when the button is clicked, the Product Form will display the product details (the Product ID specified in the ProductID text box control).
TIPS
This macro does not work if the product ID is blank. If you click the Display Product Details button without specifying the Product ID, a blank form appears. The next task will show you how to prompt the user to enter the product ID.
3.
Click the Switchboard.DisplayProduct macro. In the Where Condition box for the OpenForm action, type
[ProductID]=[Forms]![Switchboard]![ProductID].
Remember to click the OpenForm action to see the action arguments. This syntax will display the record that has the ProductID equivalent to the ProductID found on the Switchboard form. Important: Part of the syntax is not shown in the illustration below. You can press <Shift>+<F2> to display a zoom window for the syntax.
2003 ComputerTrainingManual.com
94
Microsoft
Access 2003
AUTOMATING A DATABASE WITH MACROS
4.
Module 4
Save and close the macro. Open the Switchboard form. In the Product ID: text box, type 5.
The form appears as shown below.
5.
2003 ComputerTrainingManual.com
95
Microsoft
Access 2003
AUTOMATING A DATABASE WITH MACROS
How To Create A Conditional Macro
Module 4
1.
Open the Switchboard macro in Design View. Click the Conditions button on the toolbar.
The Condition column appears.
2.
SUMMARY
For the DisplayProduct macro, in the Condition column, type IsNull([ProductID]) and in the Action column, select the MsgBox action. Under Action arguments, in the Message box, type Please enter the product ID and in the Title box, type Product ID Error.
Use the insert rows button to insert a row above the OpenForm action. This macro will prompt a message box if the ProductID control is Null (empty).
1. Open the macro in Design View. 2. Click the Conditions button on the toolbar. 3. Type the expression in the Condition column. 4. Save the macro.
3.
Insert another row. In the Condition column, type.... In the Action column, select the StopMacro action.
` means the condition is as above. StopMacro is needed to stop the macro or else the next action (OpenForm) will still run after the massage box appears.
4.
Save and close the macro. Open the Switchboard form to test the macro.
This message box appears if you click Display Product Details button without specifying the Product ID.
2003 ComputerTrainingManual.com
96
Microsoft
Access 2003
AUTOMATING A DATABASE WITH MACROS
How To Secure A Database With An Autoexec Macro
Module 4
1. 2.
Create the actions to open the Switchboard form and then Maximize the form as shown below.
The Switchboard form will maximize automatically when the database is opened.
SUMMARY
1. Create a new macro. 2. Save the macro as Autoexec. 3. In the Action column, select the OpenForm action. 4. Under Action Arguments, in the Form Name box, specify the form you want to open. 5. Maximize the form.
3.
TIPS
Save and close the macro. Close the database. Open the database again.
The Switchboard appears automatically and fills the entire screen. Users do not see the Database Window and this helps to prevent users from manipulating the database objects.
If you want to skip the autoexec macro when you open the database, hold down the <Shift> key when you open the database.
2003 ComputerTrainingManual.com
97