Microsoft KB Archive/210125

= ACC2000: CreateControl Creates Empty Container for OLE Controls =

Article ID: 210125

Article Last Modified on 6/23/2005

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q210125



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. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements. CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

 Open the sample database Northwind.mdb. Create a new blank form named Template. Insert a Calendar control and name it Calendar.  Create a module and type the following line in the Declarations section if it is not already there: Option Explicit   Type the following procedure: 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   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. </li></ol>

<div class="status_section">

STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

<div class="moreinformation_section">

Steps to Reproduce Behavior
<ol> Open the sample database Northwind.mdb.</li>  Create a module and type the following line in the Declarations section if it is not already there: Option Explicit </li>  Type the following procedure: 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 </li>  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. </li></ol>

<div class="references_section">