ms access save a reports chart as a jpg

I have a form with a button.  I will like to click the button, have it open a report that contains a chart.  Then export that chart to a jpg file.  The current code crashes access when I close the opened report.  This works with a form with a chart but I can't get it to work with a report.  Any ideas?
Private Sub btnimg_Click()
 
    sDirectoryName = BrowseDirectory("Find and select where to export the Image file.")
    txtFileLocation = sDirectoryName
 
    strRpt = "MonthlyCostByGroupings"
    DoCmd.OpenReport strRpt, acViewPreview
    Dim grpApp As Object
    Set grpApp = Reports!MonthlyCostByGroupings.OLEUnbound0.Object
    grpApp.Export txtFileLocation & "\Chart.jpg"
    Reports!MonthlyCostByGroupings.OLEUnbound0.Locked = False
    Reports!MonthlyCostByGroupings.OLEUnbound0.Enabled = True
    Set grpApp = Nothing
    Reports!MonthlyCostByGroupings.Action = acOLEClose
End Sub

Open in new window

bdead20Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeffrey CoachmanMIS LiasonCommented:
bdead20

1. Please post any "Support" Code.
There is a reference to a "BrowseDirectory" function, yet there is no code for it?

2. Niether strRpt nor sDirectoryName is explicitly declared.

I am trying to duplicate your issue, so I need this info.

JeffCoachman
0
bdead20Author Commented:
That code isn't specific to the problem.  I should have cleaned it up more before posting.  I updated the code to not utilize those functions and attatched it.
Private Sub btnimg_Click()
    DoCmd.OpenReport "MonthlyCostByGroupings", acViewPreview
    Dim grpApp As Object
    Set grpApp = Reports!MonthlyCostByGroupings.OLEUnbound0.Object
    grpApp.Export "C:\Chart.jpg"
    Reports!MonthlyCostByGroupings.OLEUnbound0.Locked = False
    Reports!MonthlyCostByGroupings.OLEUnbound0.Enabled = True
    Set grpApp = Nothing
    Reports!MonthlyCostByGroupings.Action = acOLEClose
End Sub

Open in new window

0
Jeffrey CoachmanMIS LiasonCommented:
I'll look at this tonight.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Jeffrey CoachmanMIS LiasonCommented:
I could not duplicate the issue.
How are you creating a Chart/Graphe as an OLEUnbound Object?
0
bdead20Author Commented:
I threw together a simple DB that causes the error.
Save-JPG-DB.zip
0
Jeffrey CoachmanMIS LiasonCommented:
Again, my question is:

How are you creating your chart to be an image in an OLE Unbound Object Frame?

When you create a chart using the Wizard, the Object is simply: "Chart"

JeffCoachman
0
bdead20Author Commented:
I've tried creating with the wizard, and just adding an Unbound Object Frame.  Both with the object type of "Microsoft Graph Chart".  I get the error either way.

My understanding is you can export this type as a image.  That part is actually working (in that the image is created) but the problem is the crashing of access after the image is saved to the directory.
0
Jeffrey CoachmanMIS LiasonCommented:
bdead20,

I undersand that (I am getting the same result), but again, my question is *HOW* are you taking the "Chart Object" (which is what Access creates by default), and putting it into a OLE Unbound control?
Please explain.
Perhaps this has something to do with why it is not working.

JeffCoachman
0
bdead20Author Commented:
Maybe I don't understand the question.  I do the following to create the chart.

1. I click create new report
2. Select design mode
3. Click "Unbound Object Frame"
4. Click in Detail
5. Select create New Microsoft Graph Chart
6. Save report

That's all I do to create the report.   I thought that makes it an OLE Unbound Control automatically.  Maybe that's a step I'm not taking that I should be?
0
Jeffrey CoachmanMIS LiasonCommented:
bdead20,

Yes that is what I meant.
;-)

The steps to create a standard Chart are:
1. I click create new report
2. Select design mode
3. Click Insert-->Chart
5. Select create New Microsoft Graph Chart
6. Save report

So the startup is different, I will investigate this tonight.

JeffCoachman
0
Jeffrey CoachmanMIS LiasonCommented:
I amd getting the same errors as you.

Can you post the Form version of this, so I can see how it works successfully?
0
bdead20Author Commented:
Hmm, I can't seem to get it to work with the form either now.  I'll mess around with it some more and figure out how I got to work and put it up tomorrow.
0
bdead20Author Commented:
I'm still not able to figure this out.
0
Jeffrey CoachmanMIS LiasonCommented:
Can you post the code that you were actually using to do this with a form?
0
bdead20Author Commented:
I can't seem to get that to work either.
0
Jeffrey CoachmanMIS LiasonCommented:
Can you post it anyway?
Perhaps I can.
0
bdead20Author Commented:
Here is aform that has 2 buttons.  1 tries to save from a report and the other from a form.  Also on the other form is a button that tries saving an image from itself.  All three encounter the same error of creating the image fine but then crashing access.
Save-JPG-DB.zip
0
Jeffrey CoachmanMIS LiasonCommented:
bdead20,

The code on the "GraphForm" will work with this code, however it will still throw an OLE error and crash out of Access.

Private Sub Command1_Click()
Dim grpApp As Object
   Set grpApp = Me.OLEUnbound0 '.Object
    grpApp.Export "C:\ChartFromForm.jpg"
End Sub

Where did you get this code from, originally?

JeffCoachman
0
bdead20Author Commented:
0
Jeffrey CoachmanMIS LiasonCommented:
bdead20,

Well that code worked beautifully.

But again, it is using the default "Chart object".
This brings me back to my original question:
Why are you using an OLEUnbound control, when the default is a "Chart Object"?
This may explain why it worked for you before, but now crashes when you use this "OLEUnbound" control.
Besides the charts you are using in the sample have no source data, so I am not sure if this would have ever worked anyway.

When you create a chart in Access, follow the basic wizard steps:
Open the Form or Report in design View.
Click: Insert-->Chart
Size your chart
Select your Table/Query
Select your Fields
Select your Chart Type
Select your Chart Layout
Name your Chart
Finish
... and the code in the link you provided will work fine.

I tried everything I could, but could not get the code to work in a report.
The only thing I can see to do, is to create a temp form with the exact same chart as the report, and then run the conversion code on the temp form.

JeffCoachman
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bdead20Author Commented:
Ok, yes, the way I was creating charts was definitly the problem.  I couldn't get it to work with a report either.  This is probably because the Enabled and Locked options are not avaialbe for a chart inside a report and required to prevent the error.  Thanks for you help and sticking with the problem.
0
Jeffrey CoachmanMIS LiasonCommented:
bdead20,

  "probably because the Enabled and Locked options are not avaialbe for a chart"

Yeah, I thought about that too.

Even when when I commented out that code, the JPG, would still be created, but then the form/report would trigger the crash.

JeffCoachman
0
bdead20Author Commented:
I have a follow up question related to this one located at
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_23916092.html#a22993978
0
Jeffrey CoachmanMIS LiasonCommented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.