Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 281 – Fall 2015 Lab 4 Parametric Query and Forms in MS Access.

Similar presentations


Presentation on theme: "CS 281 – Fall 2015 Lab 4 Parametric Query and Forms in MS Access."— Presentation transcript:

1 CS 281 – Fall 2015 Lab 4 Parametric Query and Forms in MS Access

2 QUERY PARAMETERS Example 1: Get the employee_no, name, and date_of_birth of a user-specified employee. SELECT employee_no, name, date_of_birth FROM employee WHERE employee_no = [Enter employee no:];

3 QUERY PARAMETERS Example 2: Get the beginning and ending years from the user; display employees who joined to the company in a year that is between the user specified years. SELECT employee_no, name, year_joined, skill FROM employee WHERE year_joined >= [Enter a beginning year:] AND year_joined <= [Enter an ending year:];

4 Your SQL – 1 - Increase all X’s (skill) pay_rates by X% (take the skill and payrate by manually) Ex: Increase all managers’ pay_rates by 100% Or Increase all assistants’ pay_rates by 50%

5 Your SQL – 1 - Increase all managers’ pay_rates by 100% (take the skill and payrate by manually) UPDATE employee SET pay_rate = pay_rate*[Enter Pay Rate] where skill = [Enter skill];

6 Your SQL – 2 - Delete all employees who live in X (city) (take the city by manually)

7 Your SQL – 2 - Delete all employees who live in X (take the city by manually) delete * from employee where city = [enter city];

8 FORMS IN MS ACCESS

9

10 How to create Forms? Create with Design View – Enable you to design all form. – You need to do all the work. Create with Form Wizard – Easy and Quick – Predefined templates – Can be modified later using Design View

11 Forms: Create with Design View 1. Click the "Blank Form" in the "Create" tab. 2. Add labels, text boxes, event buttons, and other controls to the design surface of your form by clicking that control in the "Toolbox" and clicking and dragging it onto the form. You can add and delete sections from forms to control what appears on the form and where it appears. 3. Click the "Save" button on the "Form Design" toolbar or choose "File", then "Save". Enter the name of the form in the "Save As" dialog box, and then choose OK. In Design View, you can add graphic elements such as lines, boxes, text labels, and bound controls. Bound controls display data from underlying record sources like tables, queries, or calculations; or they contain the results of calculations based on data in your database.

12 Forms: Create with Design View

13

14

15

16

17

18 Forms: Create with Form Wizard 1. Click the "Create" tab. Select "Form Wizard”. Choose a table or query from the drop- down list that will be the data source. 2. In the first step of the wizard, select the fields you want to see on your form from the "Available Fields" list box by double-clicking to place them in the "Selected Fields" list. For any related tables: Select that table from the Tables/Queries list box, then add the fields of interest to the "Selected Fields" list box; then choose "Next". 3. If you create a form based on a relationship, in Step 2 of the wizard you can specify the parent table used to control the view of your data, choose the parent table in the "How Do You Want To View Your Data" list box. If you have more than one data source, select also whether the child table appears in a Form with Subform(s) or is a "Linked Form Linked Through a Button to a New Window"; then choose "Next". 4. Select the layout and style desired on the next two steps of the wizard. When you select a choice, a preview is shown in the window. 5. Enter a name for the form in the "Form" text box, or a name for the subform derived from the related or linked tables as appropriate and then choose "Finish" on the next screen.

19 Forms: Create with Form Wizard

20

21

22

23

24 Using Macros in Forms To automate a sequence of operations Example: Money Transfer from one account to another account – Requires 2 SQL Update Queries – Using a macro, you can execute these two SQL Update queries in sequence, by first withdrawing amount from one account then adding amount to another account.

25 Using Macros in Forms

26

27

28

29

30

31

32

33 Money is transferred

34 Getting input from forms 1) Get employee no 2) Run a query for that employee no and show result Text box, with name Text0

35 A parametric query with input from the form SELECT * FROM employee WHERE employee_no=Forms!Form4!Text0; This is how you refer to textbox (in the form) in an SQL query.

36 Let’s call this query with a command button This button calls the query when clicked

37 Button runs the query...

38

39 Let’s call this query with a command button


Download ppt "CS 281 – Fall 2015 Lab 4 Parametric Query and Forms in MS Access."

Similar presentations


Ads by Google