ACC2000: CreateControl Creates Empty Container for OLE Controls

ID: Q210125


The information in this article applies to:
  • Microsoft Access 2000

Advanced: Requires expert coding, interoperability, and multiuser skills.


SYMPTOMS

When you use the CreateControl() function to programmatically create an OLE control, only an empty container is created.


CAUSE

The CreateControl() function does not add the OLE data needed to make the control functional. This occurs even if the procedure sets the Class or OLEClass properties of the control.


RESOLUTION

In order to create an OLE control at run time, you must first create a "template" form that contains all OLE controls that your procedure needs to create at run time. Then, the procedure must set the OLEData property of the new custom control to the OLEData property of the OLE control on the "template" form.

Create a form with all OLE controls that you plan for your procedure to create at run time. The procedure must set the OLEData property of the new OLE control to the OLEData property of the appropriate control on the template form. The following steps demonstrate how to do this with the Calendar control included with Access.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp
CAUTION: Following the steps in this example will modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and perform these steps on a copy of the database.

  1. Open the sample database Northwind.mdb.


  2. Create a new blank form named Template.


  3. Insert a Calendar control and name it Calendar.


  4. Create a module and type the following line in the Declarations section if it is not already there:


  5. 
    Option Explicit 
  6. Type the following procedure:


  7. 
    Sub CreateCalendar()
       Dim frm As Form
       Dim ctl As Control
       DoCmd.OpenForm "Template", acDesign , , , , acHidden
       Set frm = CreateForm()
       Set ctl = CreateControl(frm.Name, acCustomControl, acDetail)
       ctl.OLEData = Forms!Template!Calendar.OLEData
       DoCmd.Restore
       DoCmd.Close acForm, "Template"
    End Sub 
  8. To test this function, type the following line in the Immediate window, and then press ENTER:
    
    CreateCalendar 
    Note that a new form is created with a Calendar control.



STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article.


MORE INFORMATION

Steps to Reproduce Behavior

  1. Open the sample database Northwind.mdb.


  2. Create a module and type the following line in the Declarations section if it is not already there:


  3. 
    Option Explicit 
  4. Type the following procedure:


  5. 
    Sub CreateCalendar()
       Dim frm As Form
       Dim ctl As Control
       Set frm = CreateForm()
       Set ctl = CreateControl(frm.Name, acCustomControl, acDetail)
       ctl.Class = "MSACAL.MSACALCtrl.7"
       ctl.OLEClass = "Calendar Control"
    End Sub 
  6. To test this function, type the following line in the Immediate window, and then press ENTER:
    
    CreateCalendar 
    Note that a new form is created with an empty OLE control container even though the procedure set the Class and OLEClass properties.



REFERENCES

For more information about CreateControl() function, click Microsoft Access Help on the Help menu, type "CreateControl Function" in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

Additional query words: pra

Keywords : kbprg kbdta AccCon KbVBA
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbbug


Last Reviewed: July 6, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.