Académique Documents
Professionnel Documents
Culture Documents
Access 2003
Advanced
Forms and
Switchboards
Introduction
This workbook has been prepared to help users who wish to create a user interface for a database in Access
2002 by customising Forms and creating Switchboards. It is aimed at those who are confident in creating
Forms in Access and who have an understanding of database design. An understanding of how Queries are
designed would also be helpful.
This guide can be used as a reference or tutorial document. To assist your learning, a series of practical tasks
are available in a separate document. You can download the training files used in this workbook from the IS
training web site at: www.ucl.ac.uk/is/training/documents
There is also a comprehensive range of online training in Access 2002 available via TheLearningZone at
www.ucl.ac.uk/elearning
Creating Expressions
When creating expressions, observe the following rules:
All expressions should start with an equals = sign.
Round brackets ( ) and mathematical operators Plus +, Minus -, Divide / and Multiply * can be used in
the usual way.
Control Names of Controls on the Form can also be added, enclosed in square brackets.
For example, is based on the Table tbl_Doctor and there is a Control called Salary on the Form, this Control
can be included as: [Salary]
Control Source
The Control Source Property displays the
Expression you created.
You can click on the Build Button to use the
Expression Builder to help you create an
expression.
Formatting
You can add appropriate formatting to your
Control using the Format and Decimal Places
Properties. For example, a calculated Control
based on the Salary field could have a Format Property of Currency and
Decimal Places Property of 2.
5. Click on the Tables, Queries, or Both button to display a list of Tables and/or
Queries:
11. In the final box, type in a name for your Combo Box and click
Finish.
Sort in
ascending order
by NurseName
4. Close the Query Builder window and click Yes when you are asked if you
want to save the changes.
4. Ensure the Toolbox is displayed and the Control Wizard is turned on.
5. Click on the Command Button button on the Toolbox.
6. Click on the Form where you
want to place the button.
The Command Button Wizard
is displayed on your screen
as shown left.
7. Select the relevant Category
from the options on the left.
8. Select the required Action
from the box on the right and
click Next. You may be
prompted for futher details, such as the name of the Object you wish to
open, depending on the Action chosen.
9. In the next dialog box, decide whether you want Text or a Picture on your
button.
10. If you selected Text, type in the text you want displayed on
your button in the box.
11. If you selected Picture, click on the Browse button and
locate the picture you want
Or
Select one of the Pictures listed in the dialog box. Click on a Picture to see a
sample of it on the left in the dialog box.
12. Click Next.
13. In the final box, type in a name for your Command Button.
14. Click Finish.
15. Switch to Form View to try out your new button.
4. Select Open the form and find specific data to display and click Next:
5. Select the appropriate Fields from the two Forms that are linked together
and click Next:
Property Function
Name Change the name of the button if appropriate
Caption Type the text you wish to appear on the button
Picture Click on the Build Button to the right of the Picture
Property and use the Picture Builder to choose from a list of
pictures Access provides or click on the Browse button to
select one of your own.
On Click Select a Macro from the drop-down list to run it when the
Command Button is clicked on in Form View. See Macros on
page 22 for details of how to create Macros.
Status Bar Text can be added or amended by clicking in the Status Bar Text Property in the Property Window
and typing in the required text.
Helpful Hint
This type of user instruction is not very useful for users who navigate a Form using the mouse!
Creating a Switchboard
1. From the Tools menu, point to Database Utilities and then click
Switchboard Manager.
2. If you don’t already have a
switchboard, Access asks if
you would like to create one.
Click Yes.
3. The Switchboard Manager
dialog box will appear, as
shown right, with one
Switchboard already created
and selected (the ‘Main
Switchboard’). Click Edit.
4. In the Edit Switchboard Page
dialog box you can change the
name of the Switchboard if you wish. Click New.
5. In the Edit Switchboard Item dialog box, type the text you wish to appear
next to the first switchboard button in the Text box (e.g. ‘Add a new doctor’)
6. Select an appropriate command from the Command drop-down list e.g. Open
Form In Add Mode.
See the table overleaf for more details of what Commands are available and
their uses.
7. In the third box, select the appropriate Object to run or open. Access will
display a list of available items depending on the Command you chose
previously.
8. Click OK.
Understanding Switchboards
The Switchboards that you create using the Switchboard Manager actually
consist of a Switchboard Table and Switchboard Form which together enable
you to view and use one or more Switchboards:
The Switchboard Table
When you create a switchboard with the Switchboard Manager, Access
automatically creates a Table called Switchboard Items. The Table is
automatically updated as you create new switchboards and switchboard items
and keeps a record of each of these, their names and what they do. You should
not edit this Table manually.
The Switchboard Form
Access also creates a Form called Switchboard. To view the Switchboard you
have created, open the Form from the Database Window.
Editing Switchboards
You can create new Switchboards or Switchboard Items, or edit existing ones, at any time by using the
Switchboard Manager.
To create a new Switchboard:
1. From the Tools menu, point to Database Utilites and then click
Switchboard Manager.
2. Click on New
3. For more details on using multiple Switchboards with a database see
Working with multiple Switchboards on page 20.
To edit or delete an existing Switchboard:
1. From the Tools menu, point to Database Utilites and then click
Switchboard Manager.
2. Click on the appropriate Switchboard and click Delete to remove the
Switchboard or Edit.
If you choose Edit you can then change the name of the Switchboard, add
an Item to it or edit an existing Item (see below).
To edit or delete an existing Switchboard Item:
1. Follow the steps above to view the Items on an existing Switchboard.
2. Click on the appropriate Item and click Delete to remove the Item or Edit
to make changes to it.
If you want to rearrange Items, click on the Item and then click Move Up or
Move Down.
Helpful Hint
If you make changes to Items on a Switchboard while the Switchboard Form is open and displaying that
Switchboard, you will not automatically see all the changes you have made. Close the Form and re-open it to
see the changes.
Helpful Hint:
If you make a mistake and want to override the Startup changes you have made, close the database and hold
down the Shift key while you re-open it.
Data Modes
There are three main data modes – Read Only, Add and Edit modes. For details of Add and Edit modes see
Understanding Switchboard Commands on page 17. Read Only Mode allows you to view all the records but not
to add any new ones or make any changes to the data. Because you cannot use a Switchboard Command open a
Form in Read Only mode, a Macro can be useful to achieve this. Having created the Macro (as above) you then
use the ‘Run Macro’ Command on the Switchboard Item and select the appropriate Macro from the list.
To do this:
1. Create a new Macro as described in Creating a Macro to open a Form on
page 22.
2. Add the following Actions to the Macro Grid, with the corresponding Action
Arguments in the lower pane. This will perform the actions as described in
the steps above. Details given in italics could be replaced with Form or
Control Names of your choice.
Action Arguments
SetValue Item: [Visible]
Expression: No
OpenForm Form: frm_patient
Data Mode: Add
SetValue Item: [Forms]![frm_patient]![StaffNumber]
Expression: [Forms]![frm_doctor]![StaffNumber]
Close Form: frm_doctor
GoToControl Control Name: [PatientName]
In this example, the Macro is run after you change the value in the NumberOfBeds Field Control and then
leave the Field (After Update). The 6 lines of the Macro given above will carry out the following Actions:
It checks if the value in NumberOfPatients is greater than the value in NumberOfBeds. If this is the case
(i.e. the Condition is met), a Message Box is displayed and then the Macro is stopped (using the StopMacro
Action).
If the Condition is not met, the Macro continues to run and checks if NumberOfPatients is equal to
NumberOfBeds.
If the Condition is met a different Message Box is displayed and the Macro is stopped.
Finally, if the Macro is still running (i.e. neither of the previous two Conditions were met), the Macro checks
if the value in NumberOfBeds is greater than the value in NumberOfPatients by two or less and displays
another message if the Condition is met. The last line stops the Macro.
Although the Form itself is Unbound i.e. has no Record Source, the Combo Box needs to display the data
from the appropriate Field(s). As with all Combo Boxes, the Primary Key Field should always be included as
well as any other Fields needed to make the data listed meaningful to the user. In this example, it should be
based on the WardNumber and WardName Fields from tbl_ward:
1. Create a Combo Box using the
Wizard as described in Creating a
Combo Box which Looks up
Values in a Table or Query on
page 4.
Use a meaningful instruction for the user as
a Label e.g. Select a Ward from the List
Rename the Combo Box to something
meaningful, for example ComboWard.
This can be done by typing a suitable Name
in the Name Property which is on the Other Tab of the Property Dialog Box.
2. Create a Command Button using the Wizard which will close the Form as
described in Command Button Wizard on page 10. Use the text Cancel on
the Button.
3. Name and save the Form with an appropriate name e.g. frm_Select_Ward.
4. Check that the Combo Box displays the appropriate data and that the
Cancel Button closes the Form.
The details for the Macro are given below. You can substitute the Form Name with your own:
Action Arguments Description
SetValue Item: [Visible] Hides the current Object (i.e.
Expression: No the Dialog Box)
OpenForm Form: frm_Nurse_by_Ward Open the Form to display the
Data Mode: Edit Nurses records
Close Form: frm_Select_Ward Closes the Dialog Box