Download presentation
Presentation is loading. Please wait.
Published byDuane Bennett Modified over 8 years ago
1
CS 281 – Fall 2010 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
FORMS IN MS ACCESS
6
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
7
Forms: Create with Design View 1. Click the "Forms" tab in the "Database" window, then choose the "New" button. 2. Choose the table or query to base your form on from the drop-down list. If you are creating a switchboard or dialog box, you can leave the text box blank. 3. Double click "Design View" in the "New Form" dialog box. Access opens the blank form in the design view. 4. 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. 5. 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, then choose OK.
8
Forms: Create with Design View
16
Forms: Create with Form Wizard 1. Click the "Forms" tab in the "Database" window. Select "Form Wizard" in the "New Form" dialog box. Choose a table or query from the drop-down list that will be the data source. Choose OK. 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.
17
Forms: Create with Form Wizard
23
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.
24
Using Macros in Forms
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...
39
Let’s call this query with a command button
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.