Creating a database form

From Apache OpenOffice Wiki
< Documentation‎ | OOo3 User Guides‎ | Getting Started
Revision as of 21:35, 14 July 2018 by Sancho (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Databases are used to store data. But, how is the data put into the database? Forms are used to do this. In the language of databases, a form is a front end for data entry and editing.

A simple form consists of the fields from a table.

Fields of a simple form.

More complex forms can contain much more. These can contain additional text, graphics, selection boxes and many other elements. The figure below is made from the same table with a text label (Fuel Purchases), a list box placed in PaymentType, and a graphic background.

Simple form with additions.

Top of page

Using the Wizard to create a form

We will use the Wizard to create two forms: CD Collection and Vacations. The CD Collection form will be a simple form, while the Vacations form will contain a form and a subform. We will create the Vacations form with its subform and let you modify the CD Collection form using the same process.

In the main database window, click the Form icon. Double-click Use Wizard to Create Form to open the wizard. Simple forms require only some of these steps, while more complex forms may use all of them.

Top of page

Step 1: Select fields.

  1. Under Tables or queries, select Vacations as the table. Available fields lists the fields for the Vacations table.
  2. Click the right double arrow to move all of these fields to the Fields in the form list. Click Next.
Form Wizard steps.

Top of page

Step 2: Set up a subform.

Since we have already created a relationship between the Fuel and Vacations tables, we will use that relationship. If no relationship had been defined, this would be done in step 4.

  1. Click the box labeled Add Subform.
  2. Click the radio button labeled Subform based upon existing relation.
  3. Fuel is listed as a relation we want to add. So, click Fuel to highlight it, as shown below. Click Next.
Adding a subform.

Correction for Version 3.2.1 Step 2. Set up a subform - Select 'Subform based on manual selection of fields'. This will allow you to access Step 4. Get joined fields.

Top of page

Step 3: Add subform fields.

This step is exactly the same as step 1. The only difference is that not all of the fields will be used in the subform.

  1. Select Fuel under Tables or queries.
  2. Use the >> button to move all the fields to the right.
  3. Click the FuelID field to highlight it.
  4. Use the < button to move the FuelID to the left.
  5. Click Next.
Selecting fields of a subform.

Top of page

Step 4: Get joined fields.

This step is for tables or queries for which no relationship has been defined. Since we want to list all expenses by the day they occur in both the form and subform, we will join the Date fields of these two tables.

Selection of joined subform and main form fields.
  1. Select Date from the First joined subform field dropdown list. This is the Date field in the Fuel table. This is not the Primary key for the Fuel table, but it is known as a Foreign key.
  2. Select Date from the First joined main form field dropdown list. This is the Date field in the Vacations table. This is the Primary key for the Vacations table. Click Next.
Documentation note.png It is possible to create a relationship between two tables that is based upon more than one pair of fields. How to do that and why is discussed in the Base Guide (not yet written).
Documentation caution.png When selecting a pair of fields from two tables to use as a relationship, they have to have the same field type. That is why we used the Date field from both tables: both their field types are Date[DATE].

Whether a single pair of fields from two tables are chosen as the relationship or two or more pairs are chosen, certain requirements must be met for the form to work.

  • No field from the subform can be the Primary key for its table. (FuelID cannot be used.)
  • Each pair of joined fields must have the same file type.
  • One of the fields from the main form must be the Primary key for its table. (Date would have to be used.)

Top of page

Step 5: Arrange controls.

Documentation note.png Each control in a form consists of two parts: label and field. This step in creating the form determines where a control's label and field are placed in relationship with each other. The four choices from left to right are Columnar left, Columnar - Labels on top, As Data Sheet, and In Blocks - Labels Above.
  1. Arrangement of the main form: Click Columnar - Labels on top. The labels will be placed above their field.
  2. Arrangement of the subform: Click As Data Sheet. (The labels are column headings and the field entries are in spreadsheet format.) Click Next.
Control arrangements.

Top of page

Step 6: Set data entry.

Unless you have a need for any of these entries to be checked, accept the default settings. Click Next.

Top of page

Step 7: Apply styles.

  1. Select the color you want in the Apply Styles list. (I chose the beige which is Orange 4 in the Color table.)
  2. Select the Field border you want. (I prefer the 3-D look. You might want to experiment with the different possible settings.)
  3. Click Next.

Top of page

Step 8: Set name.

  1. Enter the name for the form. In this case, it is Fuel.
  2. Click the circle in from of Modify the form. (This circle is called a radio button.)
  3. Click Next. The form opens in Edit mode.

Top of page

Modifying a form

We will be moving the controls to different places in the form and changing the background to a picture. We will also modify the label for the PaymentType field as well as change the field to a list box.

First, we must decide what we want to change and to what. The discussion will follow this ten step outline.

  1. The Date field in the main form needs a dropdown capability. It also needs to be lengthened to show the day of the week, month, day, and year.
  2. Shorten the length of the payment fields (all fields containing the word payment).
  3. The controls need to be move into groups: food, fuel subform, and miscellaneous.
  4. Some of the labels need to have their wording changed. Some single words should be two words. Some abbreviations should be used if possible (Misc. for miscellaneous).
  5. The widths of several fields and labels need to be changed. Only Lunch, Supper, Motel, and Tolls have acceptable lengths. But for a better appearance, changes will be made to these as well.
  6. All the fields whose label ends in Payment will be replaced with a list box. This box contains the entries from the Payment Type table.
  7. The Note field needs to be lengthened vertically and a scroll bar added. It also needs to be moved.
  8. Changes need to be made in the Date and PaymentType columns of the subform that are similar to the changes in the main form.
  9. Headings need to be added for each group in the main form.
  10. The background needs to be changed to a picture. Some of the labels will have to be modified so that they can be read clearly. The font color of the headings needs to be changed as well.

Here are some pointers that we will be using in these steps. The controls in the main form consists of a label and its field. Sometimes we want to work with the entire control, and other times we want to work with only the label or the field. There are times when we want to work with a group of controls.

  • Clicking a label or field selects the entire control. A border appears around the control with eight green handles. You can then drag and drop it where you want.
A selected control.
  • Control+click a label or field selects only the label or the field.
  • By using the Tab key, you can change the selection from the field to the label or the label to the field.
Selecting a field of a control.
  • Moving a group of controls is almost as easy as moving one of them.
  1. Click the field of the top left control to be moved, to select it.
  2. Move the cursor to just above and to the left of the selected control.
  3. Drag the cursor to the bottom right of the group of controls and release the mouse button.
  4. As you drag the cursor, a dashed box appears showing what is contained in your selection. Make sure it is big enough to include the entire length of all the controls.
  5. When you release the mouse button, a border with its green handles appears around the controls you selected.
  6. Selecting multiple controls.
  7. Move the cursor over one of the fields. It changes to a double arrow.
  8. Drag the group of controls to where you want them.
  9. Double arrow

Before changing the Date field, we will move the Lunch and Tolls controls to the right 5 cm (2 inches).

Tip.png When either changing a size or moving a control, two properties of the Form Design toolbar should be selected: Snap to Grid, and Guides when Moving. Your controls will line up better, and an outline of what you are moving moves as the cursor moves.

You should also have both rulers active (Tools > Options > Writer > View). Since the form is created in Writer, that is where you have to make sure both horizontal and vertical rulers have a check in the box in front of them.

Documentation note.png I use centimeters when making changes in a form because centimeters are more accurate than inches. When moving controls (fields and their labels), placement is also more accurate. You can change your rulers from inches to centimeters by right-clicking each ruler and selecting centimeter from the context menu. You do not have to understand what centimeters are. You only have to match your controls, labels, or fields to specific numerals on a ruler.

Top of page

Step 1: Change the Date field.

  1. Control+click the Date field to select it.
  2. Move the cursor over the middle green handle on the right side. It should change to a single arrow.
  3. Single arrow.
  4. Hold the left mouse button down as you drag the cursor to the right until the length is 6 cm. The vertical dashed line is lined up with the 6. (This is approximately 2.4 inches.) Release the mouse button.
  5. Click the Control icon in the Form Controls toolbar. It is the one circled in red. The Properties: Date Field window opens. Each line contains a property of the field.
  6. Form Controls toolbar.
    1. Go to the Date format property. This is a dropdown list with Standard (short) as the default setting.
      • Click the default Standard (short) to open the list.
      • Click the Standard (long) entry to select it.
    2. Scroll down to the Dropdown property. Its default setting is No. It is also a dropdown list.
      • Click the default No setting to open the list.
      • Click Yes to select it.
      • Click on the 'x' in the upper right hand corner of the control box to close it. Your changes will automatically be saved.
Tip.png To see what the Date field will look like, click the Form Mode On/Off icon (the second icon from the left in the figure above). You can do this any time you want to see the form with the changes you have made.

Top of page

Step 2: Shorten the width of a field.

All of the fields whose label contains the word payment are too wide. They need shortening before the controls are moved.

  1. Control+click the BPayment field.
  2. Move the cursor over the middle green handle on the right. The cursor becomes a single arrow.
  3. Drag the cursor to the left until the field is 2.5 cm wide (1 inch).
  4. Repeat these steps to shorten these fields: Lpayment, SPayment, SnPayment, Mpayment, and MiscPayment.
Selecting a field.
Tip.png If you have the Snap to Grid and Guides when moving icons selected in the Design Format toolbar, you will see how wide the field is as you shorten it.

Top of page

Step 3: Move the controls to group them by category.

We want to move the controls so that they look like the figure below.

Positioning of controls.
  1. Click the first control you want to move. A border appears around the control with eight green handles.
  2. Move the cursor over the label or field of the control. It becomes a double arrow.
  3. Drag and drop the control to where you want it.
  4. Use the same steps to move the rest of the controls to where they belong.
Documentation caution.png Do not use Control+click when moving a field. It moves either the field or the label but not both. To move both, use a mouse click and drag to the desired spot.
Documentation note.png The only way to learn to do these two steps well is to practice them. Another way exists which will place controls where you want them, but this is a more advanced feature and will be explained in the Base Guide.

Top of page

Step 4: Change the label wording.

Field names need to be single words. However, the labels for the fields can be more than one word. So, we will change them. To do so, we will be editing the text in the label.

  1. Control+click the SnackNo label. Do one of the following:
    1. Right-click the SnackNo label.
      • Select Control from the context menu. The window that opens is labeled Properties: Label field. It contains all of the properties of the selected label.
      • Context menu.
      • In the Label selection, click between the k and N in SnackNo.
      • Use the spacebar to make SnackNo into two words.
      • Place a . (period) after the No.
      • Close the Properties window.
      • Multi-word label.
    2. Or, click the Control icon in the Form Controls toolbar. The Properties window opens. The rest of the steps are the same.
    3. Form Controls toolbar.
  2. Use the same procedure to change these labels as well: BPayment to Payment, LPayment to Payment, SPayment to Payment, Miscellaneous to Misc., SnackCost to Snack Cost, MPayment to Payment, MiscPayment to Misc. Payment, and MiscNotes to Misc. Notes.
Tip.png All of the listings in the Properties window can be modified by you. For example, by changing the Alignment from Left to Center, the word or words in the label are centered within the Label. When you have some time, you might want to experiment with different settings just to see the results you get.

Top of page

Step 5: Change the widths of the labels and fields.

We want the following controls to be 2 cm wide (0.8 inches): Breakfast, Lunch, Supper, Odometer, Snack No., Tolls, Snack Cost, Motel, and Misc. All of the payment fields were changed in step 2, but Misc. Payment needs to be changed to 3 cm (1.2 inches).

  1. Click Breakfast. The border around it appears with eight green handles.
  2. Move the cursor over the middle green handle on the right. The cursor changes into a single arrow.
  3. Drag and drop the cursor to the left to shorten the control or to the right to lengthen the control. Use the guide lines to determine the width.
  4. Repeat for the other listed controls.

Top of page

Step 6: Replace fields with other fields.

We want to replace the PaymentType field with a List Box. Then we can choose the type of payment from the Payment Type table rather than having to manually enter the type. In my case, each of my payment types begins with a different letter. If I enter the first letter of the payment type, the rest of the word automatically appears. I can then go to the next field.

  1. Control+click the Payment field for Breakfast. The green handles appear around the field but not around the Label.
  2. Selecting a field of a control.
  3. Right-click within the green handles and select Replace with > List Box. (The figure below shows the list of replacement fields.)
  4. Replacement fields.
  5. Click the Control icon in the Form Controls toolbar to open the Properties window.
  6. On the General tab, scroll down to the Dropdown selection. Change the No to Yes in this dropdown list.
  7. Dropdown list open to reveal choices.
  8. Click the Data tab.
  9. Type of list contents dropdown list.
    • Type of list contents is a dropdown list. Change it to Sql.
    • Type the following exactly as it is in the List contents box:
      SELECT "Type", "Type" FROM "Payment Type"
    • List content for payment type fields.
      Tip.png You should be able to copy and paste SELECT "Type", "Type" FROM "Payment Type" from above directly into the List content box. Just make sure you copy from the S in SELECT to the double quotation mark after the phrase Payment Type and no more than this.

      Documentation note.png What you wrote is called an SQL command. The words SELECT and FROM are written in capital letters because they are commands. When the command SELECT is used, it requires a field name within quotation marks and then the field's alias, also within quotation marks. In this case, the field and its alias are the same. The FROM command requires the name of the table which contains the field. Single-word table names do not require quotation marks, but multiple-word table names do.
    • Repeat these steps for the payment fields for Lunch, Supper, Motel, Snacks, and Misc. The main form should look like the figure below as far as where the controls are located. It also shows what the Note control should look like. Those changes are explained in the next step.
    Position of controls in main form.
  10. Close the Properties window.

Top of page

Step 7: Change the Note field.

We want the Note control where it is located in the figure above. Since it has a memo field type, it needs a vertical scrollbar for additional text space if desired.

  1. Control+click the Note field. The green handles should surround the Note field but not its label.
  2. Click the Control icon to open the Properties window.
  3. Scroll down to the Text type setting. Change the selection from Single-line to Multi-line
  4. Scroll down to the Scrollbars setting. Change the selection from None to Vertical in this dropdown list.
  5. Scrollbar selections in Properties window.
  6. Close the Properties window.
  7. Lengthen the Note field.
    • Move the cursor over the middle green handle at the bottom of the Note field. It becomes a vertical single arrow.
    • Drag the cursor down until the length is 6 cm (2.4 inches).

Top of page

Step 8: Change labels and fields in a subform.

The Date column needs to be widened. The field in the PaymentType column needs to be changed to a list box. The label for PaymentType column needs to be two words.

Change the PaymentType column:

  1. Right-click the label PaymentType to open a context menu.
  2. Choices for modifying a control in a subform.
  3. Select Replace with, and then select List box from the context menu.
  4. Again right-click the label PaymentType to open a context menu.
  5. Select Column. This opens the Properties window.
  6. In the Label box, change PaymentType to Payment Type.
  7. Properties window for control in a subform.
  8. Click the Data tab.
  9. From the Type of list contents dropdown list, select sql.
  10. Type the following exactly as it is written:
    SELECT "Type", "Type" FROM "Payment Type"
  11. Close the Properties window.
Tip.png Step 6: Replace fields with other fields, beginning with part 5, contains more detailed instruction.

Top of page

Step 9: Add headings to groups.

  1. Make sure the cursor is in the upper left corner. If it is not, click in that corner to move it there.
  2. Use the Enter key to move the cursor to the fifth line from the top.
  3. Change the Apply Styles dropdown list from Default to Heading 2.
  4. Apply Styles list.
  5. Use the spacebar to move the cursor to where you want the heading to start.
  6. Type the heading Meals.
  7. Use the spacebar to move the cursor to the center of snack area.
  8. Type the heading Snacks.
  9. Use the Enter key to move the cursor between the Supper control and the subform.
  10. Use the spacebar to move the cursor to the center of the subform.
  11. Type the heading Fuel Data.
Documentation note.png If you know how to use styles, you can open the Styles and Formatting window using F11. Right-clicking the Heading 2 paragraph style allows you to modify the appearance of all three headings. See the Writer Guide Chapter 6 (Introduction to Styles).

Top of page

Step 10: Change the background of a form.

The background for a form can be a color, or a graphic (picture). You can use any of the colors in the Color Table at Tools > Options > > Colors. If you know how to create custom colors, you can use them. You can also use a picture (graphic file) as the background. We will use a picture found in OOo: sky.gif. Since the background is dark in places, many of the labels and headings will need changing in order to be seen.

Background graphic.
  1. Select the labels of the top row of controls.
    1. Control+click the Date label.
    2. Control+shift+click the rest of the labels of the top row. The border will gradually grow to the right as you do this until all the labels are enclosed in it.
    3. Selecting multiple labels at one time.
    4. Click the Control icon in the Design Form toolbar to open the Properties window.
    5. Change the Background selection from Default to Light cyan. (This is a dropdown list.)
  2. Select the other labels in the same way and then change their background color.
  3. Close the Properties window.
  4. Documentation note.png I have chosen to use Light cyan as the background color for my labels. You are free to choose whatever color you wish, including a custom color you earlier created.
  5. Press the F11 key to open the Styles and Formatting window. Notice the left icon has a black outline around it. This is the Paragraph Styles icon. Below it is a list of paragraph styles including headings.
  6. Top portion of the Styles and Formatting window.
    1. Right-click Heading 2 and select Modify from the context menu.
    2. On the Paragraph Style dialog, click the Font Effects tab.
    3. Tabs of the Paragraphs: Heading 2 window.
    4. Change the Font color dropdown list to Light cyan.
    5. Left side of Font Effects tab.
    6. Click OK to close the Paragraph Style: Heading 2 dialog.
    7. Press the F11 key to close the Formatting and Styles window.
    8. Tip.png Learning how to use styles can be very helpful at times. By using styles, we changed the font color for all three headings at one time. There are other methods of changing the font color, but they require repeating the same steps for each heading.

  7. Right-click the background and select Page from the context menu.
  8. Click the Background tab.
  9. Background tab of Page Styles.
    1. Change the As dropdown list from Color to Graphic.
    2. Search for this file: sky.gif. It is located in the Gallery folder of OOo.
    3. Click the Browse button in the File section. Browse to the folder containing sky.gif.
    4. Select this file and click Open.
    5. In the Type section, select Area.
    6. Click OK to close the Page Style: Default window.

The form should look like the figure below.

Finished form.

Top of page

Step 11: Change the tab order.

The Tab key moves the cursor from field to field. This is much easier to do than to click each field to enter data into it. It also permits us to group our expenses into areas before we begin entering data. For example, all of our meal receipts can be grouped together as can our snacks and also our fuel purchases.

  1. Control+click the Date field.
  2. Click the Form Design icon in the Form Controls toolbar to open the Form Design toolbar.
  3. Form Controls toolbar with Form Design icon circled.
  4. Click the Activation Order icon.
  5. Form Design toolbar with Activation Order icon circled.
  6. Rearrange the order of the fields in the Tab Order window.
  7. Tab Order window.
    • Find the txtMPayment listing near the bottom of the list and click it.
    • Click the Move Up button until txtPayment is just below fmtMotel.
    • Use the same two steps to put the fields in the same order as shown below.
    • Tab order for the main form.
    • Click OK.
  8. Save and close the form.
  9. Save the database.

Top of page

Creating forms in Design View

This method requires using the Form Controls and Form Design toolbars extensively. These techniques are beyond the scope of this document. Instructions for creating forms using Design view will be described in the Database Guide.

Top of page

Creating subforms in Design View

Again, this is beyond the scope of this document. Creation of subforms in Design View will be described in the Database Guide.

Top of page

Content on this page is licensed under the Creative Common Attribution 3.0 license (CC-BY).
Personal tools