Microsoft KB Archive/120262

= ACC2: Cannot Embed OLE Objects Using Access Basic Code =

Article ID: 120262

Article Last Modified on 11/6/2000

-

APPLIES TO


 * Microsoft Access 2.0 Standard Edition

-



This article was previously published under Q120262





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

You can use Access Basic code to embed one OLE object in a bound control on a form successfully. However, subsequent OLE objects that you try to embed with Access Basic code are visible in the form, but are not saved when you save the record.



CAUSE
You are not moving the focus in your Access Basic code to the OLE controls in which you are trying to embed objects.



RESOLUTION
Set the focus in your Access Basic code to subsequent OLE controls before saving the record.



STATUS
This problem no longer occurs in Microsoft Access version 7.0.



Steps to Reproduce Behavior
 Create a new table with two OLE object fields called OLE1 and OLE2. Set the Required property for both fields to Yes. Create a new form based on the table you created in step 1. Add the two OLE fields to the form.  Set the form's OnLoad property to the following event procedure:

Sub Form1_Load Me![OLE1].SourceDoc = "c:\windows\arcade.bmp" Me![OLE1].Action = OLE_CREATE_EMBED

Me![OLE2].SourceDoc = "c:\windows\arcade.bmp" Me![OLE2].Action = OLE_CREATE_EMBED End Sub  View the form in Form view. Note that both the OLE controls contain the Arcade bitmap. From the File menu, choose Save Record to save the record. You will receive the error message:

Field ' .OLE2' can't contain a null value

NOTE: If you did not set the Required property for both fields to Yes, you will not receive an error message, and the second OLE object field will contain a null value.</li></ol>

To correct the problem, change the event procedure for the OnLoad property as follows:

Sub Form1_Load Me![OLE1].SourceDoc = "c:\windows\arcade.bmp" Me![OLE1].Action = OLE_CREATE_EMBED

Me![OLE2].SourceDoc = "c:\windows\arcade.bmp" Me![OLE2].Action = OLE_CREATE_EMBED Me![OLE2].Setfocus

End Sub

<div class="references_section">