Microsoft KB Archive/824276

= Access quits unexpectedly when you programmatically export a Graph object =

Article ID: 824276

Article Last Modified on 6/9/2004

-

APPLIES TO


 * Microsoft Office Access 2003

-



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

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



For a Microsoft Access 2002 version of this article, see 287022.



SYMPTOMS
After you try to programmatically export a Microsoft Graph object, you may 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 Office Access 2003 quits:

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



RESOLUTION
To resolve this problem, you can use either of the following methods:  === Set the Action Property to acOLEClose After the Object Is Exported ===

Because the Graph object is contained in an OLE object frame, you can set the Action property of the object frame to acOLEClose. This closes the OLE server and therefore prevents the error. Although this prevents the shutdown, the Graph object is not accessible until you close the form and then you reopen the form.

For example, to resolve the problem that is mentioned in the &quot;Steps to Reproduce the Behavior&quot; section, you must set the Action property of the object frame to acOLEClose. To do this, follow these steps:  Start Access. Open the database where you want to export the Graph object from. Open the form that contains the Graph object in Design view.  Insert code that is similar to the following code for the Click event of the 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 Office Access.</li> On the File menu, click Save.</li> On the View menu, click Form View.

Notice that the form opens and that the Graph object appears.</li> Click the command button to export the Graph object to the file that is named C:\Graph1.jpg.</li> On the View menu, click Design View.

Notice that the form opens in Design view without any errors and that the Graph object is successfully exported to JPEG format.</li></ol> </li> ==== Create a PivotChart Object Instead of Using Graph ====

When you use the PivotChart view for forms in Access, you can programmatically export the chart to a graphics file to avoid this problem. To create a PivotChart and to programmatically export the chart to a graphics file, follow these steps: <ol> Start Access.</li> Open the Northwind.mdb sample database.</li> On the Insert menu, click Form.</li> In the New Form dialog box, click AutoForm: PivotChart.</li> In the Choose the table or query where the object's data comes from list, click Sales by Category, and then click OK.</li> Move CategoryName from Chart Field List to Drop Category Fields Here.</li> Move ProductSales from Chart Field List to Drop Data Fields Here.

Notice that the chart that appears shows the Sum of Product Sales by Category.</li> On the File menu, click Close. When you are prompted to save the form, click Yes. Save the form as frmPivotChart .</li> On the Insert menu, click Form.</li> Click Design View, and then click OK.

Do not select a table or a query.</li> Move frmPivotChart from the Database window to the new form.

This creates 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 then set the Name property of the command button to Command1 .</li> <li>In the Command Button Wizard dialog box, click Cancel.</li> <li>On the View menu, click Code to view the module of the form.</li> <li> Use the copy and paste feature to move the following code to the Visual Basic Editor: 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 Office 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.

Notice that the subform appears in PivotChart view.</li> <li>Click the command button to export the PivotChart to the file that is named C:\PivotChart1.jpg.</li> <li>On the View menu, click Design View.

Notice that the form opens in Design view without any errors.</li></ol> </li></ul>

<div class="status_section">

STATUS
Microsoft has confirmed that this is a bug 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>Start Access.</li> <li>Open the Northwind.mdb sample database.</li> <li>On the Insert menu, click Form.</li> <li>In the New Form dialog box, click Chart Wizard.</li> <li>In the Choose the table or query where the object's data comes from box, click Sales by Category, and then click OK.</li> <li>Add the CategoryName field and the ProductSales field to the Fields for Chart box, and then click Finish.

Notice that a new form opens with a Graph object.</li> <li>On the View menu, click Design View.</li> <li>On the View menu, click Properties.</li> <li>Click MSGraph to view the properties of the MSGraph object.</li> <li>On the Other tab, set the Name property to Graph1 .</li> <li>Add a command button to the form, and then set the Name property of the command button 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 that is next to Microsoft Graph 11.0 Object Library.

If you do not see the Microsoft Graph 11.0 Object Library, click Browse, look for the file in  :\Program Files\Microsoft Office\Office11\Graph.exe, and then click Open.</li> <li>Click OK to close the References dialog box.</li> <li> Use the copy and paste feature to put the following Visual Basic for Applications code in 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 Office Access.</li> <li>On the File menu, click Save. Save the form as Form1 .</li> <li>On the View menu, click Form View.

Notice that the form opens and that the MSGraph object appears.</li> <li>Click the command button to export the Graph object to the file that is named C:\Graph1.jpg.</li> <li>On the View menu, click Design View.

Notice 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.

You may receive the following error message, and then Access quits unexpectedly:

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

</li></ol>

Additional query words: ACC2003

Keywords: kberrmsg kbbug kbexport kbprogramming KB824276

-

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

© Microsoft Corporation. All rights reserved.