ACC: CreateControl() Function Always Creates Label with Colon

ID: Q121667


The information in this article applies to:


SYMPTOMS

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

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.


MORE INFORMATION

Steps to Reproduce Problem


  1. Open the sample database NWIND.MDB.


  2. Create a new table called Table1. Add one field to the table.


  3. 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.


  4. From the View menu, choose Options. In the Category box, select Form & Report Design, then set the Form Template item to Test. Choose OK.


  5. 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.
    
          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 


  6. From the View menu, choose Immediate Window.


  7. In the Immediate window, type the following line, and then press ENTER:

    NormalForm

    Note that the label that is created contains a colon.



REFERENCES

For more information about the CreateControl() function, search for "CreateControl," and then "CreateControl, CreateReportControl Functions" using the Microsoft Access version 2.0 Help menu.

Microsoft Access "The Secrets of AccessWizards," version 1.1, Chapter 2, "Incantations: AccessWizard Functions and Properties," pages 12-15


Keywords          : kbusage FmrProp 
Version           : 1.1 2.0
Platform          : WINDOWS 
Issue type        : kbbug 

Last Reviewed: April 7, 1999