Download Forms

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Microsoft Jet Database Engine wikipedia , lookup

Clusterpoint wikipedia , lookup

Relational model wikipedia , lookup

Database model wikipedia , lookup

Object-relational impedance mismatch wikipedia , lookup

Transcript
1
3500 Database Management Systems
Lab on System Development
Using MS Access (2007, 2010)
Updated March 2014
In this lab you will practice procedures for creating input/output forms, reports, and some other
tasks related to building a database system. You will be using MS Access (procedures should be
applicable to version 2007 and 2010). Assuming that a database is already in place, a large part of
building a DB system is related to developing input and output objects. This is the focus of the lab.
You will be working with tables from the PetStore database. If you already have a copy of it in your
private space, just start it. Otherwise, download it from Jerry Post’s Website into your storage.
Note: There might be some variation in some procedural steps as these instructions have evolved
through successive versions of MS Access.
1. CREATING FORMS
It is very easy to create a form with Access 2007 or 2010. Here is one quick procedure for creating
a form on a table in the PetStore system:
1. In the database window on the left edge of the screen, select Tables and then mark Animal
2. In the Main Menu at the top (Ribbon) click Create, and then Form
You are done! The DBMS will create a form on the Animal table in a default format. The form
immediately displays records from the Animal table. Scroll the records by using Page Up/Down
keys. Notice that the form is automatically named as Animal1, to avoid overwriting the existing
Animal Form. You can save your form under this default name (if you create another form on
Anima table, it will be defaulted into Animal2, etc.).
This form does not support navigation, but you can easily add such functionality. Do this:
1. In Main Menu (Ribbon), click Home, then View, then Design View. Your form now looks
different. Assume you want to add a navigation button in the form footer.
2. In the main Menu, focus on the Design tab and on the icons in it called Controls.
3. Find the control called Button and click it. You’ll know that the button function is active if
you place the cursor in the form area and it becomes a cross associated with a small image
of button.
4. Place the cursor in the form footer and draw a button in the size you wish.
1
2
5. A communication box called Command Button Wizard automatically pops up, displaying
functionality (methods) you can assign to your button. The option you need “Record
Navigation” is on the top in Categories and already is marked.
6. In Actions, choose Go To Next Record
7. In the next box, choose a graphical or textual description for the button. This is what the
user will see when running the form. Click Next.
8. In the next box, accept the default name for this button. This name is used by DBMS to
differentiate between the form objects. Click Finish.
To test your form, click View/Form View. Test your button.
If you want to have more freedom in designing the form, you can use this procedure:
1. Click the Forms tab in the database window.
2. In the main Menu at the top, click Create, and then Form Design. A grid like drawing space
for creating forms opens up.
3. In the Database Menu on the left edge, mark table Animal (if it isn’t already marked).
4. If the Design menu (tab), click Add Existing Fields. The Field List opens up on the right edge
of the screen, showing columns in table Animal and in the related tables.
5. You can add a column by column to your drawing space, by clicking a column name and
then dragging it into the drawing space, or by double clicking a column name.
Optionally, you can add multiple columns at a time (e.g., hold left Shift down and click fields
you want to add (this selects fields in sequence shown); then drag the selection into the
drawing space. You can also add multiple columns non-sequentially, by holding the Control
key down and then clicking desired column names; finish by dragging the selection where
you wish.
6. For adding buttons to your form, see the procedure for quick form creation above.
There are many controls available for designing forms. Figure 1 below describes some. Note that
end-users should never be able to directly access tables or queries. Instead, they should do it via
the forms interface, and the available controls suffice for any sort of access.
The procedure below produces a form for running a query, which could be very useful for your
Database System Project. This is actually another way of implementing the control Button. Do this:
1. Click the Forms tab in the database window.
2. In the main Menu at the top, click Create, and then choose Blank Form
3. In Ribbon, click Home/View/Design View.
4. In Design/Controls, click the button control.
2
3
5. Once you drop the button in the form, the box Command Button Wizard should appear.
Click the category Miscellaneous.
6. In Actions, choose Run Query, and click Next.
7. A list of queries pops up. Choose one and click Next.
8. On the next screen, choose the Text option and type in some meaningful label for the query
based on what it outputs. Animal Dates. Click Finish.
Test your form by switching back to the Form view. When you click on the button you created, you
should get an output of the chosen query. Check its SQL statement.
1.1 Editing Forms
Below is a layout of controls you can use on your forms. To get these controls, have a form open in
Design View, and look at the Design tab in the Ribbon. (The tab may look differently in Access
2007 and 2010, but the content should be comparable).
Figure 1: Design Controls
Here are some functions for editing forms in Design View.

Grid lines - By default, a series of lines and dots underlay the form in Design View so form
controls can be easily aligned. To deactivate/activate the grid, right-click anywhere in the
form space and select the appropriate option from the pop-up menu.

Tab order – This is one of useful functions for building user interface (more below).

Resizing and moving controls – You can resize controls or move by clicking and dragging
the handles on the edges and corners of the element with the mouse. Notice that cursor
takes on different forms in these actions.

Label/Text Box alignment – If you insert a column from a table, a label and a text box
will be created in the form. They are linked, so that moving one would move the other. You
can move each separately by clicking the large handle at the top-left corner of either one.
3
4

Page Header and Footer - Headers and footers added to a form will only appear when it is
printed. Access these sections by selecting right-clicking the form and selecting the
header/footer option.
1.2 Combo Boxes and List Boxes
A combo box (that is, drop-down list) and a list box can ease data entry by allowing the user to
enter data from a set of values that are stored in a table or outputted by a query (e.g., the names
of animals’ categories—bird, cat, dog, etc.—that are in the Category table). Here is a procedure for
creating combo boxes for entering animal categories and breeds.
1. Open in Design View the form for entering animal data (Animal1).
2. Delete the existing attribute Category.
3. In the Ribbon, select Design/Controls.
4. In Controls, click the combo box control and drop it into the form. The Combo Box Wizard dialog
box pops up.
4. In the Combo Box Wizard window, select the top option (“I want the combo box to look up the
values in a table or query”). Click Next.
5. On the next dialog box, choose the table Category as the data source, and click Next.
6. The make selections as the system prompts you: Category field, sort ascending, option “Insert
value in the field.
7. You can now finish your design job by adding the label Category next to the combo box.
To test if the form works, try to input a new record to the table Animal.
Results of your development may not be the best piece of user interface one can get. Some reformatting needs to be implemented. Try to use your knowledge of MS software to figure out how
to move items around, resize, and so on (it may work  ).
1.3 Option Buttons
Option buttons are useful for entering binary choices (yes/no, true/false) or some other limited
number of values (usually up to four). In addition, the values are stored as the number data type
(e.g., 1 and 0 to represent yes/no options), which further can be used for querying purposes.
Assume that you need to know which animals in the animals table were returned and re-introduced
in the inventory under a new ID. To satisfy this need, you could change a bit design of the table
Animal. You can add a column Returned in the table, assuming that it will have values 0 for “No”
(“False”) and 1 for “Yes” (“True”).
4
5
Do this:
1. Open table Animal in Design View.
2. Go to the last row and type Returned.
3. Select Number for the data type.
4. Save the updated design.
Now you can run the procedure for adding an option No/Yes (False/True) group to your form
Animal1:
1. In Ribbon, select Design/Controls and the Option Group control. The cursor changes into a cross.
2. Click in the form area. The Option Group Wizard dialog box should appear.
3. On the Option Group Wizard box, enter the word “No” in the first line. Then press Tab and enter
“Yes”. Click Next. (This step may be different in Access 2010.)
4. On the next dialog box, select the “No” to be the default value, and click Next. (In some other
cases, a Yes could be default, or there is no default value. Here, we assume that most animals are
not returned to the store, that is, are sold for the first time.)
5. On the next dialog box, enter numerical values for the options: 0 for “No” and 1 for “Yes”. Click
Next.
6. On the next dialog box, choose “Store the value in this field,” and in the combo box with field
names select “Returned”. Click Next.
7. On the next dialog box, select “Option Button” and click Next.
8. On the next dialog box, type Returned and click Finish.
Test your form by entering new rows and selecting the No and Yes values for the field Returned.
Check if the new data are really stored in the table Animal.
5
6
1.4 Creating Forms & Subforms
When a form or both form and subform already exist, you can link them in the form-subform
relationship. One method is based on the Subform Wizard, and the other on the drag-and-drop
technique.
With the following procedure, you will create a form-subform object by using a Supplier form as the
main form and an AnimalOrder form as the subform. To do this, first create simple forms on the
tables Supplier and AnimalOrder (see above). Then, the procedure is as follows:
1. Open the main form Supplier in Design View
2. In Ribbon/Design/Controls, click the Controls Wizard button
3. In Ribbon/Design/Controls, click the Subform/Subreport icon
in the toolbox
in the toolbox. The cursor
becomes a cross associated with a tiny Subform/Subreport symbol. Draw an outline of the
subform on the Supplier form (you can adjust its size later). The Subform Wizard dialog box
form appears.
4. Select “Use existing form” and choose the form AnimalOrder from the list available. Click
Next.
5. On the next dialog box, check “Choose from a list.” Click Next.
6. On the next screen, type in the name of your Animal Order subform that will appear on the
form’s layout or select the default choice displayed.
7. Save your form.
Test your form in the Form View. If all went well, you should have the upper part of your object
displaying an individual supplier, while the lower part displays animal purchase orders and some
item details.
Note: You can always get back to the Design View and improve your form. For example, adjust the
size of this space.
1.5 Designing Menus for User Interface
In principle, end-users should not be allowed to access tables directly but only via user interface,
which implies activation of forms, queries, and reports. Dialogue design should minimally include a
main menu and key sub-menus connected with the main menu. Navigation back and forth should
be supported to fit business needs.
In earlier than 2007 version of MS Access, the main menu was usually built as a switchboard.
These menus are still around in implemented MS Access systems. With later versions of MS Access,
Microsoft has pushed for its Tab approach to menu design.
6
7
Using tabs may be more optimal design for navigation than the switchboard approach. Different
tabs can be used for accessing and entering data, running queries and reports, etc. Tabs can be
named (which may do the job of listing main menu options in a switchboard), and they are readily
visible and accessible. Creating tabs is easier than implementing switchboards.
Creating tabs
Let us assume we wish to build tabs to represent the dialogue structure shown in Figure 2 below.
Here is an idea on how you can do it:
1. Create a blank form by clicking Create/Blank Form
2. On Design Menu, click the tab control and drop it into the form space
3. One tab can be for data entry, and the other for calling up reports
4. You can then insert buttons and other controls in each tab to manipulate forms, queries and
reports.
With tabs, you can design a dialogue such as one shown below.
Access 2010 also has a Navigation Form, accessible in Design Menu. You may want to explore it.
Creating Switchboard
If you decide to make use of switchboard for the menu structure, below are procedures you would
need to perform. Note that Access may not always respond to your expectations, probably because
the switchboard functionality is not advanced in newer versions of Access.
Switchboard is just another kind of form. The word “Switchboard” is reserved term for a default
switchboard, but you can create many switchboards with some modification in the name. They can
be linked to a default switchboard and among themselves to support user’s smooth navigation.
Before creating your first switchboard consider design of user interface in Figure 2 below, and note
that it can be supported either by linked forms or by switchboards.
7
8
Figure 2. Possible design of User Interface for Your Project’s System
The PetStore system already has two switchboards that do not use the reserved word
“Switchboard”. You will create the default switchboard, which will provide access to the data on
animals.
NOTE: Before starting the work, make sure that the security option is disabled!
While having PetStore open, run the procedure below for creating a switchboard. Note: Access
2010 may not have the Switchboard shown in tab Database Tools. If so, try this procedure to add
it:
1. Open your .accdb client database in Microsoft Access 2010
2. Select the File tab > Options > Customize Ribbon
3. In the right column, highlight "Database Tools"
4. Click "New Group". Click Rename to name the group "Switchboard"
5. In the "Choose commands from:" combo box at the top of the window, select 'All Commands'
6. Scroll down and highlight "Switchboard Manager"
7. Click Add to add the "Switchboard Manager" to the new group you created under the "Database Tools" tab
8. Click Ok to close the Access Options
9. You should now see the "Switchboard Manager" under the "Database Tools" tab
(Source: http://support.microsoft.com/kb/2484384 )
Procedure for creating Switchboard :
1. In the Ribbon, click Database Tools tab, and in the Database Tools group select Switchboard
Manager.
8
9
2. The Switchboard Manager dialog box should list the already existing Switchboard(s), if there is
one. Click the New button.
3. In the Create New dialog box, select the default name of the Switchboard (you can change the
name later). The Switchboard Manager dialog box should be active again and displaying the name
of your new switchboard.
4. Click your switchboard and then the Edit button.
5. In the dialog box entitled Edit Switchboard Page, click the New button to create a new item on
the switchboard.
6. The dialog box entitled Edit Switchboard Item should be on the screen. In the field Text, type
the name of the command that will appear in your switchboard; for example: List animals.
7. In the Command combo box, choose Open Form in Edit Mode
8. In the Form combo box, choose Animal, and click OK
9. You should have the Edit Switchboard Page dialog box again on the screen. Click the Close
button.
10. Optionally, if you see multiple switchboards listed in the Switchboard Manager dialog box, click
your switchboard
11. Click the button Make Default, and then Close.
Your switchboard should appear in the Navigation Pane entitled “Switchboard”. To test it, click it
and check if the button for opening the form Animal works. If not, check again if the security option
is enabled; if yes, disable it and try again.
You can use the procedure above – with appropriate changes in steps 6, 7 & 8 – to add more
buttons to your switchboard. If you want to create the structure shown in Figure 2, your default
switchboard may need to have just two buttons, each opening another switchboard (one for
working with data, another for getting reports).
To support usability, you want to have in each of these linked switchboards a button for opening
the default switchboard (see Figure 2). This will allow the user to always return to the default
switchboard (i.e., the main menu).
9
10
NOTE: Although your creation of the switchboards went well, you may not be able to see all of
them in the Navigation Pane. Clicking the Switchboard Manager should provide access to all your
switchboards.
2. DEVELOPING REPORTS
Designing reports has similarities with designing forms. On the differences side, reports are the
output from the system and so no controls for inputting data are used. Also, reports usually build
on queries and put more emphasis on formatting as they are supposed to be printed out into
permanent documents (e.g., standard performance reports, invoices and catalogs).
You can create reports in several ways. Basic reports can be created very simply and quickly, and
then embellished in the Layout and Design View of the report.
Similarly to the way you create forms directly from tables, you can create reports right from
queries.
Try this procedure:
1. In the Navigation Pane click (mark) any query, for example Query04-20 that may be on the
top, which gives a breakdown of animal sales per month
2. In the Ribbon, click Create/Reports/Report
You are done! Although the formatting may not be what is needed, it can be quickly improved. For
example, while in the Layout View, try these:

You can edit the title simply by clicking in the title text box and typing

You can resize the column width by clicking any column and then dragging its edge

You can run some calculations, like totals of the columns (click a column and right-click the
mouse; in the pop-up menu, select the option Total <column name>
Let’s make a more complex report that will utilize a crosstab query that you used in the last lab. If
you can’t access it, here is the procedure for creating it:
1. Copy and paste the statement below and name the resulting query as
QueryCategoryEmployeeValue:
SELECT Animal.Category, Employee.LastName, Sum(SaleAnimal.SalePrice) AS [Value Sold]
FROM Employee, Sale, SaleAnimal, Animal
WHERE Employee.EmployeeID=Sale.EmployeeID AND Sale.SaleID=SaleAnimal.SaleID AND
SaleAnimal.AnimalID=Animal.AnimalID
10
11
GROUP BY Animal.Category, Employee.LastName;
When you run the query it should output 43 rows.
2. Copy and paste the statement below, and name the resulting query as
QueryCategoryEmployeeValue_Crosstab:
TRANSFORM Sum(QueryCategoryEmployeeValue.[Value Sold]) AS [SumOfValue Sold]
SELECT QueryCategoryEmployeeValue.LastName, Sum(QueryCategoryEmployeeValue.[Value
Sold]) AS [Total Of Value Sold]
FROM QueryCategoryEmployeeValue
GROUP BY QueryCategoryEmployeeValue.LastName
PIVOT QueryCategoryEmployeeValue.Category;
When you run the query it should output 10 rows.
Then create a report by using the above described two-step procedure.
Apply necessary formatting (e.g., change the column width so all information fits on one page).
Additional powerful functions are easily accessible beyond those described above. For example,
assuming that your report is sorted on Employee Last Name, change the sorting to be based on
total:
1. Click the Total Value Sold column
2. In the pop-up menu, select the sort option
It’s a good idea to sum up the Total Value Sold column. You already know how to do this in the
Layout View (or check the bullets on the previous page). If you switch to design View, you may see
that the footer underneath this column contains the Sum aggregate function—the same one you
used in queries.
You should always entitle a report, using the Layout or Design View, type in the title box “Employee
Performance.” Then, increase the size of the title and boldface it. All these functions are easy to
access.
Finally, change the report style: Check Ribbon/Format/AutoFormat for available styles.
3. MACROS
A macro is usually a small file that contains calls to available functions (e.g., opening a form,
printing a report, etc.). Macros automate the use of a database system and may have a speed
advantage. The procedure below creates a macro that will enlarge the default switchboard when
the user clicks it.
11
12
You ca use this procedure to create a macro for maximizing the size of a switchboard (in case you
use it):
1. In the Ribbon, click Create
2. In the group Other, Database window, click the Macro
3. In the column Action, click the first field, which is a dropdown list. Select Maximize.
4. To save your macro, click the diskette icon that in the upper-left corner of the window (by the
Office button).
5. In the new dialog box, type the name as MacroMaximizeSwitchboard.
The next procedure assigns this macro to your switchboard:
1. Open your switchboard in Design View.
2. Place the cursor in the form and right-click the mouse; this pops up a menu for working with
forms. At the bottom of it, select Properties.
3. Look at combo box at the top called “Selection type”. Drop it down and select Form.
4. Select the Event tab.
5. Find the line “On Open” and click in it.
6. In the dialog form that opens up on the screen, click the first row, and in the list of choices
select RunMacro.
7. In the lower part of the dialog form, find the label “Macro Name.” Click it and find your macro
MacroMaximizeSwitchboard and click it.
6. Save the form.
The effect of the code you created with the above two procedures is such that when you start the
switchboard it will cover the entire screen.
12
13
4. SPLITTING DATABASE
Database systems today are split into a back-end (tables with business data) and front-end (all
other database objects, such forms, reports, and tables containing metadata). The back-end can be
put on a server so that other users can access it. Front-ends can be different (e.g., different queries
for different users).
The PetStore system does not differentiate between the back and front end. Still, these can be
designed. Below is the procedure for doing this. You should make a backup of your PetStore before
splitting it. In case something goes wrong you can get back to the original version.
To backup your PetStore,
1. Open PetStore
2. In Ribbon, select Database Tools/Administer/Replication Options/Create Replica and follow the
instructions on the screens
If all want well, you should get a backup of your database that contains the word "Replica" in its
name.
Once you have a backup created, you can split the original system into a back- and front-end with
this procedure.
1. Open PetStore
2. In Ribbon, select Database Tools/Move Data /Access Database. The Database Splitter Wizard starts.
3. In the next dialog form, you will see some instructions, a Split Database button, etc. Follow
instructions to complete the splitting.
Finally, your original system should be split so that the front-end keep its original name, while the
back-end has a suffix "_be". The back-end should contain tables only, while the front-end should
contain all other objects and tables that are marked with arrows, meaning that the tables are
physically in other databases (see the procedure on linking tables).
5. LINKING TABLES ACROSS DATABASES
Once you split a database into a back-end and front-end database, you need to link the two
databases. This is referred to as linking tables (looking from the front-end perspective). Here is a
procedure for linking tables:
13
14
1. Open front-end database
2. In Ribbon, select External Data/Access
3. Locate your back-end database with tables (use the Browse button) and click OK
4. Select the table(s) you want to link; alternatively, click Select All
If the linking went OK, you should be able to see the linked tables in your database window (having
an arrow next to their names). The linking leaves tables physically in another database, and it just
creates a pointer to the linked tables. Data can be changed either in original tables or in the linked
ones. Design changes can be made only in original tables.
END
14