Access shuts down unexpectedly after programmatically exporting Microsoft Graph object (287022)
The information in this article applies to:
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 "C:\Graph1.jpg", "JPEG"
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.
- Click the command button to export the Microsoft Graph object to the file C:\Graph1.jpg.
- On the View menu, click Design View.
Note that the form opens in Design view without any errors.
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:
- Open the sample database Northwind.mdb.
- On the Insert menu, click Form.
- 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.
- On the View menu, click Design View.
- On the View menu, click Properties.
- On the Edit menu, click Select Form.
- In the property sheet for the form, click the Format tab, and then change the DefaultView property to PivotChart.
- On the View menu, click PivotChart View.
- Drag the CategoryName field from the field list to the Drop Category Fields Here drop area.
- 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.
- On the File menu, click Close. When you are prompted to save, click Yes, and save the form as frmPivotChart.
- On the Insert menu, click Form.
- Click Design View, and then click OK without selecting a table or query.
- Drag the frmPivotChart form from the Database window to the new form to create a subform.
- On the View menu, click Properties.
- Click the subform object.
- In the property sheet, click the Other tab, and then set the Name property to frmPivotChart.
- Add a command button to the main form, and set its Name property to Command1.
- On the View menu, click Code to view the module of the form.
- 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 "C:\PivotChart1.jpg", "JPEG"
End Sub
- On the File menu, click Close and Return to Microsoft Access.
- On the File menu, click Save, and then save the form as frmMain.
- On the View menu, click Form View. Note that the subform is displayed in PivotChart view.
- Click the command button to export the PivotChart to the file C:\PivotChart1.jpg.
- On the View menu, click Design View.
Note that the form opens in Design view without any errors.
STATUSMicrosoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.
Modification Type: | Minor | Last Reviewed: | 10/11/2006 |
---|
Keywords: | kbprb kbnofix KB287022 |
---|
|