Microsoft KB Archive/121667

= ACC: CreateControl Function Always Creates Label with Colon =

Article ID: 121667

Article Last Modified on 5/6/2003

-

APPLIES TO


 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition

-



This article was previously published under Q121667



Moderate: Requires basic macro, coding, and interoperability skills.



SYMPTOMS
When you use the CreateControl function to create a text box on a form, the text box's attached label always contains a colon, even if you have created your own form template and set the AddColon property for the default text box to No.



RESOLUTION
This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.1, or the "Building Applications" manual in version 2.0.

Add the following line to the sample code in step 5 of the "Steps to Reproduce Problem" section later in this article. Insert this line before the line that reads "DoCmd Restore" to change the label's Caption property to remove the colon:

  MyLabel.Caption=Left$(MyLabel.Caption,Len(MyLabel.Caption)-1).



STATUS
Microsoft has confirmed this to be a problem in Microsoft Access versions 1.1 and 2.0. This problem no longer occurs in Microsoft Access version 7.0.



Steps to Reproduce Problem
 Open the sample database NWIND.MDB. Create a new table called Table1. Add one field to the table. Create a blank, new form, and then set the default text box's AddColon property to No. (To set the default text box's properties, view the property sheet and then click the Text Box button in the toolbox.) Save the form as Test. From the View menu, choose Options. In the Category box, select Form & Report Design, then set the Form Template item to Test. Choose OK.  Create a new module, and then enter the following sample code in the module.

NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.

<pre class="fixed_text">     Option Explicit Sub NormalForm Dim MyRecordSource As String Dim DataX As Integer, DataY As Integer, LabelX As Integer, _ LabelY As Integer Dim MyForm As String, MyFormCreate As Form, MyLabel As _ Control, MyControl As Control MyRecordSource = "Table1" Set MyFormCreate = CreateForm("", "") MyForm = MyFormCreate.Formname  'Use this line in version 1.1. MyForm = MyFormCreate.Name      'Use this line in version 2.0. MyFormCreate.RecordSource = MyRecordSource LabelX = 100 LabelY = 100 DataX = 1000 DataY = 100 ' Create unbound default-size text box in the detail section. Set MyControl = CreateControl(MyForm, 109, 0, "", "", DataX, _         DataY) ' Create child label control for the text box. Set MyLabel = CreateControl (MyForm, 100, 0, MyControl.Control_          name, "hello", LabelX, LabelY)  'Use this line in version 1.1. Set MyLabel = CreateControl(MyForm, 100, 0, MyControl.Name, _         "hello", LabelX, LabelY)   'Use this line in version 2.0. DoCmd Restore End Sub </li> From the View menu, choose Immediate Window.</li> In the Immediate window, type the following line, and then press ENTER:

NormalForm

Note that the label that is created contains a colon.</li></ol>

<div class="references_section">