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.

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 "Steps to Reproduce the Behavior" section, you must set the Action property of the object frame to acOLEClose. To do this, follow these steps:
    1. Start Access.
    2. Open the database where you want to export the Graph object from.
    3. Open the form that contains the Graph object in Design view.
    4. 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 
      
    5. On the File menu, click Close and Return to Microsoft Office Access.
    6. On the File menu, click Save.
    7. On the View menu, click Form View.

      Notice that the form opens and that the Graph object appears.
    8. Click the command button to export the Graph object to the file that is named C:\Graph1.jpg.
    9. 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 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:
    1. Start Access.
    2. Open the Northwind.mdb sample database.
    3. On the Insert menu, click Form.
    4. In the New Form dialog box, click AutoForm: PivotChart.
    5. In the Choose the table or query where the object's data comes from list, click Sales by Category, and then click OK.
    6. Move CategoryName from Chart Field List to Drop Category Fields Here.
    7. 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.
    8. On the File menu, click Close. When you are prompted to save the form, click Yes. Save the form as frmPivotChart.
    9. On the Insert menu, click Form.
    10. Click Design View, and then click OK.

      Do not select a table or a query.
    11. Move frmPivotChart from the Database window to the new form.

      This creates a subform.
    12. On the View menu, click Properties.
    13. Click the subform object.
    14. In the property sheet, click the Other tab, and then set the Name property to frmPivotChart.
    15. Add a command button to the main form, and then set the Name property of the command button to Command1.
    16. In the Command Button Wizard dialog box, click Cancel.
    17. On the View menu, click Code to view the module of the form.
    18. 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
      	
    19. On the File menu, click Close and Return to Microsoft Office Access.
    20. On the File menu, click Save, and then save the form as frmMain.
    21. On the View menu, click Form View.

      Notice that the subform appears in PivotChart view.
    22. Click the command button to export the PivotChart to the file that is named C:\PivotChart1.jpg.
    23. 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.

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. Start Access.
  2. Open the Northwind.mdb sample database.
  3. On the Insert menu, click Form.
  4. In the New Form dialog box, click Chart Wizard.
  5. In the Choose the table or query where the object's data comes from box, click Sales by Category, and then click OK.
  6. 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.
  7. On the View menu, click Design View.
  8. On the View menu, click Properties.
  9. Click MSGraph to view the properties of the MSGraph object.
  10. On the Other tab, set the Name property to Graph1.
  11. Add a command button to the form, and then set the Name property of the command button to Command1.
  12. On the View menu, click Code.
  13. On the Tools menu, click References.
  14. 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 <installation drive>:\Program Files\Microsoft Office\Office11\Graph.exe, and then click Open.
  15. Click OK to close the References dialog box.
  16. 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 "C:\Graph1.jpg", "JPEG"
        Set grpApp = Nothing
    End Sub
    
  17. On the File menu, click Close and Return to Microsoft Office Access.
  18. On the File menu, click Save. Save the form as Form1.
  19. On the View menu, click Form View.

    Notice that the form opens and that the MSGraph object appears.
  20. Click the command button to export the Graph object to the file that is named C:\Graph1.jpg.
  21. 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.
  22. 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.

Modification Type:MinorLast Reviewed:6/9/2004
Keywords:kbProgramming kbExport kberrmsg kbbug KB824276 kbAudDeveloper