Anda di halaman 1dari 8

Access 2013: In Practice (Chapters 5-7)

Integrated Access Project 4


For this project, you enhance the functionality of a database that tracks daily price information for a
collection of stocks. The starting database file is provided for you. You use Design view to create and
execute an update action query. Next you create a subquery to find the highest closing price of each
stock. You then create a third query that uses the subquery and edit the query join properties. You
create a form to collect query parameters and write the macros for the buttons on the form. You also
create an embedded user interface macro for a combo box on the form and test the functionality of the
macros. Finally, you complete a main form by adding a subform and a calculated field. You customize
the look and functionality of this form.
[Student Learning Outcomes: 5.3, 5.4, 5.5, 5.7, 6.1, 6.3, 6.8, 7.1, 7.2, 7.3, 7.4, 7.8]
Files Needed: StockTracking-04.accdb
Completed Project File Names: [your initials] Access Project 4.accdb

Skills Covered in this Project


Create an update action query.
Create a subquery in Design view.
Create a query that uses a subquery.
Change the join type of a relationship in a query.
Use a right outer join.
Create a form in Design view.
Add and edit a control in a form.
Change the border style property of a form.
Remove a scroll bar and record selector.
Change the enabled property of a control.
Create a form to capture parameters.
Use SQL in the row source property of a combo box control.
Use the Macro Builder.
Build macros for a parameter form button.
Modify a query to reference text boxes on a form.
Test a parameter form.
Build an embedded macro.
Add a subform to a main form.
Set the master and child link fields.
Use an aggregate function on a subform.
Add a control on a main form that refers to a control on a
subform.
Remove navigation buttons.

1. Open the StockTracking-04.accdb database file from your student data files and save it as [your
initials] Access Project 4.
2. If prompted, enable content in the database.
3. Create an update action query to modify data in the Stocks table. Someone has entered the wrong
sector name on some of the stocks.

Access 2013: In Practice

Integrated Access Project 4 (Chapters 5-7)

Page 1 of 8

4.
5.
6.

7.

a. Create a new query in Design view.


b. Add the Stocks table into the Query Design window and add the StockSymbol, StockName and
Sector fields into the query.
c. Enter Technology-All into the criteria box of the Sector field.
d. Run the query. Verify that it finds the 3 stocks in this sector.
e. Switch back to Design view and convert the query into an update query.
f. Enter Technology in the Update To box of the Sector field.
g. Run the query. An Access message box displays, informing you that You are about to update 3
row(s). Click Yes to execute the query.
h. Save the query as UpdateTechnologySectorStocks.
i. Close the query.
Open the Stocks table to verify that the sector field was updated correctly for those three
technology sector stocks.
Close the table.
Create a new summary query in Design view. You want to find the highest closing price for each
stock. This query will be used as a subquery in the next step.
a. Create a new query in Design view.
b. Add the HistoricalPrices table into the Query Design window and add the FKStockSymbol and
Close fields into the query.
c. Add the Total row to the query.
d. Group By the FKStockSymbol field and use the Max aggregate function on the Close field.
e. Save the query as MaxClosePriceByStock.
f. Run the query. 25 records should display, with AAPL appearing at the top of the list with a
MaxOfClose of $702.10.
g. Close the query.
Create a new query that uses a subquery. You want to display the date that each stock had its
highest closing price. Due to the way a summary query works, you could not include the date field
in the MaxClosePriceByStock query.
a. Create a new query in Design view.
b. Add the HistoricalPrices table and the MaxClosePriceByStock query into the Query Design
window. If necessary, increase the size of the HistoricalPrices table in the query window so that
all the fields are visible.
c. Add the FKStockSymbol and QuoteDate fields from the HistoricalPrices table and the
MaxOfClose field from the MaxClosePriceByStock table.
d. Save the query as DateEachStockHadMaxClosePrice.
e. Run the query. Note that 329,125 records display. This is because the HistoricalPrices table is
not yet joined correctly to the MaxClosePriceByStock query.
f. Switch back to Design view.
g. Drag the Close field from the HistoricalPrices table on top of the MaxOfClose field in the
MaxClosePriceByStock query.

Access 2013: In Practice

Integrated Access Project 4 (Chapters 5-7)

Page 2 of 8

h. Right-click the relationship line and select Join Properties to open the Join Properties dialog box
(Figure 1).

Figure 1 The Join Properties dialog box

i.
j.

Select the third radio button and click OK.


Run the query. Note that 38 records display. Since there are only 25 stocks, this is still not
correct. This occurs because the same close price appears for different stocks, even though it
may not be the highest close for each of those stocks.
k. Switch back to Design view.
l. Drag the FKStockSymbol field from the HistoricalPrices table on top of the FKStockSymbol field
in the MaxClosePriceByStock query. By also joining on the stock symbol, only the correct
records will display.
m. Right-click the relationship line and select Join Properties to
open the Join Properties dialog box
n. Select the third radio button and click OK.
o. Run the query. 25 records should display and match the
results shown in Figure 2.
p. Save and close the query.
8. Review the existing parameter query.
a. Run the SectorIndustryParameter query.
b. Type Services in the Enter Parameter Value dialog box
and press OK. The second Enter Parameter Value dialog box
displays.
c. In the second Enter Parameter Value dialog box, dont enter
anything and press OK. The query executes and displays the
14 stocks that are in the Services sector.
d. Close the query.
9. Create a form to collect parameters for the
SectorIndustryParameter query.
a. Create a new form using Form Design.
b. Deselect the Use Control Wizards button if it is currently
Figure 2 Query results
selected.
c. Add a combo box control to the form to capture the sector parameter.

Access 2013: In Practice

Integrated Access Project 4 (Chapters 5-7)

Page 3 of 8

d. Set the following properties for the combo box: Enter comboSector in the Name property,
1.5 in the Width property, .5 in the Top property, 2.5 in the Left property, and Text
Black in the Fore Color property. On the Data tab, enter Select Distinct Sector
from Stocks; in the Row Source property to assign the data source to the combo box.
Adding Distinct into the SQL query eliminates duplicates.
e. Set the following properties for the label associated with the sector combo box: Enter 2 in
the Width property, 1 in the Height
property, .5 in the Top property, .4
in the Left property, and Text Black
in the Fore Color property. Select Center
in the Text Align property box, and type
Click the arrow to select
the desired sector, or
leave blank to display
stocks in all sectors. in the
Caption property. To have the contents
wrap, as shown in Figure 3, click inside
the label control and press Shift+Enter
before or, and again after or.
f. Add another combo box control to the
Figure 3 - Design view of GetSectorIndustryParameters form
form to capture the industry parameter.
g. Set the following properties for the combo box: Enter comboIndustry in the Name property,
3 in the Width property, 1.8 in the Top property, 2.5 in the Left property, and Text
Black in the Fore Color property. On the
Data tab, select No in the Enabled property
and open the Zoom window in the Row
Source property. Enter the SQL statement
in Figure 4 in the Zoom window and click
Figure 4 SQL statement for the comboIndustry control
OK. This query displays only the industries
for the selected sector.
h. Set the following properties for the label associated with the industry combo box: Enter 2 in
the Width property, 1 in the Height property, 1.8 in the Top property, and .4 in the Left
property. Select Center in the Text Align property box, and type Once a sector is
selected, if desired, you can click the arrow to limit the
results to an industry within the chosen sector. in the Caption property.
To have the contents wrap, as shown in Figure 3, click inside the label control and press
Shift+Enter before to an.
i. Add a button control to the form and set the following properties for the button: Enter OK in
the Caption property, 3 in the Top property, 1 in the Left property, and cmdOK in the Name
property.
j. Add a second button control to the form and set the following properties for the button: Enter
Cancel in the Caption property, 3 in the Top property, 3 in the Left property, and
cmdCancel in the Name property.

Access 2013: In Practice

Integrated Access Project 4 (Chapters 5-7)

Page 4 of 8

10.

11.

12.

13.

k. Save the form as GetSectorIndustryParameters. The form should look similar to


Figure 3. Note that the comboIndustry combo box and label appear in a dimmed state because
the enabled property is set to No. You will enable these controls through macros in Step 13.
Enhance the form design and modify properties to make it become a dialog box.
a. Set the following properties for the form: Select Yes in the Pop Up property, Yes in the Modal
property, Dialog in the Border Style property, No in the Record Selectors property, No in the
Navigation Buttons property, and Neither in the Scroll Bars. Type Stock Tracking in the
Caption property and 6 in the Width property.
b. In the Detail section, enter 3.7 in the Height
property.
c. Close the Property Sheet.
d. Save the form and change to Form view. The form
should look similar to Figure 5. Click the X button to
close the form.
Modify the query parameters to reference form controls.
a. Open the SectorIndustryParameter query in Design
view.
Figure 5 - Form view of the completed form
b. Edit the current parameter in the Sector field so that it
reads Like * &
[Forms]![GetSectorIndustryParameters]![comboSector] & *.
c. Make a similar change in the Industry field so that it now references the comboIndustry combo
box on the GetSectorIndustryParameters form.
d. Save and close the query.
Add the macro code for the OK and Cancel buttons.
a. Open the GetSectorIndustryParameters form in
Design view.
b. Open the MacroBuilder for the On Click property
of the OK button.
c. Enter the macro code shown in Figure 6.
d. Save and close the macro.
e. Open the MacroBuilder for the On Click property
of the Cancel button.
f. Add the CloseWindow action, select Form in the
Object Type argument, enter
GetSectorIndustryParameters in the
Object Name argument, and select No in the
Save argument.
g. Save and close the macro.
h. Save the form.
Figure 6 - Macro code for the OK button
Add a user interface macro to the comboSector
combo box.
a. Open the MacroBuilder for the After Update property of the comboSector combo box.

Access 2013: In Practice

Integrated Access Project 4 (Chapters 5-7)

Page 5 of 8

b. Enter the macro code shown in


Figure 7. This code executes
anytime the selection in the
combo box is updated. The
macro ensures that the industry
combo box works in conjunction
with the selection in the sector
combo box.
c. Save and close the macro.
d. Save and close the form.
14. Test the form.
a. Double-click
GetSectorIndustryParameters
to open the form.
b. Click OK. The query executes
and displays the 25 records.
c. Close the query results.
d. Double-click
GetSectorIndustryParameters
to open the form.
e. Select Consumer Goods in the
sector combo box. Note that
the industry combo box and
label are no longer dimmed.
Click the drop-down arrow in
the industry combo box. Note
that there are four options.
Change the sector combo box to
Services. Click the drop-down
arrow in the industry combo
Figure 7 - Macro code for the comboSector combo box
box. Note that there are 11
industry choices. Select Department Stores and click OK. The query executes and displays the
two stocks that match both the sector and industry criteria.
f. Close the query results.
g. Double-click GetSectorIndustryParameters to open the form.
h. Select Services in the sector combo box and click OK. The query executes and displays the 14
stocks in the services sector.
i. Close the query results.
j. Double-click GetSectorIndustryParameters to open the form.
k. Click Cancel. The form closes.
15. Add a subform to a mainform.
a. Open the VolumeAvgBySector form in Design view.
b. Ensure that Use Control Wizards is turned on.

Access 2013: In Practice

Integrated Access Project 4 (Chapters 5-7)

Page 6 of 8

16.

17.

18.

19.

c. Click the Subform/Subreport button and click in the Detail section of the form (near the left
edge and below the label). Choose to add the VolumeSubform onto the main form and accept
the suggested name for the subform. Because the main form is not bound to a record source,
the wizard did not ask you how to link the two forms.
Set the link fields on the subform.
a. If needed, open the Property Sheet and select the Data tab.
b. Click to select the subform. Verify that VolumeSubform appears in the Selection type drop-down
list.
c. Enter [comboVolSector] in the Link Master Fields property. This is the name of the combo
box on the main form.
d. Enter [Sector] in the Link Child Fields property. Although the Sector field does not display on
the subform, this field is included in the data source of the subform.
e. Save the main form.
f. Switch to Form view to
preview the form
(Figure 8).
g. Select Industrial Goods
in the combo box. The
subform updates to
display the two stocks
in this sector.
Customize the subform to
adjust the form size,
remove the border and
Navigation bar, and edit
the label.
a. Switch to Design view.
b. Select the subform and Figure 8 - Form view of main form with added subform
change the Width
property to 9.3, the Height property to 2.6, the Top property to 1.4, the Left property
to .25, and select Transparent in the Border Style property.
c. Inside the subform, click the Select All box to select the subform and then select No in the
Navigation Buttons property box.
d. Select the label control of the subform and make the following changes to these properties:
Enter Stocks in this Sector in the Caption property, 1.4 in the Width property,
1.1 in the Top property, and .5 in the Left property.
e. Save the form.
Add a calculated control onto the subform and enter an aggregate function.
a. Add a text box control to the Form Footer section of the subform.
b. Enter =Avg([AvgOfVolume]) into the Control Source property and SFAvgVol in the Name
property.
c. Delete the label that was added with the text box.
d. Save the form.
Add a text box to the main form to reference a control from the subform.

Access 2013: In Practice

Integrated Access Project 4 (Chapters 5-7)

Page 7 of 8

a. Add a text box control on the main form, to the right of the combo box and make the following
changes to these properties: Enter =[VolumeSubform].[Form]![SFAvgVol] into the
Control Source property, select Standard in the Format property, enter 1 in the Width
property, .3 in the Top property, and 7 in the Left property. Select No in the Tab Stop
property.
b. Select the label control of that text box and make the following changes to these properties:
Enter Average Volume in the Caption property 1.2 in the Width property, .3 in the Top
property, and 5.8 in the Left property.
c. Save the form and change to Form view. Note that the average volume text box displays #Error.
This displays since the subform does not yet have any data, and as a result, the SFAvgVol text
box does not have a value.
d. Change to Design view to fix the error.
e. Edit the Control Source property of the text box to read:
=IIF(IsNull([ComboVolSector]),Null,
[VolumeSubform].[Form]![SFAvgVol] This expression uses the Access IIF
(Immediate If) function which is similar to the IF function in Excel. Based on whether the combo
box is empty (null) or not, the IIF function chooses the correct value to display.
f. Save the form.
20. Test the form.
a. Switch to Form view. Note that the average volume text box no longer displays #Error.
b. Select Industrial Goods in the combo box. The subform updates to display the two stocks in this
sector and the average volume text box updates to read 3,352,588.43.
c. Select Services in the combo box. The average volume textbox and subform update. Note that
the subform scroll bars display when needed (Figure 9).

Figure 9 Form view of completed form

d. Close the form.


21. Close the database.

Access 2013: In Practice

Integrated Access Project 4 (Chapters 5-7)

Page 8 of 8

Anda mungkin juga menyukai