Download presentation
Presentation is loading. Please wait.
Published byGarry Scott Modified over 6 years ago
1
Access Project 8 Using Visual Basic for Applications (VBA) and Creating Multi-Page Forms
2
Objectives Use VBA Create functions in a standard module
Test functions Use the functions in a query Associate code with an event
3
Objectives Create Sub procedures Correct errors using debugger
Create code to update controls Create a function to run a command Create a form using Design view
4
Objectives Add a tab control Add a subform control to a form
Add a chart to a form Add an ActiveX control to a form
5
Creating Functions in a Standard Module
Open the Ashton James College database in Microsoft Office Access 2003 as described on page AC 462 Click Modules on the Objects bar in the Database window Click the New button on the Database window toolbar and be sure the window is maximized Type Function PromoFactor(Client_Type) and then press the ENTER key Type the statements shown in lines 2 through 12 of Table 8-10 on page AC 467
6
Creating Functions in a Standard Module
Use the DOWN ARROW key to move the insertion point below the End Function statement Type Function PromoAmount(Client_Type, Current_Due) and then press the ENTER key Type the statements shown in lines 2 through 4 of Table 8-11 on page AC 468 Click the Save button on the Standard toolbar, type Promo Modules as the module name, and then click the OK button
7
Creating Functions in a Standard Module
8
Testing Functions in the Immediate Window
Click View on the menu bar, and then click Immediate Window on the View menu Type ?PromoFactor(“EDU”) in the Immediate window, and then press the ENTER key Type ?PromoAmount(“EDU”,10000) in the Immediate window, and then press the ENTER key Click the Close button for the Microsoft Visual Basic – Ashton James College – [Promo Modules (Code)] window to close the window
9
Testing Functions in the Immediate Window
10
Using Functions in a Query
In the Database window, click Tables on the Objects bar, and then click Client, if necessary Click the New Object button arrow on the Database toolbar, and then click Query Be sure Design View is selected, and then click the OK button Be sure the Query1 : Select Query window is maximized
11
Using Functions in a Query
Resize the upper and lower panes and the Client field list so all the fields in the Client table appear One-by-one double-click the Client Number, Name, Current Due, and Client Type fields Right-click the column following Client Type, and then click Zoom on the shortcut menu Type Promo Factor:PromoFactor([Client Type]) as the expression
12
Using Functions in a Query
Click the OK button Right-click the column following Promo Factor, and then click Zoom on the shortcut menu Type Promo Amount:PromoAmount([Client Type],[Current Due])*1.00 as the expression
13
Using Functions in a Query
Right-click the Promo Amount column, click Properties on the shortcut menu, click the Format property on the General tab, click the Format property box arrow, and then click Currency Close the property sheet by clicking its Close button Run the query, resize each column to best fit the data by double-clicking the right border of the column heading Close the window containing the query by clicking its Close Window button, click the Yes button to save the query, type Promo Amount Query as the name, and then click the OK button
14
Using Functions in a Query
15
Associating Code with an Event
Add the necessary command buttons and controls to the form, as instructed on pages AC 475 – AC 481 Right-click the cmdPromo button (the button whose caption is Show Promotion), click Properties on the shortcut menu, scroll down so the On Click property appears, and then click the On Click property Click the Build button, click Code Builder in the Choose Builder dialog box, and then click the OK button Close the Immediate window by clicking its Close button so more of the Visual Basic code is visible Type the statements on lines 2 through 10 shown in Table 8-12 on page AC 482
16
Associating Code with an Event
17
Creating Sub Procedures
Click the Insert Module button arrow on the Standard toolbar Click Procedure Type ShowPromotion as the name of the procedure in the Add Procedure dialog box
18
Creating Sub Procedures
Click the OK button and then type the statements on lines 2 through 4 for the ShowPromotion procedure shown in Table 8-13 on page AC 484 Use the techniques in the previous steps to create the HidePromotion procedure from Table 8-14 on page AC 484 Click the Close button for the Microsoft Visual Basic – Ashton James College – [Form_Client Update Form (Code)] window and then click the Close button for the cmdPromo property sheet
19
Creating Sub Procedures
20
Creating Code to Update Controls
Right-click the form selector (the small box in the upper-left corner of the form), click Properties, and then click the On Current property Click the Build button Click in front of the letter E in End Sub Add the additional statement shown in Figure 8-41 on page AC 489 Click the Insert Module button arrow on the Standard toolbar, click Procedure, be sure the Sub and Public option buttons are selected in the Add Procedure dialog box, type UpdatePromoData as the name of the procedure, and then click the OK button
21
Creating Code to Update Controls
Type the statements on lines 2 and 3 for the UpdatePromoData procedure shown in Table 8-15 on page AC 488 Click the Close button for the Microsoft Visual Basic – Ashton James College – [Form_Client Update Form (Code)] window to close the window Close the Form property sheet Right-click the combo box for Client Type, click Properties on the shortcut menu, click the After Update property, click the Build button, click Code Builder in the Choose Builder dialog box, and then click the OK button Add the statement shown in Figure 8-43 on page AC 490 to the Combo18_AfterUpdate procedure
22
Creating Code to Update Controls
Click the Close button for the Microsoft Visual Basic – Ashton James College – [Form_Client Update Form (Code)] window to close the window Click the Close button for the Combo Box: Combo 18 property sheet Right-click the control for the Current Due field (the white space, not the label), click Properties on the shortcut menu, click the After Update property, click the Build button, click Code Builder in the Choose Builder dialog box, and then click the OK button Add the statement shown on the following slide to the Current_Due_AfterUpdate procedure Click the Close button for the Microsoft Visual Basic – Ashton James College – [Form_Client Update (Code)] window to close the window and then close the Text Box: Current Due property sheet
23
Creating Code to Update Controls
24
Creating a Function to Run a Query
Click Modules on the Objects bar in the Database window, right-click Promo Modules, and then click Design View on the shortcut menu Be sure the window is maximized Click below the End Function for the second function (PromoAmount), type Function RunPromoAmountQuery(), and then press the ENTER key Type the statements on lines 2 through 12 shown in Table 8-17 on page AC 493 Click the Close button for the Microsoft Visual Basic – Ashton James College – [Promo Modules (Code)] window to close the window
25
Creating a Function to Run a Query
Click Forms on the Objects bar in the Database window, right-click the Client Update Form, click Design View on the shortcut menu, and then maximize the window if it already is not maximized Right-click the button whose caption is Run Promotion Query, click Properties on the shortcut menu, click the On Click property in the Command Button:cmdPromoQuery property sheet, and then type =RunPromoAmountQuery() as the value for the On Click property Close the property sheet by clicking its Close button, and then click the Close Window button for the window containing the form design When asked if you want to save your changes, click the Yes button
26
Creating a Function to Run a Query
27
Creating a Form If necessary in the Database window, click Tables on the Objects bar, and then click Trainer Click the New Object button arrow on the Database toolbar Click Form Be sure Design View is selected, and then click the OK button
28
Creating a Form Be sure the field list appears and the window is maximized. (If it does not, click the Field List button on the Form Design toolbar) Drag the Trainer Number, First Name, and Last Name fields to the approximate positions shown on the following slide Move the attached labels for the First Name and Last Name fields to the positions shown in the figure by dragging their move handles Close the field list by clicking its Close button
29
Creating a Form
30
Using Tab Controls to Create a Multi-Page Form
Click the Tab Control tool and move the mouse pointer to the approximate location shown in Figure 8-58 on page AC 506 Click the position shown in Figure 8-58 Right-click the tab control, and then click Insert Page on the shortcut menu Click the leftmost tab, right-click the tab control, and then click Properties on the shortcut menu Change the name to Datasheet
31
Using Tab Controls to Create a Multi-Page Form
Close the property sheet by clicking its Close button Right-click the middle tab, select Properties on the shortcut menu, change the name to Charts, and then close the property sheet Right-click the rightmost tab, select Properties on the shortcut menu, change the name to Web, and then close the property sheet Click the leftmost tab Resize the tab control to the approximate size shown on the following slide by dragging the appropriate sizing handles
32
Using Tab Controls to Create a Multi-Page Form
33
Placing a Subform Be sure the Control Wizards tool is selected, click the Subform/Subreport tool in the toolbox, and then move the mouse pointer to the approximate position shown in Figure 8-62 on page AC 508 Click the position shown in Figure Be sure the “Use existing Tables and Queries” option button is selected Click the Next button Click the Tables/Queries box arrow and then click the Clients and Course Offerings query
34
Placing a Subform Click the Add All fields button
Click the Next button Be sure the “Choose from a list” option button is selected
35
Placing a Subform Type Course Offerings for Trainer as the name of the subform and then click the Finish button If the window is no longer maximized, maximize the window If a field list appears, close the field list Resize the subform to the approximate size shown on the following slide by dragging the appropriate sizing handles
36
Placing a Subform
37
Inserting Charts In the Ashton James College: Database window, be sure Forms is selected on the Objects bar, right-click Trainer Data and then click Design View on the shortcut menu Be sure the window is maximized, and then close the field list if it appears Click the Charts tab and then click Insert on the menu bar Click Chart and then move the pointer to the approximate position shown in Figure 8-69 on page AC 512 Click the position shown in Figure 8-69
38
Inserting Charts Click the Queries option button in the Chart Wizard dialog box, click the Clients and Course Offerings query, and then click the Next button Select the Course Number and Total Hours fields by clicking them and then clicking the Add Field button Click the Next button Be sure the chart in the upper-left corner is selected
39
Inserting Charts Click the Next button
Click the Next button, type Total Hours by Course as the title, and then click the Finish button Use the techniques shown in Steps 1 through 7 on pages AC 511 through AC 514 to add a second chart at the position shown on the following slide. In this chart, select Hours Spent instead of Total Hours and type Hours Spent by Course as the title of the chart instead of Total Hours by Course
40
Inserting Charts
41
Adding an ActiveX Control
Click the third tab, the one labeled Web on the tab control Click Insert on the menu bar, and then click ActiveX Control on the Insert menu to display the Insert ActiveX Control dialog box Select Microsoft Web Browser in the Select an ActiveX Control list and then click the OK button Be sure the Web browser just added is selected Drag the right sizing handle and then drag the lower sizing handle to change the size of the Web Browser control to the one shown in Figure 8-77 on page AC 516
42
Adding an ActiveX Control
Right-click the control and then click Properties on the shortcut menu to display the property sheet Note the number of your Web Browser control, which may be different from the one shown in Figure 8-77 on page AC 516 Click the Close button for the property sheet Right-click the form selector, click Properties on the shortcut menu, scroll down so the On Load property appears, and then click the On Load property
43
Adding an ActiveX Control
Click the Build button, click Code Builder in the Choose Builder dialog box, and then click the OK button Type me!WebBrowser1.navigate " ajc.html" as the statement in the Form_Load procedure Click the Close button for the Microsoft Visual Basic – Ashton James College – [Form_Trainer Data (Code)] window to close the window Click the Close button for the property sheet
44
Adding an ActiveX Control
45
Summary Use VBA Create functions in a standard module Test functions
Use the functions in a query Associate code with an event
46
Summary Create Sub procedures Correct errors using debugger
Create code to update controls Create a function to run a command Create a form using Design view
47
Summary Add a tab control Add a subform control to a form
Add a chart to a form Add an ActiveX control to a form
48
Access Project 8 Complete
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.