Access shuts down unexpectedly after programmatically exporting Microsoft Graph object

Article translations Article translations
Article ID: 287022 - View products that this article applies to.
This article was previously published under Q287022
This article has been archived. It is offered "as is" and will no longer be updated.
Advanced: Requires expert coding, interoperability, and multiuser skills.

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

Expand all | Collapse all

On This Page

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:
  1. Open the database from which you want to export the Microsoft Graph object.
  2. Open the form that contains the Microsoft Graph object in Design view.
  3. 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"
    Me.Graph1.Locked = False
    Me.Graph1.Enabled = True
    Set grpApp = Nothing
    Me.Graph1.Action = acOLEClose
    End Sub 
    					
  4. On the File menu, click Close and Return to Microsoft Access.
  5. On the File menu, click Save, and then save the form.
  6. On the View menu, click Form View. Note that the form opens and that the Microsoft Graph object is displayed.
  7. Click the command button to export the Microsoft Graph object to the file C:\Graph1.jpg.
  8. 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:
  1. Open the sample database Northwind.mdb.
  2. On the Insert menu, click Form.
  3. 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.
  4. On the View menu, click Design View.
  5. On the View menu, click Properties.
  6. On the Edit menu, click Select Form.
  7. In the property sheet for the form, click the Format tab, and then change the DefaultView property to PivotChart.
  8. On the View menu, click PivotChart View.
  9. Drag the CategoryName field from the field list to the Drop Category Fields Here drop area.
  10. 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.
  11. On the File menu, click Close. When you are prompted to save, click Yes, and save the form as frmPivotChart.
  12. On the Insert menu, click Form.
  13. Click Design View, and then click OK without selecting a table or query.
  14. Drag the frmPivotChart form from the Database window to the new form to create a subform.
  15. On the View menu, click Properties.
  16. Click the subform object.
  17. In the property sheet, click the Other tab, and then set the Name property to frmPivotChart.
  18. Add a command button to the main form, and set its Name property to Command1.
  19. On the View menu, click Code to view the module of the form.
  20. 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
    					
  21. On the File menu, click Close and Return to Microsoft Access.
  22. On the File menu, click Save, and then save the form as frmMain.
  23. On the View menu, click Form View. Note that the subform is displayed in PivotChart view.
  24. Click the command button to export the PivotChart to the file C:\PivotChart1.jpg.
  25. On the View menu, click Design View.
Note that the form opens in Design view without any errors.

Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

More information

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.

  1. Open the sample database Northwind.mdb.
  2. On the Insert menu, click Form.
  3. 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.
  4. 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.
  5. On the View menu, click Design View.
  6. On the View menu, click Properties.
  7. Select the MSGraph object to view its properties.
  8. On the Other tab, set the Name property to Graph1.
  9. Add a command button to the form, and set its Name property to Command1.
  10. On the View menu, click Code.
  11. On the Tools menu, click References.
  12. 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.
  13. Click OK to close the References dialog box.
  14. 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 "C:\Graph1.jpg", "JPEG"
        Set grpApp = Nothing
    End Sub
    					
  15. On the File menu, click Close and Return to Microsoft Access.
  16. On the File menu, click Save, and save the form as Form1.
  17. On the View menu, click Form View. Note that the form opens and that the MSGraph object is displayed.
  18. Click the command button to export the Microsoft Graph object to the file C:\Graph1.jpg.
  19. 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.
  20. Click OK.
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.

Properties

Article ID: 287022 - Last Review: October 26, 2013 - Revision: 4.0
Applies to
  • Microsoft Access 2002 Standard Edition
Keywords: 
kbnosurvey kbarchive kbprb kbnofix KB287022

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com