Access quits unexpectedly when you programmatically export a Graph object (824276)
The information in this article 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. SYMPTOMSAfter 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. RESOLUTIONTo 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 "Steps to Reproduce the Behavior"
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 "C:\Graph1.jpg", "JPEG"
Set grpApp = Nothing
Me.Graph1.Action = acOLEClose
End Sub
- On the File menu, click Close
and Return to Microsoft Office Access.
- On the File menu, click
Save.
- On the View menu, click Form
View.
Notice that the form opens and that the Graph object
appears. - Click the command button to export the Graph object to
the file that is named C:\Graph1.jpg.
- 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.
Create a PivotChart Object Instead of Using GraphWhen 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:
- Start Access.
- Open the Northwind.mdb sample database.
- On the Insert menu, click
Form.
- In the New Form dialog box, click
AutoForm: PivotChart.
- In the Choose the table or query where the
object's data comes from list, click Sales by
Category, and then click OK.
- Move CategoryName from Chart Field List to Drop Category
Fields Here.
- 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. - On the File menu, click
Close. When you are prompted to save the form, click
Yes. Save the form as frmPivotChart.
- On the Insert menu, click
Form.
- Click Design View, and then click
OK.
Do not select a table or a query. - Move frmPivotChart from the Database window to the new form.
This creates 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 then set the
Name property of the command button to
Command1.
- In the Command Button Wizard dialog
box, click Cancel.
- On the View menu, click
Code to view the module of the form.
- 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 "C:\PivotChart1.jpg", "JPEG"
End Sub
- On the File menu, click Close
and Return to Microsoft Office Access.
- On the File menu, click
Save, and then save the form as
frmMain.
- On the View menu, click Form
View.
Notice that the subform appears in PivotChart
view. - Click the command button to export the PivotChart to
the file that is named C:\PivotChart1.jpg.
- On the View menu, click Design
View.
Notice that the form opens in Design view without any
errors.
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are
listed at the beginning of this article.
Modification Type: | Minor | Last Reviewed: | 6/9/2004 |
---|
Keywords: | kbProgramming kbExport kberrmsg kbbug KB824276 kbAudDeveloper |
---|
|