Full Version: Changing Chart types using VB
UtterAccess Discussion Forums > Microsoft® Access > Access Reports
justin84
I have a chart in a report, and I would like to be able to change its type (say from line to bar) using visual basic, but i can't figure out how?

Any suggestions?

Thanks,
Justin
cs51
Hello for the same type of my problem KingMartin has given the solution for me .That solution is as follows
CODE
Sub ChangeChartType()

Dim Sht As Worksheet

Dim Cht As ChartObject

   For Each Sht In ThisWorkbook.Worksheets  

      For Each Cht In Sht.ChartObjects    

        Cht.Chart.ChartType = xlLine    ' you can change  any chart type here instead of X1Line

           Next Cht  

          Next Sht

End Sub



--------------------------------------------------------------------------------

I hope you can adapt this to your requirements
Thanks To kingMartin
thanks to you
thanks.gif

Edited by: cs51 on 03.09.04.
justin84
No luck yet.

When I run:

Debug.Print Me.ReportChart.Object.Application.Chart.ChartType

I get the following error:

2771 - The bound or unbound object frame you tries to edit doesn't contain an OLE Object

Does it matter that the chart is in a report?

Thanks,
Justin
cs51
Sorry this works fine in Excel charts
As the chart is in report it may not be working
you can give reference to excel object by using Tools > references in VBE (alt+F11) and click checkmark against Microsoft Excel 9.0 Object library and try the above code
Thanks
cs51
Hello one more suggestion
Instead of pasting chart in your report using unbound frame object(after browsing for the file which contains the chart) , you can check a mark against Link
When you are linking to the source whatever you change in source it will be reflected in your report also.In this way I hope you can solve your problem
Thanks

cs

thanks.gif
Aart
I'm getting the same error on a form with an ActiveX control (Spin Button). When the filtered form returns 0 records, it returns that error. I "solved' it by setting AllowAdditions = True.
Not the same problem as yours but the quirks in Access work in mysterious ways. Hope it might help.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.