Microsoft KB Archive/104711

{|
 * width="100%"|

ACC1x: Creating Unbound Object Frame with CreateControl

 * }

Q104711

-

The information in this article applies to:


 * Microsoft Access versions 1.0, 1.1

-

SYMPTOMS
When you use the CreateControl function with a controltype argument of 114 to create an unbound object frame, Microsoft Access causes a general protection (GP) fault when you view the form in Form view.

CAUSE
The CreateControl function does not provide any method for specifying the object to embed in the new control. Instead, an empty, unbound object frame is created. Note that you cannot create an empty, unbound object frame when you create the frame manually because Microsoft Access displays an Insert Object dialog box in which you must select the object to embed.

RESOLUTION
The GP fault occurs because Microsoft Access does not expect to run with an empty, unbound object frame. The CreateControl function does not provide any method of specifying the object to embed.

The following example demonstrates how to use the sample function CreateUnboundObjectFrame to create an unbound object frame using a DoMenuItem action:

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

  Create a new module, and enter the following:

     Function CreateUnboundObjectFrame (ByVal sFormName$, _                                         ByVal sObjectPath$)

A_FORMDESIGNBAR = 3 A_INSERTOBJECT = 10

DoCmd SelectObject A_FORM, sFormName SendKeys "%f" & sObjectPath & "{ENTER}" DoCmd DoMenuItem A_FORMDESIGNBAR, A_EDIT, A_INSERTOBJECT

End Function  Create a new, unbound form. Save the form as Chess. With the form open, select the Database window. Create a new module. In the module's Immediate window, type the following, and then press ENTER:

? CreateUnboundOjbectFrame("Chess", "c:\windows\chess.bmp")

NOTE: This example assumes that the CHESS.BMP file supplied with Microsoft Windows is located in the C:\WINDOWS directory.

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

Steps to Reproduce Problem
 Create a new, unbound form. Save the form as CreateControlTest. With the form open, select the Database window.</li>  Create a new module. Enter the following sample function:

<pre class="CODESAMP">     Function CreateUnboundObjectFrame Dim C As Control Set C = CreateControl("CreateControlTest", 114) End Function </li> In the module's Immediate window, type the following, and then press ENTER:

? CreateUnboundObjectFrame</li>  View the CreateControlTest form in Form view. The following error message will occur:

An error has occurred in your application. If you choose Ignore, you should save your work in a new file. If you choose Close, your application will terminate.

</li></ol>

If you choose Close or Ignore several times, the following error message will occur:

MSACCESS caused a General Protection Fault in module MSACCESS.EXE at 0096:50B6.