What Control Properties Are Available and Why Use Them?
Just as reports have properties, so do controls. You can change most control properties at design time or at runtime, allowing you to easily build flexibility into your reports. For example, certain controls are visible only when specific conditions are true.
The Control's Format Properties
You can modify several formatting properties of the selected objects using the formatting toolbar. If you prefer, you can set all the properties in the Properties window. The following are the Format properties of a report control:
- Format
Determines how the data in the control is displayed. 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. - Caption
Specifies the text displayed for labels and command buttons. A caption is a string containing 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. - Hyperlink SubAddress
The Hyperlink SubAddress property is a string representing 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
Defines the number of decimal places displayed for numeric values. - Visible
Determines whether a control is visible. In many cases, you will want to toggle the visibility of a control in response to different situations. - Hide Duplicates
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. - Can Grow, Can Shrink
The Can Grow property, when set to Yes, allows a control to 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. - Left, Top, Width, Height
These properties set the size and position of the controls on a report. - Back Style, Back Color
The Back Style property can be set to Normal or Transparent. When set to Transparent, the color of the report shows through to the control. When 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, Border Width
These properties set the physical attributes of a control's border. - Fore Color
This property sets the color of the text within the control. - Font Color, Font Name, Font Size, Font Weight, Font Italic, Font Underline
The border properties affect the control's border, but the font properties affect the appearance of the text within the control. - Text Align
Sets the alignment of the text within the control. It can be set to Left, Center, Right, or Distribute. When set to Distribute, text is justified. - Reading Order
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, where 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
Specifies the visual placement of the control's vertical scrollbars and buttons. This property also works in conjunction with language-specific versions of Access to determine scrollbar placement in either the right-to-left or left-to-right direction. The default setting is System, which lets the operating system determine the scrollbar alignment. - Numeral Shapes
Determines the format for displaying numeric characters. This property also 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 include Arabic, National, and Context. - Left Margin, Top Margin, Right Margin, Bottom Margin
These properties are used to determine how far the text within the control prints from the left, top, right, and bottom of the control. These properties are particularly useful for large controls containing a lot of text, such as a memo or an invoice. - Line Spacing
Used to control the spacing between lines of text within a control. The Line Spacing property is designated in inches. - Is Hyperlink
Used to determine whether the text within the control is displayed as a hyperlink. If the Is Hyperlink property is set to Yes, and the text within the control is a relevant link, the text will serve as a hyperlink. (This is useful only if you save the report in HTML format.)
The Control's Data Properties
The Data properties of a control specify information about the data underlying a particular report control.
- Control Source
Specifies the field in the report's record source that's used to populate the control. A control source can also be a valid expression. - Input Mask
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 the data entered as a phone number. - Running Sum
The Running Sum property (unique to reports) is quite powerful. It can be used to calculate a record-by-record or group-by-group total. It can be set to No, Over Group, or Over All. When 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 set to Over All, the sum continues to accumulate over the entire report.
The Other Control Properties
The Other properties of a control designate properties that don't fit into any other category, such as:
- Name
The Name property gives you an easy and self-documenting way to refer to the control in VBA code and in many other situations. You should name all your controls. Naming conventions for report controls are the same as those for form controls. Refer to Appendix B, "Naming Conventions," for more detailed information. - Vertical
Used to determine whether the text within the 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 gives you a user-defined slot for the control. You can place any extra information in the Tag property.
CAUTIONA common mistake many developers make is giving controls names that conflict with Access names. This type of error is very difficult to track down. Make sure you use distinctive names for both fields and controls. Furthermore, don't give a control the same name as the name of a field within its expression. For example, the expression =ClientName & Title shouldn't have the name ClientName; that would cause an #error# message when the report is run. Finally, don't give a control the same name as its control source. Access gives bound controls the same name as their fields, so you need to change them to avoid problems. Following these simple warnings will spare you a lot of grief!