<<

Microsoft Access XP (2002) - Forms

. Navigation . Wizards . Custom Forms . Combo Boxes . Calculations in Forms . Pictures . Multitable Input . Summary Operations USC - Marshall School of Business AIS – User Support

Table of Contents

Exercise File Needed ...... 3 INTRODUCTION TO ACCESS FORMS ...... 4 Accessing the Database in HOH401 ...... 4 Opening Sweets 2000 ...... 4 AUTOCONTENT WIZARD ...... 5 NAVIGATING FORMS ...... 5 Keyboard Navigation ...... 5 Mouse Navigation ...... 5 DATA ENTRY USING A FORM ...... 6 Data Entry Using a Mouse ...... 6 SAVING A FORM ...... 6 SEARCHING FOR RECORDS IN A FORM ...... 7 Find ...... 7 Filter by Example ...... 7 USING THE FORM WIZARD ...... 8 MANUALLY CREATING A FORM ...... 9 THE FORM DESIGN ENVIRONMENT ...... 9 The Canvas Area ...... 9 Placing Fields on the Form ...... 10 Placing Several Fields on the Form Similtanously ...... 10 Selecting Controls ...... 11 Deleting a Control ...... 11 Moving and Resizing Controls ...... 11 Aligning Controls ...... 11 THE TOOLBOX ...... 12 CREATING A DROP DOWN LIST (COMBO BOX) ...... 13 Creating a Combo Box for “Customer ID” Number ...... 13 Set Order ...... 15 USING A COMBO BOX TO GO TO A RECORD...... 16 CREATING AN OPTION GROUP ...... 18 CREATING TAB SHEETS ...... 20 CREATING A CHECK BOX ...... 21 CALCULATIONS IN FORMS ...... 22 Equation Guidelines ...... 22 CALCULATIONS INVOLVING NUMBERS ...... 22 Formatting Calculated Fields ...... 23 Disallow Tab Stop ...... 23 Changing the description for the Control ...... 23 CALCULATIONS INVOLVING DATES ...... 24 Expressing Time in Other Units ...... 25 USING FORM HEADER & FOOTERS ...... 27 Inserting a Picture in the Form Header ...... 27 Resizing Pictures ...... 27 Setting Size Mode...... 28 Inserting Text into Headers or Footers ...... 28 Inserting The Date & Time ...... 28

AccessXP-Forms.doc April 23, 2003 Page 2 of 33 USC - Marshall School of Business AIS – User Support

Inserting Page Numbers ...... 28 TABLE RELATIONS & MULTIFORM ENTRY ...... 29 Table Relations: ...... 29 Relating Tables ...... 29 CREATING A MAIN/SUBFORM ...... 31 USING MAIN/SUBFORMS ...... 32 Moving to the Next/Previous Record ...... 32 Starting a New Record ...... 32 Adding Another Record ...... 32 Saving & Reusing the Main/Subform...... 33

Exercise File Needed

This handout utilized a database file called: SweetsXP.mdb. It can be found on the Marshall Web Page at: http://www.marshall.usc.edu/Web/Computing.cfm?doc_id=770#Access

AccessXP-Forms.doc April 23, 2003 Page 3 of 33 USC - Marshall School of Business AIS – User Support

INTRODUCTION TO ACCESS FORMS

Although data can be entered and edited directly in a table, most users create forms for data entry. Forms can be easier to work with and have several advantages over working directly with tables.

. Calculations can be placed in forms but not in tables. . A form can be used to place data into more than one table (This can be done using tables as well.) . Fields can be hidden from the data entry person. For example, there may be certain fields that you do not wish them to see such as Salary or you may simply have certain fields that will be filled in later and you do not want the data entry person to type anything in them yet. . Pictures can be stored in tables, but they can only be displayed in forms (or reports). . The fields can be placed on the form in any order or position desired. For example, if you are doing data entry from a survey, you can arrange your form to look exactly like the survey. . A from only shows one record at a time, making data entry easier. . Switchboards employing macro buttons are created in forms (Not covered in this handout.)

It should be noted that when you use a form, data is not duplicated, you are merely creating another method of viewing the data in a table. When you are working on data through a form, you are really working on data from the underlying table.

General Steps in Creating a From: a. Select the table that the form is to be used with. b. Create the form either using a form wizard or manually in “Design View” .

Accessing the Database in HOH401 If you are attending the Access workshop in HOH401, you will need to access the SweetsXP.mdb database. This database can be copied off the network into C:\temp by typing the line below in the RUN box.

1. From the Windows taskbar, click on: START - RUN 2. Type the following: \\msbapps\labapps\prof\training\getfiles 3. Click on “Ok” .

Opening Sweets XP 1. Start MS Access XP. 2. Select: Open an Existing Database 3. Select: More Files and click on “Ok” . 5. Select the file called: SweetsXP.mdb and click “Open” .

AccessXP-Forms.doc April 23, 2003 Page 4 of 33 USC - Marshall School of Business AIS – User Support

AUTOCONTENT WIZARD

The Autocontent Wizard is the fastest method of creating a form. It makes a standardized form based upon the table selected.

1. Click on the Tables tab in the Database . 2. Select the table “General Candy Info” . 3. From the , click on: INSERT - FORM 4. In the New Form window, select: AutoForm: Columnar and click “Ok” .

NAVIGATING FORMS

Keyboard Navigation KEYSTROKE ACTION Enter Moves the cursor to the next field Tab Moves the cursor out of a memo field. Shift + Tab Moves the cursor to the previous field. Control + Page Down Moves the cursor to the next record. Control + Page Up Moves the cursor to the previous record. Page Down Moves to the next page of a multi-page record. Page Up Moves to the previous page of a multi-page record. Control + Home Moves the cursor to the first record. Control + End Moves the cursor to the last record. F5 Allows you to specify the record to go to.

Mouse Navigation

Moves the cursor to Displays the current Starts a new record. Displays the total the first record. record number. number of records..

Moves the cursor up Moves the cursor Moves the cursor to one record. down one record. the last record.

AccessXP-Forms.doc April 23, 2003 Page 5 of 33 USC - Marshall School of Business AIS – User Support

DATA ENTRY USING A FORM

Data entry and editing using a form is essentially the same data entry & editing in tables. Keystroke Action ENTER (in the last field of a record) Saves the record. SHIFT + ENTER (in any field of a record) Saves the record Control + Inserts a new record. Control - Deletes the current record. F2 Toggles the cursor between highlighting the entire field to a single character cursor. Spacebar Toggles the check in a Yes/No F4 Activates the drop down list of a combo box. Control + ; Inserts the current date. Control + Shift + : Inserts the current time. Control + ‘ Copies data from the field above.

Data Entry Using a Mouse Starts a new record. Deletes the current record. . Clicking a check box will add/remove its check in a Yes/No field. . Clicking the down arrow in a combo box will display a list of choices.

SAVING A FORM

When you save a form, it will be kept under the Forms tab in the Database window. However, you do not have to save a form to use it for data entry and whether you save a form or not, the data typed into it is still written to the table.

To save your form: 1. Click on the “Save” on the . 2. Type a descriptive name for the form. 3. Click on “Ok” .

To use the form at a later date, merely click on the Forms tab in the Database window and then double click the form.

AccessXP-Forms.doc April 23, 2003 Page 6 of 33 USC - Marshall School of Business AIS – User Support

SEARCHING FOR RECORDS IN A FORM

The methods for searching a Form are the same as searching a table.

Find 1. Open the form you wish to search. 2. Click in the field you wish to search. 3. Click on the “Find” icon from the toolbar. 4. Type the text you are looking for in the Find What box. 5. Click “Find First” to move the record containing your text.

Type what you are searching for here.

Select the search direction here: All, Up, or Down.

Match: Whole Field, Any Part of Field, or Start of Field..

Filter by Example Unlike “Find” which takes you to the record containing your text, “Filter by Example” will display only those records matching the example you select.

1. Click on the word “Nabisco” in the Manufacturer field. 2. Click on the “Filter by Example” icon.

You should only be able to view records where the manufacturer is Nabisco. Note the words “(Filtered)” at the bottom of your screen. This indicates that you are not seeing all of your records.

Removing the Filter To remove the filter and display all of your records again: 1. Click on the “Remove Filter” icon.

AccessXP-Forms.doc April 23, 2003 Page 7 of 33 USC - Marshall School of Business AIS – User Support

USING THE FORM WIZARD

Like the Autocontent Wizard , the Form Wizard also creates a form for you, but they differ in that the Form Wizard allows for some user input into how the form will look.

We will create a form for the table “General Candy Info” that leaves out the Candy ID field. Since this field is an autonumber field, the data entry person will never need to type in it.

1. Click on the Tables tab in the Database window. 2. Select the table “General Candy Info” . 3. From the menu, click on: INSERT - FORM 4. In the New Form window, select: Form Wizard then click “Ok” . 5. Select the all fields except Candy ID for your form. (See illustration below.)

Lists all of the fields in Lists all of the table. the fields Pick the that will fields you appear on want on your form. your form Use the > from this sign to list. bring fields to your form.

Places the selected field on your form. Removes the selected field from your form.

Places all fields on your form Removes all fields from your form.

6. Click on “Next”. 7. Select the type of layout you would like. 8. Click on “Next”. 9. Select a style you would like: 10. Click on “Next”. 11. Type a title for your form. 12. Select: Open the form to view or enter information 13. Click on “Finish” .

AccessXP-Forms.doc April 23, 2003 Page 8 of 33 USC - Marshall School of Business AIS – User Support

MANUALLY CREATING A FORM

For most purposes, the wizards will suffice in creating the desired forms. However, it usually is necessary to go into “Design View” and modify the form. The best way to learn about “Design View” is to create a form from scratch.

In this example, we will create a form for the table called “Orders” .

1. Click on the Tables tab in the Database window. 2. Select the table “Orders” 3. From the menu, click on: INSERT - FORM 4. Select “Design View” and click on “Ok” .

THE FORM DESIGN ENVIRONMENT

Prior to creating a form, it is important to become familiar with some of the more important features in form design view.

The Canvas Area The Canvas area of a form is the area where objects (fields, pictures, buttons, etc.) must be placed. Its size will determine how big the form is and how many pages/screens a record will take to display. Note that the Form Header/Footer and Page Header/Footer area will not be present in your form at this time. They can be displayed by selecting them from the menu under: VIEW -

Items placed in the Form Header/Form Footer sections will appear at the Top/Bottom of the screen and printout. Headers & Footers are for such things as field headings, the current date, or the title of your form.

Items placed in the Page Header/Page Footer sections will only appear at the Top/Bottom of every printed page but not on the screen.

Fields from your table should be placed in the Detail area.

Click & drag the Section Bars to control how large a section is.

Click & drag the Canvas area by its edge to resize the form.

AccessXP-Forms.doc April 23, 2003 Page 9 of 33 USC - Marshall School of Business AIS – User Support

Placing Fields on the Form Data fields should be placed in the Details area of the form. Place them there by clicking & dragging them from the field list.

Field List: Clicking the “Field List” icon on the Form Design toolbar will display/hide a list of the fields in the table that the form is based on. Click and drag a field name to the Details area of your form to place it on your form.

1. If the Field List is not visible, click the “Field List” icon. 2. Click & drag Order ID to the Details section of the form.

Note that two controls are created: The Label control which is the name of the data being displayed, and the TextBox control which is the actual data.

3. To see the actual data, click on the “Form View” icon. 4. To return to design view, click on the “Design View” icon.

Label Control: This Text Control: Data is the title of the data from the table is being displayed displayed in the Text (same as a column Control box. In this heading). This case, the Order ID control can be numbers will be deleted or renamed displayed if viewed without harming the from “Form View”. connection to the table.

5. Place the rest of the fields on the form.

Placing Several Fields on the Form Similtanously Rather than placing fields on the form one by one, you can select several fields and place them on the form similtanously. When you click & drag any one of the selected fields to the form, all of the selected fields will be placed on the form.

Selection Techniques . Double clicking the table’s name (“Orders”) at the top of the Field List will highlight all the fields in the table. . Holding down the “CONTROL” key on the keyboard allows you to select discontiguous fields. . Clicking a field, and then holding down the “SHIFT” key on the keyobard and clicking another field will select all of the fields between and including the two fields.

AccessXP-Forms.doc April 23, 2003 Page 10 of 33 USC - Marshall School of Business AIS – User Support

Selecting Controls To modify any object in Form Design View, you must first select it. Objects are selected by clicking on them. To deselect an object, simply click in the background away from the object.

Deleting a Control To remove a field from the form, simply click on it to select it and press the “DELETE” key on the keyboard.

Moving and Resizing Controls

Move a Control: To move just one of the controls, click and drag the control by the large square in its upper left corner. The mouse will turn into a finger when positioned correctly.

Resize: To resize a control, place the mouse on one of the small black squares surrounding the control and click and drag. The mouse becomes a double headed arrow when positioned correctly.

Aligning Controls The controls on the form can be manually moved and aligned with each other, but using FORMAT – ALIGN from the menu is usually faster. You can select multiple controls by either: . Holding down the “SHIFT” key while clicking the control on the form. . Clicking & dragging around several controls selects any control that is at least partially included. (Note that Labels are automatically selected with their associated control)

1. Select one of the controls to be aligned. (See the example below.) 2. Hold down the “SHIFT” key and click the other controls it is to be aligned with. 3. From the menu, click on: FORMAT - ALIGN - LEFT 4. Repeat the procedure above for the other controls.

AccessXP-Forms.doc April 23, 2003 Page 11 of 33 USC - Marshall School of Business AIS – User Support

THE TOOLBOX To create such controls as drop down boxes, check boxes, pictures, calculations, etc, it is necessary to use the Toolbox .

1. Click the “Toolbox” icon on the Form Design toolbar to hide/display the toolbar:

Select Objects: Allows the selection of objects. Control Wizards: When turned on, Label: Used for placing text on any part wizards will help with using other tool of your form. box controls.

Text Box: Used to create calculations. Option Group: Used in conjunction with option buttons, this allows you to select between a group of choices. Toggle : Toggles between two choices.

Option Button: Use either with a Yes/No Check Box: Used with Yes/No fields. field or in an option group. : Allows selection from a list of choices.

Combo Box: Allows selection from a drop down list of choices. Image: Use to place pictures from a source outside the database on the form. Command Button: Use to activate macros & module commands. Bound Object Frame: Used to display OLE objects (such as pictures) that are stored in the table in the form. Unbound Object Frame: Use to place OLE objects (sounds, pictures, etc.) from an outside source in your form. Tab Control: Allows you to place controls behind one another using tabs. Page Break: Forces a page break. Line: Use to place lines on your form. SubForm/SubReport: Use to create a form within a form. More Controls: Opens a list of more advanced controls. Rectangle: Places a rectangle in the form.

AccessXP-Forms.doc April 23, 2003 Page 12 of 33 USC - Marshall School of Business AIS – User Support

CREATING A DROP DOWN LIST (COMBO BOX) Combo boxes in forms allow the data entry person to click a down arrow which will list choices that can be placed in the field. Combo boxes are useful when there are only a limited number of choices to select from. Further, they ensure that entries are spelled correctly.

Creating a Combo Box In the “Orders” form, we are supposed to type in the Customer ID for the customer we are taking the order for. This means that either we have to have all of the Customer ID numbers memorized or have them on a sheet of paper somewhere telling us what each company’s ID is.

To avoid this problem, we will make a combo box that will list the Company Name and their Customer ID number. When the user selects a Company Name from the drop-down list, the Customer ID number will be placed in the Combo Box for us. To create this list, we will use the “Sweets Customers” table because it contains the Company Names and Customer IDs.

1. Open the “Orders” form in “Design View” . 2. Click on the Textbox control “Customer ID” and press the “DELETE” key. 3. Display the Toolbox toolbar.

4. Make sure the “Control Wizards” button is pressed. 5. Click on the “Combo Box” icon.

6. Drag the field Customer ID from the Field List onto the form.

At this point, the wizards will activate.

7. Select: I want the combo box to look up the values in a table or query.

8. Click on “Next” .

9. At “Which table or query should provide the values for your combo box?” , select: “Sweets Customers”

10. Click on “Next” .

AccessXP-Forms.doc April 23, 2003 Page 13 of 33 USC - Marshall School of Business AIS – User Support

11. At “Which fields contain the values you want included in your combo box?”

Select: Customer ID and click the “>” button.

Select: Company Name and then click the “>” button.

12. Click on “Next” .

13. Remove the check from Hide key column

14. Adjust the column widths.

15. Click on “Next” .

16. For the value to store, select: Customer ID Of the two columns being displayed, this is the one containing the data we are after.

17. Click on “Next” .

18. Set “Store that value in this field” to: Customer ID (We will be storing the Customer IDs in the Customer ID field.)

19. Click on “Next” .

20. Label the Customer ID control: Customer ID

21. Click on “Finish” .

AccessXP-Forms.doc April 23, 2003 Page 14 of 33 USC - Marshall School of Business AIS – User Support

You should now have a combo box on your screen. Select “Form View” to use it.

1. Click the “Form View” icon. 2. Click on the down arrow to select from the drop-down list. When you click on a Company Name, the Customer ID should be placed in the Customer ID box.

Notes: . The “F4” key also activates the combo box. . Typing in the combo box goes to the first matching value from the list.

Exercise: Try making another combo box for Employee ID . The Employee IDs, First, and Last Names are in the “Sweets Employees” table.

Set Tab Order When data is being entered into a form, the user will normally press either “ENTER” or “TAB” to move to the next control. The Tab Order property determines which control the cursor moves to next. By default, Tab Order is determined by the sequence in which controls are added to the form. However, if you did not place the controls on the form in the sequence that you wish to browse them with the cursor, you will need to set the form’s Tab Order .

1. Click on the “Design View” icon. 2. From the menu, select: VIEW - TAB ORDER… 3. See the illustration below on setting tab order. Click “Ok” when finished.

To Manually set tab order: 1. Click on the gray box next to the field name and let up on the mouse button. 2. Click and drag the selected field up or down using the mouse.

Using Auto Order: Pressing “Auto Order” will change tab order to match the position of the fields on the form. The cursor will move left to right, top to bottom.

AccessXP-Forms.doc April 23, 2003 Page 15 of 33 USC - Marshall School of Business AIS – User Support

USING A COMBO BOX TO GO TO A RECORD

An “unbound” combo box (a control that is not connected to a field in the table) can be used to go to a record by selecting from the list. Unlike a bound combo box which places data in a field, an unbound combo box lists data, but does not place data in the table.

We will create a new form based on the table “Sweets Customers” and create a combo box which we can use to pull up a record based on the Company Name .

Setting up the Form 1. Save and close the “Orders” form by clicking the “Save” button. 2. Click on the Tables tab and select the table “Sweets Customers” 3. From the menu, select: INSERT - FORM 4. Select “Design View” and click on “Ok” . 5. Make sure the Field List is displayed. 6. Make sure the Toolbox is displayed. 7. From the Field List, double click the “Sweets Customers” title to select all fields. 8. Click & drag any one of the fields to place them all on your form. 9. Make sure the “Toolbox Wizards” icon is pressed.

Using the Combo Box Wizards

10. Click on the “Combo Box” button on the Toolbox . 11. Click on a blank area of the form.

12. Select: Find a record on my form based on the value I selected in my combo box.

13. Click on “Next” .

14. Select Company Name and click the “>” button to place it in the combo box.

15. Click on “Next” .

16. Leave the keyed column hidden and adjust the column width of the “Company Name” column.

17. Click on “Next” .

AccessXP-Forms.doc April 23, 2003 Page 16 of 33 USC - Marshall School of Business AIS – User Support

18. Type in a label such as: Click to find a company 19. Click on “Finish” .

Testing the Combo Box 20. Click the “Form View” icon. 21. Click the down arrow for the combo box and select a company.

You should have been taken to the record for that company.

22. Save the form: FILE - SAVE 23. Name the file: “Customers” and click “Ok” .

AccessXP-Forms.doc April 23, 2003 Page 17 of 33 USC - Marshall School of Business AIS – User Support

CREATING AN OPTION GROUP

An Option Group allows the user to select from a limited list of choices by clicking radio buttons. The concept is similar to a combo box in that the user selects items from a list but the result is completely different. With a combo box, the actual names are written to the table, with an Options Group only numbers can be written to the table.

Example: We sell to four types of companies: Single Stores, National Chains, Distributors, and Mail Order Companies. If we were to use an Option Group to select these, it would assign numbers to each of the four types of companies. For example:

Distributors = 1, Mail Order = 2, National Chains = 3, Single Store = 4

The numbers 1, 2, 3, or 4 would be written to the table rather than the company types.

1. Open the “Customers” form in “Design View” . 2. Delete the “Company Type” control from the form. 3. Make sure the Toolbox is displayed. 4. Make sure the “Toolbox Wizards” icon is selected. 5. On the Toolbox , click on the “Option Group” icon. 6. Click on a blank area of the form.

The Option Group Wizard starts.

6. Type: Distributor and press “TAB” . Type: National Chain and press “TAB” . Type: Mail Order and press “TAB” . Type: Single Store and press “TAB” . 7. Click on “Next” .

8. Set the Default Choice if desired. 9. Click on “Next” .

AccessXP-Forms.doc April 23, 2003 Page 18 of 33 USC - Marshall School of Business AIS – User Support

10. If desired, change the numbers which will be written to the table. 11. Click on “Next” .

12. Select: Store the value in this field and use the drop down arrow to select: Company Type 13. Click on “Next” .

14. Select the type of control: Option buttons and the style you would like: Etched 15. Click on “Next” . 16. Type in a caption for the option group. 17. Click on “Finish” .

Testing the Option Group 18. Click the “Form View” icon. 19. Click on one of the options for a record. 20. Go to another record and select another option. 21. Save the form . 22. Close the form. 23. Open the “Sweets Customers” table to see the numbers.

AccessXP-Forms.doc April 23, 2003 Page 19 of 33 USC - Marshall School of Business AIS – User Support

USING TAB CONTROLS Tab Controls allow the user to overlap pages on a form. The additional pages can be accessed by clicking on the tab buttons. This allows the user to place more fields on a form and separate data into logical categories.

Exercise: We will create a form for the “Sweets Employees” table which separates company information from personal information.

1. On the Tables tab, select the table “Sweets Employees” . 2. From the menu, select: INSERT - FORM 3. Select: Design View and click on “Ok” . 4. Make sure the Field List is displayed. 5. Make sure the Toolbox is displayed.

Create the Tab Control 6. From the Toolbox, click on the “Tab Control” button. 7. Click on the form to create the Tab Control . 8. If necessary, resize the form by clicking & dragging it by its handles.

Rename The Tabs 9. Double click the name of one of the tab sheets. 10. In the Name section of the Properties window, type: Company Info 11. Click on the other tab. 12. In the Name section, type: Personal Info 13. Close the Properties window.

Inserting/Deleting Sheets on Tab Controls . To Insert a sheet, right-mouse click a sheet and select: Insert Page . To Delete a sheet, right-mouse click a sheet and select: Delete Page

AccessXP-Forms.doc April 23, 2003 Page 20 of 33 USC - Marshall School of Business AIS – User Support

Placing Fields on the Pages 15. Use the mouse to click and drag the following fields from the “Sweets Employees” Field List to the “Company Info” and “Personal Info” sheets on the Tab Control :

Using The Sheets 16. Click the “Form View” icon.

. “ENTER” and “TAB” will move the cursor to the next field and eventually to the next record; but neither keystroke will move the cursor to the fields on the hidden sheet. . To move the cursor between sheets: Either click on the sheet tabs with the mouse or press “CONTROL” + “TAB” on the keyboard.

CREATING A CHECK BOX

Check boxes are used in conjunction with YES/NO fields. Rather than typing yes or no, you can click in a box to indicate yes or no or press the “SPACE” on the keyboard. We will create a for the Still Employed field in the “Sweets Employees” table.

1. With the “Employees” form still open. 2. Return to “Design View” . 3. Click on the “Check box” button on the Toolbox. 4. Click & drag Still Employed? from the Field List to one of the sheets on the form. 5. The check box is created. Click the “Form View” icon.

AccessXP-Forms.doc April 23, 2003 Page 21 of 33 USC - Marshall School of Business AIS – User Support

CALCULATIONS IN FORMS

Calculations in forms are useful as a reference but they will not write information to the table (ie. they are display only). There are two methods of creating forms containing calculations: . Type the calculations directly in the form. (Shown here.) . Create the calculations in a query, save the query, and base the form off the saved query rather than directly off the table. (Not Shown.)

Equation Guidelines . Equations in forms must begin with an “=” sign. . Field names must be spelled correctly and must be surrounded by braces (“[ ]”). . Use the “” tool to create equations.

Parenthesis Exponent Multiplication Division Addition Subtraction ( ) ^ * / + -

Label Control: This can be edited Text Control: Equations always go to say anything the user desires. It in the Text Box control. It will can even be deleted. display “Unbound” if it is not yet To change the description, simply linked to a field. click inside of the control and type To create an equation, simply click a new name. You can also change inside of the control and type the its name in the Properties window equation. Note that the equation can by editing the Caption line. also be entered in the Properties window on the Control Source line.

CALCULATIONS INVOLVING NUMBERS In the “General Candy Info” table, we will find the amount of taxes for items in the Cost Per Unit field. Assume a tax rate of 8.25%.

1. In the Database window, click on the Tables tab. 2. Select the table: “General Candy Info” 3. From the menu, select: INSERT - FORM 4. Select “Design View” and click on “Ok” . 5. Make sure the Field List is displayed. 6. Make sure the Toolbox is displayed. 7. Drag the following fields from the Field List to the form: Manufacturer , Brand Name , & Cost Per Unit 8. Click on the “Text Control” icon. 9. Click on a blank area of the form. 10. Click inside the text box you just created. 11. Type the following equation: =[Cost Per Unit]*.0825 12. Press “ENTER” . 13. Click the “Form View” icon to see the result.

AccessXP-Forms.doc April 23, 2003 Page 22 of 33 USC - Marshall School of Business AIS – User Support

Formatting Calculated Fields The equation works but there are too many decimals to the right of the decimal point. 1. Return to “Design View” . 2. Select the equation by clicking on the Text Control. 3. Click on the “Properties” icon to open the Properties window: 4. Click in the Format box and select: Currency from the drop down list.

Disallow Tab Stop When the user presses “ENTER” or “TAB” while in “Form View”, the cursor moves through all of the fields including the calculated field. Being that the user will never be entering data into this field, there is no reason to stop there, so to prevent it:

1. While in “Design View”, click on the calculation to select it. 2. Open the Properties window . 3. Click on the Other tab. 4. Set the Tab Stop option to: No

Changing the description for the Label Control 1. Still in “Design View”, click inside the label control. (The one on the left.) 2. Type a description for the text box control next to it, such as: Tax: 3. Press “ENTER” on the keyboard.

AccessXP-Forms.doc April 23, 2003 Page 23 of 33 USC - Marshall School of Business AIS – User Support

CALCULATIONS INVOLVING DATES

To find the number of days between two dates, the user simply needs to subtract one date from the other. However, if you want to express the amount of time in other units such as years or months, the equation becomes more difficult.

Exercise: We wish to find out how long our employees have worked for us in days. To achieve this we will subtract the HIRE DATE from the current date.

The current date is represented by this line of code: =Date()

1. With the “Employees” form open in “Design View” : 2. Click on the “Text Control” icon. 3. Click on an empty section of the form. (An unbound control appears.)

4. Click on the new text control to select it. 5. Open the Properties window . 6. Click on the All tab. 7. Click on the Control Source line. 8. Type the following equation: =Date()-[Hire Date] 9. Press “ENTER” . 10. Click the “Form View” icon to see the result. The answer will be in days.

AccessXP-Forms.doc April 23, 2003 Page 24 of 33 USC - Marshall School of Business AIS – User Support

Expressing Time in Other Units When the date needs to be expressed in units other than days, (months or years for example), the DATEDIFF function can be used to find the difference between two dates.

Syntax: DateDiff(“type of unit”,1st Date,2nd Date)

Type of Unit Description Type of Unit Description yyyy In years (round up) n In Minutes D In days s In Seconds W In Weeks q In quarters Y Day of the year ww The week number H In Hours m In Months

If Hire Date were 9/15/89 and today’s date were 11/21/97, the equations below would yield:

Example: =DateDiff(“m”,[Hire Date],Date()) would yield 98 (months) Example: =DateDiff(“yyyy”,[Hire Date],Date()) would yield 8 (years)

To add text (concatenation) to the end of the equation: . Use the “&” symbol to add text or other calculations to a calculation. . Enclose the text in quotes.

=DateDiff(“m”,[Hire Date],Date()) & ” Months” yields “98 Months” =DateDiff(“yyyy”,[Hire Date],Date()) & ” Years” yields “8 Years”

Note the equation expressing the answer in years is not completely accurate. This is because the units are rounded. If we divide the months by 12, you would get: 8.1666 meaning they have been there slightly over 8 years not just 8.

=DateDiff("m",[Hire Date],Date())/12 would yield: 8.1666 in years

To get more accurate results, you must employ two other operators:

. Int() Returns whole numbers only (what’s to the left of the decimal point and does not round. For example: =Int(7.83) would yield 7. We will use the Int() function to get the years unrounded. . MOD This divides one number by another and returns only the remainder. For example: 5 divided by 2 would be expressed: =5Mod2 and would yield 1. (2 goes into 5 two times with 1 left over). We will use this to get the months. i.e. 98 months divided by 12 has a remainder of 2 months.

Try the following equation:

=Int(DateDiff("m",[Hire Date],Date())/12) & " Yrs., " & DateDiff("m",[Hire Date],Date()) Mod 12 & " Mths."

AccessXP-Forms.doc April 23, 2003 Page 25 of 33 USC - Marshall School of Business AIS – User Support

4) Places a space and the letters Yrs. after the answer.

=Int(DateDiff("m",[Hire Date],Date())/12) & " Yrs., " & DateDiff("m",[Hire Date],Date()) Mod 12 & " Mths."

1) Returns the 2) Divides the 8) Places a 3) Returns only 6) Finds the 7) Divides the difference months by 12 to 5) Places this space the whole numbers difference difference (98) expressed in express the units equation at the letters: Mths. (8). between the by 12 and months. (98) in years. (8.166) end of the first after the hire date and returns the answer. equation. today’s date in remainder (2) months. (98)

AccessXP-Forms.doc April 23, 2003 Page 26 of 33 USC - Marshall School of Business AIS – User Support

USING FORM HEADER & FOOTERS Information placed in a Form Header/Footer will display at the top/bottom of every record. Form Header/Footers differ from Page Header/Footers in that Page Header/Footers only display if the form is printed. Form header/footers are generally used for: . Displaying a title for the form or a company logo at the top of the page. . Placing the current date at the top or bottom of the form. . Placing the field names (Label Controls) at the top of a column of data.

Exercise: We will create a Form Header/Footer for the “Customers” form and display a picture, title, and the current date.

1. Open the “Customers” form created earlier. 2. Go to “Design View” . 3. From the menu, select: VIEW - FORM HEADER/FOOTER

To control how large the header area is, use the mouse to drag the details bar up or down.

4. Adjust the Form Header area to about one or two inches high.

Inserting a Picture in the Form Header Access can display the most common picture formats including BMP, JPG, and GIF. There are several sources of pictures which can be used. If the “Image” icon is used, the pictures must come from a saved picture file. If the “Unbound Object Frame” icon is used, the pictures can come from files, or the clip art gallery.

1. Make sure the Toolbox is displayed. 2. Click on the “Unbound Object Frame” icon: 3. In the Insert Object window, select the option: Create New 4. From the Object Type list, select: Microsoft Clip Gallery 5. From the list, select a picture and click on “Insert” .

Resizing Pictures . To resize a picture, simply click on it and click and drag it by one of the corner black squares. . To move the picture, click and drag it from its center.

AccessXP-Forms.doc April 23, 2003 Page 27 of 33 USC - Marshall School of Business AIS – User Support

Setting Size Mode. The Size Mode determines how the picture fills the surrounding it. There are 3 modes: Clip: The picture retains its original size regardless of the frame size. If the frame is smaller than the picture, parts of the picture will be “clipped” off. Stretch: The picture will “stretch” or distort to fill the frame no matter what the dimensions of the frame are set to. Zoom: The picture will grow larger or smaller as the frame size is adjusted but the picture will always retain its original proportions.

1. Click on the picture to select it. 2. Open the Properties window . 3. Click on the All tab. 4. Click inside the Size Mode box. 5. Click on the down arrow to select the desired size mode. (Try “Stretch”.)

Inserting Text into Headers or Footers To place text anywhere in the form, use the “Label” icon located on the Toolbox :

1. With the form open in “Design View” : 2. Click on the “Label” icon on the Toolbox . 3. Click on the form where the text is to be placed. 4. Type the text and press “ENTER” when complete.

Tips When Working with Text: . Pressing “SHIFT” + “ENTER” will start a new line. . Use the Formatting toolbar to change text size, font, and other attributes. . Use the corner black squares to resize the frame surrounding the text.

Inserting The Date & Time 1. In form “Design View” : 2. From the menu, select: INSERT - DATE & TIME 3. Select the desired Date/Time options. 4. Click on the form to insert the date/time into the form header. 5. Move the control created by dragging it by the frame around it. 6. If necessary, resize the from by dragging it by the black corner handles.

Inserting Page Numbers Page numbers only display in printouts and are placed in Page Header/Footers section. 1. To insert a page number, select: INSERT - PAGE NUMBERS… 2. Select the desired options and click on “Ok” .

AccessXP-Forms.doc April 23, 2003 Page 28 of 33 USC - Marshall School of Business AIS – User Support

TABLE RELATIONS & MULTIFORM ENTRY One of the problems inherent in placing data into separate tables has to do with input and editing. Having to open two or more tables to perform data entry and editing can be tedious and prone to mistakes if the appropriate changes are not made to all tables involved. Fortunately, these problems can be solved with the use of “Table Relations” and “Multiform Entry”.

These two items go hand in hand. You can not use multiform entry unless you have first related the tables involved.

Table Relations: Table relations basically control how tables that have something in common will behave with respect to each other. To relate tables, specific conditions must exist:

Master/Subordinate: When two or more tables are related, there must be at least one “Master” table. When set up to its fullest extent, the master table dictates what can be typed into the other tables which are known as subordinates. (See Referential Integrity below).

Primary Keyed Field: The tables are linked through their common fields. Further, the “Master” table’s linking field must be a primary key field. The subordinate table’s linking fields do not have to be primary keys.

Same Data Type: The linking fields must be of the same data type or similar data types. The following field types are compatible: . Text to Text . Number to Number . AutoNumber to Number (Field size on the number field must be set to Long Integer)

Relating Tables Our eventual goal is to create a form that allows us to place information in both the “Orders” table and the “Order Details” table from a single screen.

. Orders will be the master table . The two tables will be related through their common field of Order ID .

1. Click on the “Relationships” icon from the Standard toolbar. 2. Click on the “Show Table” icon. 3. Select the table “Orders” and click on “Add” . 4. Click on the table “Order Details” and click on “Add” . 5. Click on “Close” to close the Show Table window.

The tables are related by using the mouse to connect the fields which are common to both of the tables. However, the direction the mouse is dragged determines which table is the master and which is the subordinate. Always drag from the master table to the subordinate table.

AccessXP-Forms.doc April 23, 2003 Page 29 of 33 USC - Marshall School of Business AIS – User Support

6. Click on Order ID in the “Orders” table. 7. Then drag it to Order ID in the “Order Details” table.

The Relationships window appears. At this point we could click on “Create” and be ready to create the Main Form/Sub Form, but we will explore some of the other options as well.

A specific Order ID (5 for example) exists only once in the “Orders” table but may exist many times in the “Order Details” table because they may have ordered more than one item in the same order.

Cascade Delete Related Tables: If checked, when a record is deleted from the master table, all related records in the subordinate table are also deleted. For example, if Order ID 5 is deleted in the “Orders” table then all records with Order ID 5 in the “Order Details” table will also be deleted.

Cascade Update Related Tables: If checked, when the linking field in the master table is edited, all of the matching linking fields in the subordinate table are changed as well. For example, if you were to change the Order ID in the “Orders” table from 10 to 300, in the “Order Details” table, all Order ID 10s would also change to 300.

Enforce Referential Integrity: When checked, two or more tables can be related in such a way that data cannot be typed into the subordinate table without first being typed into the master table. For example, we would not be able to enter an Order ID in the “Order Details” table unless we first place the Order ID in the “Orders” table. (This option must be check to enable the other two options.)

8. Select the Following: Enforce Referential Integrity Cascade Update Related Fields Cascade Delete Related Fields 9. Click on “Create” . 10. Save and close the Relationships window.

AccessXP-Forms.doc April 23, 2003 Page 30 of 33 USC - Marshall School of Business AIS – User Support

CREATING A MAIN/SUBFORM A Main/Subform allows you to place information into two or more related tables from one form. We will create a main/subform using Orders and Order Details.

1. In the Database window, click on the Tables tab. 2. Select the “Orders” table. 3. From the menu, select: INSERT - FORM 4. In the New Form window, select: Form Wizard and click “Ok” . 5. Place all fields from “Orders” on the form by clicking the “>>” button.

6. Change tables to “Table: Order Detail” by using the “Tables/Queries” down arrow. 7. Click the double “>>” button to select all fields from “Order Detail” . 8. Click on “Next” .

9. At “How do you want to view your data?”, select: by Orders (This will allow us to use subforms because “Orders” is the master table.) 10. Select: Form with Subform(s) 11. Click on “Next” . 12. For the subform layout select: Datasheet and click on “Next” . 13. Select a style for your form and click on “Next” . 14. Type a name for your main form and subform and click on “Finish” .

AccessXP-Forms.doc April 23, 2003 Page 31 of 33 USC - Marshall School of Business AIS – User Support

USING MAIN/SUBFORMS . The top part of the form contains data from “Orders” and the bottom part contains data from “Order Details”. . Note that the two forms are in sync by order ID. (If you are on Order ID 1 in Orders then Order Detail only shows you records where the Order ID is also 1.

Moving to the Next/Previous Record . Use the Left/Right arrows at the very bottom of your screen to go to the next record. (The ones directly below the subform only affect the subform.) . You can also use “CONTROL” + “PAGE UP” or “CONTROL” + “PAGE DOWN” to move between records.

Starting a New Record Always place data in the Main form before placing it in the subform. 1. To start a new record, click on the “New Record” icon at the bottom of the screen: 2. If necessary, click in the first field of the main form.

As data is entered, the cursor will move through the main form first and then to the sub form. Once the subform is reached, type the data for the subform. Note that the Order ID numbers will be entered automatically for your. If more than one item is being ordered, pressing enter after Quantity will allow you to type more items.

Adding Another Record After a record is complete, to start another new record, either: . Press “CONTROL” + “TAB” on the keyboard or . Press the “New Record” icon at the very bottom of the screen.

AccessXP-Forms.doc April 23, 2003 Page 32 of 33 USC - Marshall School of Business AIS – User Support

Saving & Reusing the Main/Subform When you create and save a Main/Subform, you are actually creating two forms. In our case, they are: “Order Main Form” and “Order Detail Subform” . Both forms are kept under the Forms tab in the main Database window. To use a Multientry Form, simply open the main form and the subform will be automatically pulled into it.

1. From the main Database window, click on the Forms tab. 2. Double click the mainform: “Order Main Form” (The multientry form opens.)

AccessXP-Forms.doc April 23, 2003 Page 33 of 33