Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export Access Chart as GIF? 1

Status
Not open for further replies.

Wiz0fBaud

Technical User
Jul 2, 2003
45
US
Hello All-

I am putting together an access database/form combo, so that that everyone can easily keep track of our project management and hours. The whole idea is that once a project is finished we will be able to spit out some useful data. One of these pieces of data would be a chart.

I am told that MS Charts/Graphs are embedded objects and have problems playing well in other applications. For example I'd like to export the chart/graph into PowerPoint for a financial presentation. I have read/heard that this doesn't work well.

I have heard rumors of the possibility of exporting the graph into a GIF/JPEG format. I was basically wondering if anyone knows how to do this or any other similar method from a report or some other access module.

I was thinking, that if I am able to get the GIF out, then I could import the picture into PowerPoint and "link" it so that when the gif changes (not the file name) PowerPoint will automatically be updated. Is this a plausible situation or no?

Does anyone have any ideas or other suggestions?

I found an article in MSDN about this, but I am no coding guru, I'm barely an access novice, and I’m just looking for a simple way to do this. Although I would really like to understand it.

Thanks for any help you may provide, it is greatly appreciated.
 
I have used acrobat as an intermediary. printing the chart to acrobat and then converting the acrobat file to GIF
 
I was reading about this option....


but I don't quite understand how to use this...

Me.objGraph.Export "c:\temp\graph.gif", "GIF", False


Basically I want to create a report and when it is created that chart contained in the report is immediately exported to gif, so I can insert it as a picture in MS Powerpoint?
 
You can put it on the OnFormat event of the detail of your report. As soon as the report is loaded it spits out your gif.

As an alternative, I have a routine that exports the Chart straight to Word, I'm sure it could be converted to Powerpoint, probably using some of the ideas and code from Wiz's link.

Basically I copy the chart to the clipboard:

Set frm = Forms!frmchart
Set ctl = Forms!frmchart.chtChart
frm(ctl.Name).SetFocus
DoCmd.RunCommand acCmdCopy

then do all the bits to find the right place in word, then

wd.Selection.PasteSpecial False, wdPasteOLEObject, wdFloatOverText, False
paste the whole chart into the document. This gives an editable chart that can be further customized if needed.

hth

Ben

----------------------------------------------
Ben O'Hara "Where are all the stupid people from...
...And how'd they get so dumb?"
rockband.gif
NoFX-The Decline
----------------------------------------------
 
I think I understand the first part, I put that code in a module to put it in the clipboard.

Then I want to put it in Word. What do I do with that second code. In fact for my purposes I actually want to put it in Word as an object and then copy this object from Word to Publisher manually. Can I do this and can I just paste using the edit/paste or paste special menu commands?

Thanks
 
This is my full function.

It copies the chart in the control chtChart on the form frmchart into the clipboard, opens a new instance of word, and pastes the image into a new document.

There's no error handling or comments in it, but it fairly straight forward.

hth

Ben

Code:
Public Const wdPasteOLEObject = 0
Public Const wdFloatOverText = 1

Function ExportChartToFile()
Dim wd As Object
Dim frm As Form
Dim ctl As Control
    Set frm = Forms!frmchart
    Set ctl = Forms!frmchart.chtChart
    frm(ctl.Name).SetFocus
    DoCmd.RunCommand acCmdCopy

    With CreateObject("Word.Application")
        .Visible = True
        .Documents.Add
        .Selection.PasteSpecial False, wdPasteOLEObject, wdFloatOverText, False
    End With

End Function

----------------------------------------------
Ben O'Hara "Where are all the stupid people from...
...And how'd they get so dumb?"
rockband.gif
NoFX-The Decline
----------------------------------------------
 
Thanks,

I'm not at a computer that I can try it at now. I see that you are getting the chart from a form. I'm getting it from a report. I assume I would just substitute forms!formchrt with reports!reportchrt.

I also am not sure what event to put this in - on open?

Thanks,

please bear with me I just know little bits and pieces of VB.
 
I missed the fact of it being on a report. You may struggle with this then. AFAIK you can't use setfocus on a report.
You may have to create a form that just has the exact same chart on it, then in the report, open the form, change the data on the form to match the report, export the chart and close it again. It should happen so quickly the user will hardly see the screen change.

hth

Ben

----------------------------------------------
Ben O'Hara "Where are all the stupid people from...
...And how'd they get so dumb?"
rockband.gif
NoFX-The Decline
----------------------------------------------
 
For my purposes I only want to generate the chart for another report so I can just do it in the form and export it. I've copied the chart into a form alright.

I added a control button and put your code into the on click event and get a compile error at:

Public Const wdPasteOLEObject = 0

In:

Private Sub Command2_Click()
Public Const wdPasteOLEObject = 0
Public Const wdFloatOverText = 1

Function ExportChartToFile()
Dim wd As Object
Dim frm As Form
Dim ctl As Control
Set frm = Forms!form1
Set ctl = Forms!form1.chrtChart
frm(ctl.Name).SetFocus
DoCmd.RunCommand acCmdCopy

With CreateObject("Word.Application")
.Visible = True
.Documents.Add
.Selection.PasteSpecial False, wdPasteOLEObject, wdFloatOverText, False
End With

End Function


I've turned on the references to the Word Object Library
 
I've turned on the references to the Word Object Library
So you don't have to redefine the word's constants.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
You've pasted your function into the subroutine called by your button.
If you are using the Word Reference, you can ignore the constants as phv says, then paste the function into a empty module.
Code:
Sub ExportChartToFile()
Dim wd As New Word.Application
Dim frm As Form
Dim ctl As Control
    Set frm = Forms!form1
    Set ctl = Forms!form1.chrtChart
    frm(ctl.Name).SetFocus
    DoCmd.RunCommand acCmdCopy

    With wd
        .Visible = True
        .Documents.Add
        .Selection.PasteSpecial False, wdPasteOLEObject, wdFloatOverText, False
    End With
    Set wd=Nothing
End Sub

Then behind the button you are calling the code from just put:
Code:
Call ExportChartToFile()

I've changed it from a function to a sub routine, mainly by convention as it was a function that didn't return anything.

Try that and let us know how you get on.

Ben

----------------------------------------------
Ben O'Hara "Where are all the stupid people from...
...And how'd they get so dumb?"
rockband.gif
NoFX-The Decline
----------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top