Exporting a graph/chart from Microsoft Access to PDF/JPEG/GIF (1 Viewer)

Cark

Registered User.
Local time
Today, 03:04
Joined
Dec 13, 2016
Messages
153
I have a Form called FrmFleet which contains a Tab Control Box which has the tabs Report Builder and Summary Charts. I have been able to get everything in my Report Builder tab working as intended and for convenience I have pulled out all the filters etc to make it easier to look/navigate in my example.

On the Summary Charts Tab I have a simple Graph Object that I would like to export to a PDF/JPG/GIF etc using the Export button below it.

I have struggled to find example code that allows me to export it and it seems as though there are many ways to create a graph and many ways to export them, however I have been unable to find a method that works, although I admit I am very much fumbling around with this.

Any ideas?
 

Attachments

  • ExportChartToJPGOrPDF.accdb
    960 KB · Views: 289

JHB

Have been here a while
Local time
Today, 12:04
Joined
Jun 17, 2012
Messages
7,732
I'm not able to change the form to another tabs, so I can't look at your example.
 

Cark

Registered User.
Local time
Today, 03:04
Joined
Dec 13, 2016
Messages
153
@JHB how exactly are you unable to change the tabs? Is it not letting you jump from Report Builder to Summary Charts?
 

JHB

Have been here a while
Local time
Today, 12:04
Joined
Jun 17, 2012
Messages
7,732
The database crash when I try to change the tab, (from Report Builder to Summary Charts).
I'm using MS-Access 2010, which version do you use?
Have you tried to download your database from here and open it and change the tab?
 

Cark

Registered User.
Local time
Today, 03:04
Joined
Dec 13, 2016
Messages
153
I downloaded the database back from the post and I was able to switch between tabs with no issues. I am using Access 2016 so there might be a bit of a conflict there.

To try and help you help me, I have tweaked the database, by removing the Page Tabs, so that we are simply looking at the thing causing me the problem.

This newly attached database has:

  • A simple query which counts up how many times A330, CRJTK and EM90 appear in the main table TblFleet.
  • The query is then used in the Chart Object called AdvancedGraph.
  • The Export Button appears to work correctly by exporting the graph to a predefined location.
  • When I then try to close the form FrmFleet, I get an error message saying "Sorry, an unexpected error occurred. Please exit and restart Microsoft Access."

Any ideas what is causing this error message? I have not been able to find anything on google that addresses this issue.
 

Attachments

  • ExportChartToJPGOrPDF.accdb
    1 MB · Views: 252
  • Error Message.PNG
    Error Message.PNG
    5.3 KB · Views: 189

JHB

Have been here a while
Local time
Today, 12:04
Joined
Jun 17, 2012
Messages
7,732
It works by me with the below code, new codeline added marked with red, (remember to change the blue codeline).
Working database (by me) attached.
Code:
   Set grpApp = Nothing
    Set grpApp = Me.AdvancedGraph.Object

    grpApp.export [COLOR=Blue][B]"C:\Access programmer\TestJHB.jpg"[/B][/COLOR]
    Me.AdvancedGraph.Locked = False
    Me.AdvancedGraph.Enabled = True
    
    Set grpApp = Nothing
  [B][COLOR=Red]  Me.AdvancedGraph.Action = acOLEClose[/COLOR][/B]
    Me.AdvancedGraph.Locked = True
    Me.AdvancedGraph.Enabled = False
 

Attachments

  • ExportChartToJPGOrPDF1.accdb
    464 KB · Views: 293
  • TestJHB.jpg
    TestJHB.jpg
    17.3 KB · Views: 195

Cark

Registered User.
Local time
Today, 03:04
Joined
Dec 13, 2016
Messages
153
Awesome, that's much appreciated.

Would you be able to explain why the line "Me.AdvancedGraph.Action = acOLEClose" is required and why it causes the error? I am relatively new to OLE items.

The error message Access was spitting out was horribly vague and confusing.
 

JHB

Have been here a while
Local time
Today, 12:04
Joined
Jun 17, 2012
Messages
7,732
..
Would you be able to explain why the line "Me.AdvancedGraph.Action = acOLEClose" is required and why it causes the error?
..
Sorry - No.
..
The error message Access was spitting out was horribly vague and confusing.
Get use to it - the error message from Access isn't always clear, (mostly not, but you learn what it can cause the error when you stay long enough by MS-Access), by me it was a quiet another error message, more and less the below:
"The OLE server may not be registered.
"To register the OLE server please install it again".
 

June7

AWF VIP
Local time
Today, 02:04
Joined
Mar 9, 2014
Messages
5,475
@JHB, Testing your db. It works one time then have to close and reopen form to repeat the export. But at least it does work. My graph was already enabled and not locked so wouldn't think those lines needed. BUT, I set graph as locked and disabled then used the code. AND it all worked - ONCE. Now back to getting the same errors, even after closing/reopening, C&R. Insists on repairing, yet your example db does not. Tried rebuilding graph on my form, still errors. This is very annoying. Ended up importing your form and deleting mine.
 
Last edited:

JHB

Have been here a while
Local time
Today, 12:04
Joined
Jun 17, 2012
Messages
7,732
@JHB, Testing your db. It works one time then have to close and reopen form to repeat the export.
You can make a work around - close and open the form again by code, it is not perfect but it works.
Code:
  Dim TheFormName As String
  ..
  ..
  TheFormName = Me.Name
  DoCmd.Close acForm, TheFormName, acSaveNo
  DoCmd.OpenForm TheFormName
 

Cark

Registered User.
Local time
Today, 03:04
Joined
Dec 13, 2016
Messages
153
Due to the fact I have quite a few OnLoad, OnOpen and OnCurrent events, it causes my screen to flicker when it loads the text boxes and graphs. Is there an alternative workaround to the DoCmd close and open method?
 

June7

AWF VIP
Local time
Today, 02:04
Joined
Mar 9, 2014
Messages
5,475
Don't know what causes the issue so really hard to determine better solution. If Refresh or Requery don't resolve, then only recourse I see is close/reopen.
 

Users who are viewing this thread

Top Bottom