Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

ms access save a reports chart as a jpg

Posted on 2008-10-28
24
Medium Priority
?
2,187 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I have had my own IT business for a very long time. I started mostly with hardware and after about a year started to notice a common theme. I had shelves with software boxes -- Peachtree, Quicken, Sage, Ouickbooks -- and yet most of my clients were…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

580 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