Microsoft KB Archive/287022

= Access shuts down unexpectedly after programmatically exporting Microsoft Graph object =

Article ID: 287022

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 2002 Standard Edition

-



This article was previously published under Q287022



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

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).



SYMPTOMS
After you try to programmatically export a Microsoft Graph object, you receive the following error message:

The operation on the Chart object failed.

The OLE server may not be registered.

To register the OLE server, reinstall it.

When you click OK, you receive the following error message, and then Microsoft Access shuts down:

Microsoft Access has encountered a problem and needs to close. We are sorry for the inconvenience.



RESOLUTION
There are two possible resolutions to this problem.

Set the Action Property to acOLEClose After Exporting the Object
Because the Microsoft Graph object is contained in an OLE object frame, you can set the Action property of the object frame to acOLEClose. This forces the OLE server to close, which prevents the error from occurring. However, even though this prevents the shut down from occurring, the Microsoft Graph object will not be accessible until you close and then reopen the form. To set the Action property of the object frame to acOLEClose, follow these steps:  Open the database from which you want to export the Microsoft Graph object. Open the form that contains the Microsoft Graph object in Design view.  Insert code similar to the following for the Click event of a command button: Private Sub Command1_Click Dim grpApp As Graph.Chart Set grpApp = Me.Graph1.Object grpApp.Export &quot;C:\Graph1.jpg&quot;, &quot;JPEG&quot; Set grpApp = Nothing Me.Graph1.Action = acOLEClose End Sub  On the File menu, click Close and Return to Microsoft Access. On the File menu, click Save, and then save the form. On the View menu, click Form View. Note that the form opens and that the Microsoft Graph object is displayed.</li> Click the command button to export the Microsoft Graph object to the file C:\Graph1.jpg.</li> On the View menu, click Design View. Note that the form opens in Design view without any errors.</li></ol>

Create a PivotChart Object Instead of Using Microsoft Graph
When you use the PivotChart view for forms in Microsoft Access, you can programmatically export the chart to a graphics file to avoid the problem. To create a PivotChart and programmatically export it to a graphics file, follow these steps: <ol> Open the sample database Northwind.mdb.</li> On the Insert menu, click Form.</li> In the New Form dialog box, click AutoForm: Columnar, click the arrow in the Choose the table or query where the object's data comes from box, click the Sales by Category query in the list, and then click OK.</li> On the View menu, click Design View.</li> On the View menu, click Properties.</li> On the Edit menu, click Select Form.</li> In the property sheet for the form, click the Format tab, and then change the DefaultView property to PivotChart.</li> On the View menu, click PivotChart View.</li> Drag the CategoryName field from the field list to the Drop Category Fields Here drop area.</li> Drag the ProductSales field from the field list to the Drop Data Fields Here drop area. Note that a chart appears that shows the Sum of ProductSales by Category.</li> On the File menu, click Close. When you are prompted to save, click Yes, and save the form as frmPivotChart.</li> On the Insert menu, click Form.</li> Click Design View, and then click OK without selecting a table or query.</li> Drag the frmPivotChart form from the Database window to the new form to create a subform.</li> <li>On the View menu, click Properties.</li> <li>Click the subform object.</li> <li>In the property sheet, click the Other tab, and then set the Name property to frmPivotChart.</li> <li>Add a command button to the main form, and set its Name property to Command1.</li> <li>On the View menu, click Code to view the module of the form.</li> <li> Add the following Visual Basic for Applications code to the Click event of the command button: Private Sub Command1_Click Dim frm As Access.Form

Set frm = Me.frmPivotChart.Form frm.ChartSpace.ExportPicture &quot;C:\PivotChart1.jpg&quot;, &quot;JPEG&quot; End Sub </li> <li>On the File menu, click Close and Return to Microsoft Access.</li> <li>On the File menu, click Save, and then save the form as frmMain.</li> <li>On the View menu, click Form View. Note that the subform is displayed in PivotChart view.</li> <li>Click the command button to export the PivotChart to the file C:\PivotChart1.jpg.</li> <li>On the View menu, click Design View.</li></ol>

Note that the form opens in Design view without any errors.

<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 the Behavior
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.

<ol> <li>Open the sample database Northwind.mdb.</li> <li>On the Insert menu, click Form.</li> <li>In the New Form dialog box, click the Chart Wizard, click the arrow in the Choose the table or query where the object's data comes from box, click the Sales by Category query in the list, and then click OK.</li> <li>Add the CategoryName and ProductSales fields to the Fields for Chart box, and then click Finish. Note that a new form opens with a Microsoft Graph object on it.</li> <li>On the View menu, click Design View.</li> <li>On the View menu, click Properties.</li> <li>Select the MSGraph object to view its properties.</li> <li>On the Other tab, set the Name property to Graph1.</li> <li>Add a command button to the form, and set its Name property to Command1.</li> <li>On the View menu, click Code.</li> <li>On the Tools menu, click References.</li> <li>In the References dialog box, click to select the check box next to Microsoft Graph 10.0 Object Library. If you do not see this library, click the Browse button, browse for the file C:\Program Files\Microsoft Office\Office10\Graph.exe, and then click Open.</li> <li>Click OK to close the References dialog box.</li> <li> Add the following Visual Basic for Applications code to the module of the form: Private Sub Command1_Click Dim grpApp As Graph.Chart Set grpApp = Me.Graph1.Object grpApp.Export &quot;C:\Graph1.jpg&quot;, &quot;JPEG&quot; Set grpApp = Nothing End Sub </li> <li>On the File menu, click Close and Return to Microsoft Access.</li> <li>On the File menu, click Save, and save the form as Form1.</li> <li>On the View menu, click Form View. Note that the form opens and that the MSGraph object is displayed.</li> <li>Click the command button to export the Microsoft Graph object to the file C:\Graph1.jpg.</li> <li>On the View menu, click Design View. Note that you receive the following error message:

The operation on the Chart object failed.

The OLE server may not be registered.

To register the OLE server, reinstall it.

</li> <li>Click OK.</li></ol>

Note that you receive the following error message, and then Access shuts down:

Microsoft Access has encountered a problem and needs to close. We are sorry for the inconvenience.

Additional query words: pra

Keywords: kbprb kbnofix KB287022

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.