By default, text-based controls align their strings to the left. To support the allignment of text, controls are equipped with a property named TextAlign. Its values can be:
The font is the most common object that controls how the words on an object appear. To support fonts, each control is equipped with various properties. For example, to specify the font used on a control, access its FontName property, which represents the name of the font you want to use. Then assign the desired font to it. Here is an example: Private Sub cmdChangeProperty_Click() txtLastName.FontName = "Rockwell" End Sub
Besides the font name, you can specify the style. This controls whether the characters appear in bold, in italic, or underlined. The properties used to control these aspects are FontItalic and FontUnderline, respectively. Each of these properties is Boolean. If you set the property to True, its corresponding style applies. Here are examples: Private Sub cmdChangeProperty_Click() txtLastName.FontName = "Rockwell" txtLastName.FontItalic = True txtLastName.FontUnderline = True End Sub
To make the characters of a control appear thick, you can apply a weight to it. The primary property you can use is called FontBold. This is a Boolean property. If you assign the True value to it, the characters of the value of a control appear bold. Here is an example: Private Sub cmdChangeProperty_Click() txtLastName.FontName = "Rockwell" txtLastName.FontBold = True End Sub If you want, you can make the boldness appear with more style. To do this, access the FontWeight property of the control and assign one of the following values:
Beside the name and the style, you may want to control the size of characters of a control. To support this, their classes are equipped with a property named FontSize. After accessing this property, assign the desired integer to it. Here is an example: Private Sub cmdChangeProperty_Click() txtLastName.FontName = "Rockwell" txtLastName.FontBold = True txtLastName.FontItalic = True txtLastName.FontUnderline = True txtLastName.FontSize = 12 End Sub
To enhance the appearance of characters on a control, you can use a particular color of your choice. To support this, the controls are equipped with a property named ForeColor. To specify the color for the characters, assign either a long constant or a color to the RGB() function to this property. Here is an example: Private Sub cmdChangeProperty_Click() ' Use a red color txtLastName.ForeColor = RGB(255, 0, 0) End Sub
By default, the background of text-based controls appears white. If you want, you can change it. To do this, access the BackColor property of a control and assign either a constant integer or a call to the RGB() function to it. Here is an example: Private Sub cmdChangeProperty_Click() txtLastName.BackColor = 795734 End Sub
During design, Microsoft Access applies a default border to the controls you add. If you want, you can specify a specific color to a control or to the controls on a form or report. To support this, each control is equipped with a property named BorderColor. To control it, assign the desired color to this property. Here is an example: Private Sub cmdChangeProperty_Click() txtLastName.BorderColor = 795734 End Sub
You can control the borders of a control to look a certain way. This the job of special effects:
To apply special effects to a control, access its SpecialEffects property and assign one of the following values:
You can assign the value or the corresponding constant integer. Here is an example: Private Sub cmdChangeProperty_Click() txtLastName.SpecialEffect = acEffectEtched End Sub
By default, the border of a control appears as a line. You can make it appear with a style. To do this, access its BorderStyle property and assign one of the following values:
A label is a static control that displays fixed text to the user. The user cannot change the text of a label but can read it. A label can be used by itself to display text. In many other cases, a label is used to display text about anything appropriate. To add a label to a form or report, display the form or report in Design View. In the Controls section of the Design tab of the Ribbon, click Label and click the form or report. You must also type the title of the label (if you don't and click somewhere else, the label would disappear). The label control is an object of type Label. To programmatically create a label, call the CreateConotrol() function and pass the ControlType as acLabel. The first argument is the name of the form or report on which the label will be positioned. Here is an example: Private Sub cmdCreateControl_Click() Dim ctlFirstName As Control Set ctlFirstName = CreateControl("Exercise", _ AcControlType.acLabel) Set ctlFirstName = Nothing End Sub Of course, the third argument is the section of the form or report where the label will be positioned. You can pass the fourth argument as the name of the form or report on which the label will be positioned. That is, the first and the fourth argument can be the same. Here is an example: Private Sub cmdCreateControl_Click() Dim ctlFirstName As Control Set ctlFirstName = CreateControl("Exercise", _ AcControlType.acLabel, _ AcSection.acDetail, _ "Exercise") Set ctlFirstName = Nothing End Sub
A label cannot be used directly for data entry. That is, you cannot link a label to a column of a table. A label is only used to display static text that cannot be changed. As a consequence, if you are visually creating a label, you cannot specify its Control Source in the Properties window. If you are programmatically creating the label, pass the fifth argument as an empty string. Probably the most important and the most obvious characteristic of a label is the text it displays. The text is the label's Caption. If you click the Label on the Ribbon and click on the form or report, you must first define its caption. If a label already has a caption, there are various ways you can edit it. For example, can click it and click again to put it into edit mode, then edit its string. You can also double-click it to access its Properties window and change its Caption property. If you are programmatically creating the label, to specify its caption, access the control's Caption property and assign the desired string to it. Here is an example: Private Sub cmdCreateControl_Click() Dim ctlFirstName As Control Set ctlFirstName = CreateControl("Exercise", _ AcControlType.acLabel, _ AcSection.acDetail, _ "Exercise") ctlFirstName.Caption = "First Name:" Set ctlFirstName = Nothing End Sub The appearance of a label is visibly controlled by its font characteristics. The Font name, also called its face, is the name of the font as defined by the operating system. There are various ways you can define the font characteristics of a control like the label. After selecting it while the form or report is in Design View, on the Ribbon, you can click Home or Design, then use the buttons in the Font section to specify the font characteristics. You can also access the Properties window of the label and modify the desired font properties. The position of a label is controlled by its Top and Left properties. The Top property defines the measure from the top left corner of the section where the label is positioned, to the top left corner of the label itself. There are two main ways you can set the position of a label. On the Properties window, you can change the values of the Top and Left properties. On the other hand, you can place your mouse on the top left corner of the label until the mouse pointer turns into a pointing finger. Then click and drag in the desired direction. If you are programmatically creating the label, to specify its size, pass a sixth argument as its left position and/or a seventh argument as its top position. Here are examples: Private Sub cmdCreateControl_Click() Dim ctlFirstName As Control Set ctlFirstName = CreateControl("Fundamentals", _ AcControlType.acLabel, _ AcSection.acDetail, _ "Exercise", _ "", _ 320, 260) ctlFirstName.Caption = "First Name:" Set ctlFirstName = Nothing End Sub The size of a label is controlled by its Width and Height properties. Although the dimensions are closely related to the font characteristics, they can be independently defined. There are two main ways you can resize a label, which is equivalent to changing its dimensions. To set your own dimensions, in the Format tab of the Properties window of the label, change the values of the Width and Height properties. Unless you plan to show the background color of a label, probably the best way to resize a label is to make it adjust to the dimensions depending on the font size and the total characters width. To do this, position the mouse on one of the label's handle and double-click. The label's width and height would be set to accommodate its caption. If you are programmatically creating the label, to specify its size, pass an 8th argument as its width and/or a ninth argument as its height. Here are examples: Private Sub cmdCreateControl_Click() Dim ctlFirstName As Control Set ctlFirstName = CreateControl("Fundamentals", _ AcControlType.acLabel, _ AcSection.acDetail, _ "Exercise", _ "", _ 320, 260, 1200, 260) ctlFirstName.Caption = "First Name:" Set ctlFirstName = Nothing End Sub
A text box is a Windows control used to get or display text. At its most regular use, a text box serves as a place to fill out and provide information. You can also use it only to display text without allowing the user to change its content. Like most other controls, the role of an edit box is not obvious at first glance; that is why it should be accompanied by a label that defines its purpose. From the user’s standpoint, a text box is named after the label closer to it. Such a label is usually on the left or the top side of the corresponding edit box.
To add a text box to your project, from the Controls section of the Ribbon, you can click the Text Box control and click a section of the form or report. Unless you have a good alternate reason, most of your text boxes will be placed in the Detail section. Some text boxes used in expressions can be placed in another section. By default, placing a text box on the form or report also adds a corresponding label to its left. To programmatically create a text box, call the CreateConotrol() function and pass the ControlType as acTextBox. The first argument is the name of the form or report on which the text box will be positioned. The third argument specifies the section where to position the text box. Here is an example: Private Sub cmdCreateControl_Click() Dim txtFirstName As Control Set txtFirstName = CreateControl("Exercise", _ AcControlType.acTextBox, _ AcSection.acDetail) Set txtFirstName = Nothing End Sub
As mentioned already, a text box can be used to display text, just like a normal control in a Microsoft Windows application. In a database, a text box is typically used to display the value of a field of a table. To make this possible, after specifying the Record Source of its form or report and after visually adding a text box, set its Control Source to the desired field of the table. If you are programmatically creating the text box, to specify the field it must link to, pass the name of the table as the fourth argument and pass the name of the field as the fifth argument. This could be done as follows: Private Sub cmdCreateControl_Click() Dim txtFirstName As Control Set txtFirstName = CreateControl("Exercise", _ AcControlType.acTextBox, _ AcSection.acDetail, _ "Students", "FirstName") Set txtFirstName = Nothing End Sub If you are creating a text box that will not link to a field of a table, you can pass the fourth argument as either the same as the first argument or an empty string, and then pass the fifth argument also as an empty string. Like every control on a form or report, the dimensions of the text box are controlled by its Width and Height properties. You can change these in the Properties window of the text box. You can also specify them if you are programmatically creating the control. Here are examples: Private Sub cmdCreateControl_Click() Dim txtFirstName As Control Set txtFirstName = CreateControl("Exercise", _ AcControlType.acTextBox, _ AcSection.acDetail, _ "Exercise", _ "", 1600, 260) Set txtFirstName = Nothing End Sub The position of a text box is controlled by its Top and Left properties. You can change them in the Properties window of the text box. You can also specify them when programmatically creating the control. Here are examples: Private Sub cmdCreateControl_Click() Dim txtFirstName As Control Set txtFirstName = CreateControl("Fundamentals", _ AcControlType.acTextBox, _ AcSection.acDetail, _ "Fundamentals", _ "", 1600, 260, 1760, 260) Set txtFirstName = Nothing End Sub To make a text box read-only, that is, if you don't want the user to enter text in an edit box, there are various alternatives. If you change the Enabled property from Yes to No, the text box would have a gray background and cannot receive focus. If you set the Locked property from No to Yes, the control would appear with a normal (white) background. The Special Effects property of the text box is expanded as compared to that available on a label. Besides the ability to raise or sink a text box, you can give it a thick, etched, or shadow border. |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|