Microsoft KB Archive/926429

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

Article ID: 926429

Article Last Modified on 10/15/2007

-

APPLIES TO


 * Microsoft Office Access 2007

-





For a Microsoft Office Access 2003 version of this article, see 824276.



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



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

Method 1: Set the action property to acOLEClose after the object is exported
 Start Access 2007. Click the Microsoft Office Button, and then click Open. In the Open dialog box, select the database that you want, and then click Open. On the Create menu, click PivotChart. On the Design menu, click Field List in the Show/Hide group. Do this to open the Chart Field List list. Move CategoryName from Chart Field List to Drop Category Fields Here.</li> Move ProductSales from Chart Field List to Drop Data Fields Here.

Note The chart displays the sum of product sales by category.</li> Click the Microsoft Office Button, and then click Close.</li> In the Save As dialog box, type frmPivotChart under Form Name, and then click OK.</li> 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.</li> Add a command button to the main form, and then set the Name property of the command button to Command1.</li> On the Design menu, click Button in the Controls group, and then click the Form2 designer to put the Command button on the form.</li> Right-click Command1, and then click Properties.</li> In the Property Sheet dialog box, click the Event tab, and then click the ellipsis button (...) for the On Click event.</li> In the Choose Builder dialog box, select Code Builder, and then click OK.</li>  In Visual Basic Editor, replace the code with the following code. Private Sub Command1_Click Dim grpApp As Graph.Chart Set grpApp = Me.Graph1.Object grpApp.Export &quot;C:\Graph1.jpg&quot;, &quot;JPEG&quot; Set grpApp = Nothing Me.Graph1.Action = acOLEClose End Sub </li> On the File menu, click Close and Return to Microsoft Office Access.</li> In the Save dialog box, click Yes.</li> In the Save As dialog box, type frmMain under Form Name, and then click OK.</li> On the Home menu, click View in the Views group, and then click Form View.

The subform appears in PivotChart view.</li> On the frmMain form, click the Command1 button to export the PivotChart to the following file:

C:\PivotChart1.jpg

</li> On the Home menu, click View in the Views group, and then click Design View.

The form opens in Design view.</li></ol>

Method 2: Create a PivotChart object instead of a Graph object
The steps for this method are the same as the steps in Method 1, except for step 16.

To use this method, follow steps 1 through 15 in Method 1. In step 16, 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 &quot;C:\PivotChart1.jpg&quot;, &quot;JPEG&quot; End Sub Then, follow steps 17 through 22 in Method 1.

<div class="status_section">

STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section.

<div class="moreinformation_section">

Steps to reproduce the problem
<ol> <li>Start Access 2007.</li> <li>Click the Microsoft Office Button, and then click New.</li> <li>Click Blank Database, type  in the File Name box, and then click Create.</li> <li>On the Create menu, click Table Design in the Tables group, and then create the following table: </li> <li>Click the Microsoft Office Button, and then click Save.</li> <li>Type in the Table Name box, and then click OK.

Note When you click OK, you may create a primary key.</li> <li>In the Views group, click the Datasheet view, and then type the following values in the CategoryName and ProductSales fields: </li> <li>On the Create menu, click Form Design in the Forms group.</li> <li>On the Design menu, click the Chart control in the Controls group, and then click the Form1 designer.</li> <li>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.</li> <li>In Chart Wizard under Which fields contain the data you want for the chart, select CategoryName under Available Fields.</li> <li>Click > to move CategoryName under Fields for Chart, and then click Finish.</li> <li>Repeat steps 11 and 12 for ProductSales.</li> <li>Right-click the chart, and then click Properties.</li> <li>On the Design menu, click Button in the Controls group, and then click the Form1 designer.</li> <li>Click Cancel to close Command Button Wizard.</li> <li>Right-click the Command1 control, and then click Build Event.</li> <li> 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 &quot;C:\Graph0.jpg&quot;, &quot;JPEG&quot; Set grpApp = Nothing End Sub </li> <li>On the Tools menu, click References.</li> <li>In the References -  dialog box, click to select Microsoft Graph 12.0 Object Library, and then click OK.</li> <li>On the File menu, click Close and Return to Microsoft Office Access.</li> <li>In the Views group, click View, and then click Form View.</li> <li>On Form1, click Command1.

Note The problem that is discussed in the &quot;Symptoms&quot; section occurs.</li></ol>

Additional query words: AC2007 ACC2007 Access2007

Keywords: kberrmsg kbtshoot kbprb kbexpertiseinter KB926429

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.