问题
I have created a chart in Access forms and exported it in Image Format. It's easily done, but the problem comes when after it, when I close the Form, It Shows a Pop-up message.
"The operation on the Chart object failed.
The OLE server may not be registered.
To register the OLE server, reinstall it. "
Then I have done some change and the Code looks Like:
Private Sub Command1_Click()
Dim grpApp As Graph.Chart
Set grpApp = Me.Graph1.Object
grpApp.Export "C:\Graph1.jpg", "JPEG"
Me.Graph1.Enabled = True
Me.Graph1.Locked = False
Set grpApp = Nothing
Me.Graph1.Action = acOLEClose
End Sub
Now the problem is that after the export is done, the chart becomes bad, the fonts were big and condensed and the bars looked short...
I'm really stuck..
回答1:
After trying various workarounds, I found pretty much the same question and a proper fix for the problem:
- Try unlocking the graph before the export, and restore the lock afterwards
'Unlock the control... Me!YourOLEChart.Locked = False Me!YourOLEChart.Enabled = True 'Do the actual export... Set oleGrf = Me!YourOLEChart.Object oleGrf.Export filename, "JPEG" Set oleGrf = Nothing Me!YourOLEChart.Action = acOLEClose 'Restore the lock... Me!YourOLEChart.Locked = True Me!YourOLEChart.Enabled = False
- Important: remember to set the Action acOLEClose to avoid the OLE server from crashing.
You are not alone—I had the same problem. On several runs of the form, after the export execution, the chart/graph/OLEFrame became wrong (on the form View), its format got changed and I hadn't known why.
来源:https://stackoverflow.com/questions/1262698/exporting-charts-of-access-to-image-format