Solved

ms access save a reports chart as a jpg

Posted on 2008-10-28
24
1,912 Views
Last Modified: 2013-11-28
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

0
Comment
Question by:bdead20
  • 13
  • 11
24 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 22826349
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
 

Author Comment

by:bdead20
ID: 22830486
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
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 22832967
I'll look at this tonight.
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 22837900
I could not duplicate the issue.
How are you creating a Chart/Graphe as an OLEUnbound Object?
0
 

Author Comment

by:bdead20
ID: 22840404
I threw together a simple DB that causes the error.
Save-JPG-DB.zip
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 22847433
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
 

Author Comment

by:bdead20
ID: 22849464
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
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 22850966
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
 

Author Comment

by:bdead20
ID: 22851198
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
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 22852488
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
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 22865770
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
 

Author Comment

by:bdead20
ID: 22871721
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
 

Author Comment

by:bdead20
ID: 22939532
I'm still not able to figure this out.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 22940999
Can you post the code that you were actually using to do this with a form?
0
 

Author Comment

by:bdead20
ID: 22942854
I can't seem to get that to work either.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 22947338
Can you post it anyway?
Perhaps I can.
0
 

Author Comment

by:bdead20
ID: 22963946
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
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 22973338
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
 

Author Comment

by:bdead20
ID: 22975305
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
ID: 22981106
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
 

Author Comment

by:bdead20
ID: 22984295
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
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 22988595
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
 

Author Comment

by:bdead20
ID: 22993991
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
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 22995013
thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question