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"
Method 1: Set the action property to acOLEClose after the object is exported
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.
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
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.
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 "C:\PivotChart1.jpg", "JPEG"
End Sub
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:
Field Name
Data Type
CategoryName
Text
ProductSales
Currency
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:
CategoryName
ProductSales
Beverages
45000
Condiments
15000
Produce
65000
Seafood
33000
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.
Need More Help? Contact a Support professional by Email, Online or Phone.
Customer Service For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
Newsgroups Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.