Christian de Bellefeuille
asked on
How to get the "Chart" object in an Access Form from VBA (Without using ActiveChart)
I'm creating a program with RSView32. It allow me to create some code with VBA.
I've created an Access file to be able to produce my reports. I have to change the
Minimum and Maximum value for the Y Axis of my chart with my code.
I can't figure out how i can reach my Axis. I'm stuck because i can't get this Chart
object.
Dim AppAccess As New Access.Application
Dim f As Form
Dim chart as Graph.Chart
Dim o As Object
AppAccess.OpenCurrentDatab ase "C:\LOREAL\ReportingEngine .mdb"
AppAccess.DoCmd.OpenForm ("TREND_FT_PEROX")
Set f = AppAccess.Forms("TREND_FT_ PEROX")
Set chart = f.Controls(0) ' I know that my chart is at index 0. But this cause an error.
Set o = f.Controls(0) ' This doesn't cause any error.
It keep telling me "Can't find project or library".
As soon as i get that object, i'll be able to reach the Axis and Scaling of my axes and i'll be able to change my minimum and maximum value. But please, keep in mind that i can't use "ActiveChart"... i must open my Access file from my VB code, then open my form, then access my chart, then access my axis, then my minimum and maximum properties.
Thanks for your help.
I've created an Access file to be able to produce my reports. I have to change the
Minimum and Maximum value for the Y Axis of my chart with my code.
I can't figure out how i can reach my Axis. I'm stuck because i can't get this Chart
object.
Dim AppAccess As New Access.Application
Dim f As Form
Dim chart as Graph.Chart
Dim o As Object
AppAccess.OpenCurrentDatab
AppAccess.DoCmd.OpenForm ("TREND_FT_PEROX")
Set f = AppAccess.Forms("TREND_FT_
Set chart = f.Controls(0) ' I know that my chart is at index 0. But this cause an error.
Set o = f.Controls(0) ' This doesn't cause any error.
It keep telling me "Can't find project or library".
As soon as i get that object, i'll be able to reach the Axis and Scaling of my axes and i'll be able to change my minimum and maximum value. But please, keep in mind that i can't use "ActiveChart"... i must open my Access file from my VB code, then open my form, then access my chart, then access my axis, then my minimum and maximum properties.
Thanks for your help.
I sounds like the library that defines the object Graph.Chart isn't referenced in the VBA project.
If you have set this reference you could also try:-
Set chart = f.Controls(0).object
Anthony.
If you have set this reference you could also try:-
Set chart = f.Controls(0).object
Anthony.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Change:
Set chart = f.Controls(0) ' I know that my chart is at index 0. But this cause an error.
Set o = f.Controls(0) ' This doesn't cause any error.
to:
Set o = f.Controls(0) ' This doesn't cause any error.
Msgbox TypeName(o)
and tell us what happens.
Set chart = f.Controls(0) ' I know that my chart is at index 0. But this cause an error.
Set o = f.Controls(0) ' This doesn't cause any error.
to:
Set o = f.Controls(0) ' This doesn't cause any error.
Msgbox TypeName(o)
and tell us what happens.
ASKER
Sorry for not answering for so long.
i had to do that code quite fast (that's the reason why i gave 500 pts for this question). But since i had to finish that fast, i had to use a less flexible solution. I had to give the points to somebody... so here some points for you Sizey.
Anthony: Could have been that, but it is already referenced.
Sizey: Not working anyway. I've not tried that under Visual Basic, but i can tell you that with RSView32 VBA, it doesn't work. When i type "f." i don't see anything like "GraphX"... i see Application, Form, Parent, Report. When i type ".form." i don't see anything like "BackColor". I also tried to declare F as Access.Form but it's the same.
I'll try later to see if in VB6 it does the same thing... maybe it's just a problem of RSView32 VBA. It wouldn't be the first time!!
Thanks to all of you
i had to do that code quite fast (that's the reason why i gave 500 pts for this question). But since i had to finish that fast, i had to use a less flexible solution. I had to give the points to somebody... so here some points for you Sizey.
Anthony: Could have been that, but it is already referenced.
Sizey: Not working anyway. I've not tried that under Visual Basic, but i can tell you that with RSView32 VBA, it doesn't work. When i type "f." i don't see anything like "GraphX"... i see Application, Form, Parent, Report. When i type ".form." i don't see anything like "BackColor". I also tried to declare F as Access.Form but it's the same.
I'll try later to see if in VB6 it does the same thing... maybe it's just a problem of RSView32 VBA. It wouldn't be the first time!!
Thanks to all of you
ASKER