Working with Database Objects

As noted earlier, all the objects in a given database are available for browsing in the database window. In addition, you can visit this location and create a new object with a single click.

The default action for database objects is Open—if you double-click a query icon, for example, Access executes that query and returns its result in Datasheet view. Likewise, double-clicking a form or report icon opens the selected object using the current contents of the database. The effect is the same if you select an object and click the Open button at the top of the database window. (If you select a Report object, the Open button is replaced by the Preview button.)

To view and edit the definition and structure of an object, select any object and click the Design button. In Design view, you can modify the appearance of an object (the fonts and colors on a form, for example), change the table or query from which it derives data, or adjust any of hundreds of other properties for the selected object.

Creating New Objects

To create a new table, query, form, or report, use either of the following techniques:

  • Click the New button on the toolbar at the top of the database window, and select one of the options listed in the resulting dialog box. For example, Figure 33.2 shows the New Form window, listing a variety of wizard and AutoForm tools for creating new forms. In addition, the first entry in the list enables you to go directly to the Design view for a form, and begin your work on a new form object from scratch.


    Figure 33.2.


  • Double-click any of the template icons shown at the beginning of any object list. These icons (which resemble a scratchpad with a key icon on it) offer multiple ways to create a new object, including various wizards and the option to create an object from scratch in Design view. As Figure 33.3 demonstrates, the "canned" choices available from the New Table Wizard can be a useful starting point for business and personal databases.


    Figure 33.3.


When used judiciously, wizards can be enormously helpful in the initial design of any database object. Some wizards are valuable mainly as introductory tools for newcomers to Access, whereas others are consistently useful even for experienced database developers. The Table and Query Wizards, for example, are acceptable for generic databases, but in both cases, Design view represents a far more efficient way to develop individual objects that precisely match specific requirements. On the other hand, the Form and Report Wizards almost always provide an excellent starting point for creating new forms and reports. When working with forms and reports in Design view, it's usually easier to move or modify existing objects than it is to add and edit new controls.

Tip from

When you use a wizard to create the initial version of an Access object, always expect to switch over to Design view to fine-tune the result. A wizard seldom produces the exact object that you need; in particular, the Design views for forms and reports offer direct access to important design elements such as controls, properties, fields, sections, and groups—and enable you to make detailed changes in the appearance and behavior of database objects.


Managing Database Objects

To see a concise list of available options for existing objects, select any object in the database window and use the right-click shortcut menus. Many of these options are also available from buttons on the Access toolbar, or from Access menus. You can open any object to view its content or its design; you can also rename or delete an object, cut or copy it to the Windows Clipboard, or add it to a group of favorite shortcuts for quick access.

Tip from

Unlike Access 97, Access 2000/2002 is "smart" about handling changes to the names of objects. When you rename a field in a table, Access automatically changes any references to that field in queries, forms, reports, and other objects. If you change the name of a field, you shouldn't need to edit any other objects. However, any captions that reference those fields on an existing form or report are unchanged.


Modifying Object Properties

Confusingly, every database object has two sets of properties. If you right-click the object's icon in the database window and choose Properties, you see a bare-bones dialog box that lists the object's General properties. These include the object's name, a text description, the date the object was created, and the date it was last modified. Ho-hum.

By contrast, if you open an object in Design view and click the Properties button, you see a complete list of properties that enable you to control the appearance and behavior of that object. Figure 33.4, for example, shows the Properties dialog box for a form, with all available settings organized by category on five tabs.

Figure 33.4. The Design view properties of a database object include a much more important list of settings that can dramatically change the way you see and use an object.


Tip from

Because the Properties dialog box is modeless, you can leave it open as you work with different objects. The contents of the dialog box always match the currently selected object. Rather than closing and reopening the dialog box as you edit a form, for example, move it off to the side, where you can see its contents without hiding fields or controls on the form. This technique is the most efficient way to adjust the properties of text boxes, subforms, labels, and other parts of a form or report.


Using Expressions in Database Objects

When designing database objects, you don't have to limit yourself to data stored in a table. Extend the power of a database by writing expressions to transform that data on-the-fly. An expression is a combination of symbols, values, and identifiers (the name of a field, control, or property) that calculates a numeric result, combines text, or produces a logical value. Some of the operators you'll use in expressions include everyday arithmetic operators: + (plus), – (minus), * (multiplication), and / (division). Other operators used in expressions might be less familiar.

Expressions are useful throughout Access in many types of objects. The following are a few examples:

  • In a query, you might include calculated fields, in which each entry is the result of an expression. The operands in the expression might include other fields in the same table or in a related table. You can use an expression to calculate a due date for an invoice ([SaleDate]+30) or to produce a total, such as [Qty]*[UnitPrice]. You supply the expression for the column and Access performs the operation for each record in the resulting datasheet.

→ Access performs operations for each record; see "Creating and Applying Filters".

  • The design of an individual field in a table might include a validation rule, which specifies a range of acceptable entries in the field itself. You might create a rule that prohibits users from entering a value in the SaleDate field that is in the future or more than 30 days in the past, for example. If a given data entry does not meet the condition expressed in the rule, Access rejects the entry. To create a validation rule, write an expression that will evaluate to True or False for each new entry. If the result is True, the entry is accepted; if False, it is not.

→ To learn more about creating validation rules, see "Defining Validation Rules".

  • A criterion is an expression that you can use to select a target group of records for a particular operation. Any record that meets the criterion becomes part of the group; a record that does not meet the criterion is excluded from the group. Again, a criterion expression results in a value of True or False for each record examined.

In these and other examples, you use specific types of operators in expressions to produce the appropriate types of values. The following categories of operators are commonly used:

  • The Arithmetic Operators— In addition to the familiar four (+, -, *, and /), these include ^ (exponentiation), (integer division), and MOD (the remainder from the division of two integers). These operators require numeric operands and produce numeric results.

  • The Comparison Operators— < (less than), <= (less than or equal), <> (not equal), > (greater than), >= (greater than or equal), and Between (expressing a numeric range). These operators produce logical values, indicating whether a comparison is True or False.

  • The Logical Operators— These take logical operands and produce logical results. For example, a logical operator might combine the values of two comparison expressions. Among these operators, the most commonly used are And (true if both operands are true), Or (true if one or both operands are true), and Not (produces the opposite value of an operand). Other logical operators include Eqv (true if both operands have the same value), Imp (true if the first operand is true and the second is false), and Xor (true if the operands have different values).

  • A String Operator— The & symbol represents concatenation, the process of combining two text values.

Because expressions are so central to the design of database objects, Access provides a special tool called the Expression Builder to help you write expressions quickly and accurately. As you can see in Figure 33.5, the Expression Builder contains buttons representing operands, along with other categories of identifiers that might become part of an expression.

Figure 33.5. Use the Expression Builder to build an expression one element at a time by clicking the operand buttons and selecting from categories of identifiers.


You can generally open the Expression Builder by clicking the Build button (labeled …) next to the box where the expression is entered. Or, right-click inside the box and choose Build from the shortcut menu.

Tip from

When working with forms and reports, use the Expression Builder to quickly add page numbers and date/time information. Scroll to the bottom of the left column and select Common Expressions to see these useful shortcuts.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.1.239