Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Error message when you try to programmatically export a Microsoft Graph object in Access 2007: "Run-time error 1004: Application-defined or object-defined error"


View products that this article applies to.

For a Microsoft Office Access 2003 version of this article, see 824276 (http://support.microsoft.com/kb/824276/ ) .
For a Microsoft Office Access 2003 version of this article, see 824276 (http://support.microsoft.com/kb/824276/ ) .

↑ Back to the top


Symptoms

When you try to programmatically export a Microsoft Graph object in Microsoft Office Access 2007, you receive the following error message:
Run-time error 1004:
Application-defined or object-defined error.
When you try to close the error message, 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.
After you receive the error messages, you cannot perform the following operations:
  • Save the form
  • Open the form in Design view

↑ Back to the top


Workaround

To work around this problem, use one of the following methods.

Method 1: Create a PivotChart object instead of a Graph object"

  1. Start Access 2007.
  2. Click the Microsoft Office Button, and then click Open.
  3. In the Open dialog box, select the database that you want, and then click Open.
  4. On the Create menu, click PivotChart.
  5. On the Design menu, click Field List in the Show/Hide group. Do this to open the Chart Field List list.
  6. Move CategoryName from Chart Field List to Drop Category Fields Here.
  7. Move ProductSales from Chart Field List to Drop Data Fields Here.

    Note The chart displays the sum of product sales by category.
  8. Click the Microsoft Office Button, and then click Close.
  9. In the Save As dialog box, type frmPivotChart under Form Name, and then click OK.
  10. On the Create menu, click Form Design in the Forms group, and then move frmPivotChart from the Navigation Pane to the designer.

    Note This procedure creates a subform.
  11. Add a command button to the main form, and then set the Name property of the command button to Command1.
  12. On the Design menu, click Button in the Controls group, and then click the Form2 designer to put the Command button on the form.
  13. Right-click Command1, and then click Properties.
  14. In the Property Sheet dialog box, click the Event tab, and then click the ellipsis button (...) for the On Click event.
  15. In the Choose Builder dialog box, select Code Builder, and then click OK.
  16. In Visual Basic Editor, replace the code with the following code.
    Option Compare Database
            Private Sub Command1_Click()
            Dim frm As Access.Form
    
            Set frm = Me.frmPivotChart.Form
             frm.ChartSpace.ExportPicture "C:\<folder name>\PivotChart1.jpg", "JPEG"
            End Sub
    
  17. On the File menu, click Close and Return to Microsoft Office Access.
  18. In the Save dialog box, click Yes.
  19. In the Save As dialog box, type frmMain under Form Name, and then click OK.
  20. On the Home menu, click View in the Views group, and then click Form View.

    The subform appears in PivotChart view.
  21. On the frmMain form, click the Command1 button to export the PivotChart to the following file:
    C:\PivotChart1.jpg
  22. On the Home menu, click View in the Views group, and then click Design View.

    The form opens in Design view.

Method 2: Set the action property to acOLEClose after the object is exported

Use the following code to export a graph object in Microsoft Access 2007
Private Sub Command1_Click() 
Dim grpApp As Graph.Chart 
Set grpApp = Me.Graph1.Object 
grpApp.Export "C:\<folder name>\Graph1.jpg", "JPEG" 
Me.Graph1.Enabled = True
Me.Graph1.Locked = False
Set grpApp = Nothing 
Me.Graph1.Action = acOLEClose 
End Sub

↑ Back to the top


Status

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

↑ Back to the top


More information

Steps to reproduce the problem

  1. Start Access 2007.
  2. Click the Microsoft Office Button, and then click New.
  3. Click Blank Database, type DatabaseName in the File Name box, and then click Create.
  4. On the Create menu, click Table Design in the Tables group, and then create the following table:
    Collapse this tableExpand this table
    Field NameData Type
    CategoryName Text
    ProductSalesCurrency
  5. Click the Microsoft Office Button, and then click Save.
  6. Type tabSales in the Table Name box, and then click OK.

    Note When you click OK, you may create a primary key.
  7. In the Views group, click the Datasheet view, and then type the following values in the CategoryName and ProductSales fields:
    Collapse this tableExpand this table
    CategoryNameProductSales
    Beverages45000
    Condiments15000
    Produce65000
    Seafood33000
  8. On the Create menu, click Form Design in the Forms group.
  9. On the Design menu, click the Chart control in the Controls group, and then click the Form1 designer.
  10. In the Chart Wizard dialog box, click Next.

    Note Table:tabSales is automatically selected under Which table or query would you like to use to create your chart.
  11. In Chart Wizard under Which fields contain the data you want for the chart, select CategoryName under Available Fields.
  12. Click > to move CategoryName under Fields for Chart, and then click Finish.
  13. Repeat steps 11 and 12 for ProductSales.
  14. Right-click the chart, and then click Properties.
  15. On the Design menu, click Button in the Controls group, and then click the Form1 designer.
  16. Click Cancel to close Command Button Wizard.
  17. Right-click the Command1 control, and then click Build Event.
  18. In Visual Basic Editor, replace the existing code with the following code.
    Option Compare Database
    Private Sub Command1_Click()
        Dim grpApp As Graph.Chart
        Set grpApp = Me.Graph0.Object
        grpApp.Export "C:\Graph0.jpg", "JPEG"
        Set grpApp = Nothing
    End Sub
  19. On the Tools menu, click References.
  20. In the References - DatabaseName dialog box, click to select Microsoft Graph 12.0 Object Library, and then click OK.
  21. On the File menu, click Close and Return to Microsoft Office Access.
  22. In the Views group, click View, and then click Form View.
  23. On Form1, click Command1.

    Note The problem that is discussed in the "Symptoms" section occurs.

↑ Back to the top


Keywords: KB926429, kbprb, kbtshoot, kbexpertiseinter, kberrmsg

↑ Back to the top

Article Info
Article ID : 926429
Revision : 3
Created on : 5/1/2009
Published on : 5/1/2009
Exists online : False
Views : 191