[ Team LiB ] Previous Section Next Section

Control Properties and Why to Use Them

Just as reports have properties, so do controls. You can change most control properties at design time or at runtime; this allows you to easily build flexibility into reports. For example, certain controls are visible only when specific conditions are true. The following sections discuss the Format properties of a control and the Data and Other properties of a control.

The Format Properties of a Control

The Format properties of a control allow you to customize the appearance of the control. By using the Format properties, you can modify control attributes such as the back color, font, special effect, and text alignment of the control. You can modify many of the Format properties of selected objects by using the Formatting toolbar (see Figure 17.2). If you prefer, you can set the Format properties in the Properties window (see Figure 17.3). The following sections discuss the Format properties that are available.

Figure 17.2. The Formatting toolbar.

graphics/17fig02.jpg

Figure 17.3. The Format properties of a control.

graphics/17fig03.jpg

Format

The Format property determines how Access displays the data in a control. This property is automatically inherited from the underlying field. If you want the control's format on the report to differ from the underlying field's format, you must set the Format property of the control. It's important to note that the Format options available vary based on the field type of the underlying field. In other words, the Formatting options vary if the underlying field is a Text field versus a Number field.

Caption

The Caption property specifies the text displayed for labels and command buttons. A caption is a string that contains up to 2,048 characters.

Hyperlink Address

The Hyperlink Address property is a string representing the path to a UNC (network path) or URL (Web page). Command buttons, image controls, and labels all contain the Hyperlink Address property. Therefore, if you attach a hyperlink for your company's Web page on a command button, the user can click the button to be taken to that Web page.

Hyperlink SubAddress

The Hyperlink SubAddress property is a string that represents a location within the document specified in the Hyperlink Address property. Command buttons, image controls, and labels all contain the Hyperlink SubAddress property.

Decimal Places

The Decimal Places property defines the number of decimal places displayed for numeric values.

Visible

The Visible property determines whether a control is visible. You can use this property to toggle the visibility of a control in response to different situations.

Hide Duplicates

The Hide Duplicates property hides duplicate data values in a report's Detail section. Duplicate data values occur when one or more consecutive records in a report contain the same value in one or more fields. Figure 17.4 shows a report with the Hide Duplicates property set to its default value, False. Notice the duplicate sales person values. Figure 17.5 shows the same report with the Hide Duplicates property set to True. Notice that the duplicate sales person values no longer appear.

Figure 17.4. The Hide Duplicates property set to False.

graphics/17fig04.jpg

Figure 17.5. The Hide Duplicates property set to True.

graphics/17fig05.jpg

Can Grow and Can Shrink

When the Can Grow property is set to Yes in a control, the control can expand vertically to accommodate all the data in it. The Can Shrink property eliminates blank lines when no data exists in a field for a particular record. For example, if you have a second address line on a mailing label, but there's no data in the Address2 field, you don't want a blank line to appear on the mailing label (see Figure 17.6). You must therefore set the Can Shrink property for the Address2 control to Yes (see the results in Figure 17.7). Likewise, if you have a memo that sometimes has only one line of data but at other times has multiple lines of data, you might want to set the Can Grow property to Yes so that the control grows as necessary.

Figure 17.6. The Can Shrink property set to False.

graphics/17fig06.jpg

Figure 17.7. The Can Shrink property set to True.

graphics/17fig07.jpg

Left, Top, Width, and Height

The Left, Top, Width, and Height properties set the size and position of the controls on a report.

Back Style and Back Color

You can set the Back Style property to Normal or Transparent. When this property is set to Transparent, the color of control. When it is set to Normal, the control's Back Color property determines the object's color.

Special Effect

The Special Effect property adds 3D effects to a control.

Border Style, Border Color, and Border Width

The Border Style, Border Color, and Border Width properties set the physical attributes of a control's border.

Fore Color

The Fore Color property sets the color of the text within a control.

Font Color, Font Name, Font Size, Font Weight, Font Italic, and Font Underline

The Font Color, Font Name, Font Size, Font Weight, Font Italic, and Font Underline properties affect the appearance of the text within a control.

Text Align

The Text Align property sets the alignment of the text within a control. You can set this property to Left, Center, Right, or Distribute. When it is set to Distribute, text is justified (see the Product Name column in Figure 17.8).

Figure 17.8. The Text Align property of a control.

graphics/17fig08.jpg

Reading Order

The Reading Order property determines the visual order in which characters, words, and groups of words are displayed. This property is often used with language-specific editions of Microsoft Access for which the reading order needs to be changed. The default setting is Context; Left-to-Right and Right-to-Left are the other available settings.

Scroll Bar Align

The Scroll Bar Align property specifies the visual placement of the control's vertical scrollbars and buttons. This property works in conjunction with language-specific versions of Access to determine scrollbar placement in either the right-to-left or left-to-right directions. The default setting is System, which lets the operating system determine the scrollbar alignment.

Numeral Shapes

The Numeral Shapes property determines the format for displaying numeric characters. This property works in conjunction with language-specific versions of Access to determine the type of numeric character to display. The default setting is System, which lets the operating system determine the numeric character display format. The other settings are Arabic, National, and Context.

Left Margin, Top Margin, Right Margin, and Bottom Margin

The Left Margin, Top Margin, Right Margin, and Bottom Margin properties are used to determine how far the text within a control prints from the left, top, right, and bottom of the control, respectively. These properties are particularly useful for large controls that contain a lot of text, such as memo on invoices.

Line Spacing

The Line Spacing property is used to control the spacing between lines of text within a control. The Line Spacing property is designated in inches.

Is Hyperlink

The Is Hyperlink property is used to determine whether Access displays the text within a control as a hyperlink. If you set the Is Hyperlink property to Yes and the text within the control is a relevant link, the text serves as a hyperlink. (This is useful only if you save the report in Hypertext Markup Language [HTML] format.)

The Data Properties of a Control

The Data properties of a control (see Figure 17.9), described in the following section, specify information about the data underlying a particular report control. By using the Data properties, you can designate everything from what data displays in a control to whether the data sums as it displays.

Figure 17.9. A control's Data properties.

graphics/17fig09.jpg

Control Source

The Control Source property specifies the field in the report's record source that's used to populate the control. An example would be FirstName. A control source can also be a valid expression.

Input Mask

The Input Mask property assigns specific formatting to any data that is entered into a particular control. For example, you could use the input mask (999) 000-0000 to format data entered as a phone number.

Running Sum

The Running Sum property (which is unique to reports) is powerful. You can use it to calculate a record-by-record or group-by-group total. You can set it to No, Over Group, or Over All. When it is set to No, no running sum is calculated. When it is set to Over Group, the value of the text box accumulates from record to record within the group but is reset each time the group value changes. An example is a report that shows deposit amounts for each state, with a running sum for the amount deposited within the state. Each time the state changes, the amount deposited is set to zero. When this property is set to Over All, the sum continues to accumulate over the entire report.

The Other Properties of a Control

The Other properties of a control include properties, such as those described in the following sections, that don't fit into any other category (see Figure 17.10).

Figure 17.10. The Other properties of a control.

graphics/17fig10.jpg

Name

The Name property provides an easy and self-documenting way to refer to a control in Visual Basic for Applications (VBA) code and in many other situations. You should name every control so that you can easily identify them in queries, code, and so on.

Vertical

The Vertical property is used to determine whether the text within a control is displayed vertically. The default value for this property is No.

Tag

Like the Tag property of a report, the Tag property of a control provides a user-defined slot for the control. You can place extra information in the Tag property.

graphics/clock_icon.gif

A common mistake many Access developers and users make is to give controls names that conflict with Access names. This type of error is very difficult to track down. You need to make sure you use distinctive names for both fields and controls. Furthermore, you should not give a control the same name as a field within its expression. For example, the expression =ContactName & ContactTitle shouldn't have the name "ContactName"; that would cause an #error# message when you run the report. Finally, you shouldn't give a control the same name as its control source. Access gives a bound control the same name as its field, and you need to change this name to avoid problems. Following these simple warnings will spare you a lot of grief!


    [ Team LiB ] Previous Section Next Section