Changin Chart properties programatically (1 Viewer)

MikeSr

Registered User.
Local time
Today, 12:16
Joined
Jul 30, 2009
Messages
24
I am recording pH data accross in the y axis and displaying the time stamp on the x axis. Depending on the duration of the report, Daily, weekly, monthly, The x axis gets pretty jammed up with time values.
I have tried to use the "Graph" Class and its members, but they allways error out. The "Graph" is selecected in the object browers, I see the classes and the members, code them in (most likely the wrong way) and I get this error message "Run-time error "483" object doesn't support this property or method.

I need to make some adjustments to my charts but just cant seem to find out how in vb.

Any help for this newbie would be appreciated.:)
 

jjmclell

Registered User.
Local time
Today, 09:16
Joined
Aug 10, 2009
Messages
22
It would help if you posted the code you've been working on. I've been doing a lot lately with graphs in access and could maybe help if I see where you're at.

jjmclell
 

jjmclell

Registered User.
Local time
Today, 09:16
Joined
Aug 10, 2009
Messages
22
It would help if you posted the code you've been working on. I've been doing a lot lately with graphs in access and could maybe help if I see where you're at.

jjmclell
 

MikeSr

Registered User.
Local time
Today, 12:16
Joined
Jul 30, 2009
Messages
24
I appreciate your reply. The code i have been trying is wrong. I apparently don't understand how to use the graph class and it methods. For example, in my simple mind I tried:
Graph0.axistitle.caption = "something"
Where Graph0 is the name of my graph object.
Sorry for the lack of knowlege here.

Thanks
 

jjmclell

Registered User.
Local time
Today, 09:16
Joined
Aug 10, 2009
Messages
22
This code would set the axistitle name for a chart embedded in a form. Charts done in access or excel use the MSGraph application so here's what you have to do:

Code:
Dim myChart as Object
Set myChart = Form_Charts.Graph1.Object.Application.Chart
 
With myChart.Axes(xlCategory)
    .HasTitle = True
    .AxisTitle.Text = "July Sales"
End With

So, to break it down... If your chart is in a form (or report), you have to:

1) refer to the form (or report) name (Form_Charts)

2) refer to the name of the object frame holding your chart (.Graph1)

3) refer to the object within the frame (.Object)

4) refer to the application that created the object (.Application)

5) refer to the actual chart itself (.Chart)

6) refer to the axes collection and select the axis you want to reference - in this case the category, or X-axis (.Axes(xlCategory))

7) if you want to set a title on a chart, you have to tell it that it first has a title (.HasTitle = True), and then you can set the axis title name (.AxisTitle = "July Sales")

If you go C:\Program Files\Microsoft Office\OFFICE11\1033\VBAGR10.CHM, that'll give you the reference help file for MSGraph, which gives you all the objects, properties, and methods for formatting your charts. There aren't all that many and it's actually pretty easy to work with charts.
 

jjmclell

Registered User.
Local time
Today, 09:16
Joined
Aug 10, 2009
Messages
22
This code would set the axistitle name for a chart embedded in a form. Charts done in access or excel use the MSGraph application so here's what you have to do:

Code:
Dim myChart as Object
Set myChart = Form_Charts.Graph1.Object.Application.Chart
 
With myChart.Axes(xlCategory)
    .HasTitle = True
    .AxisTitle.Text = "July Sales"
End With

So, to break it down... If your chart is in a form (or report), you have to:

1) refer to the form (or report) name (Form_Charts)

2) refer to the name of the object frame holding your chart (.Graph1)

3) refer to the object within the frame (.Object)

4) refer to the application that created the object (.Application)

5) refer to the actual chart itself (.Chart)

6) refer to the axes collection and select the axis you want to reference - in this case the category, or X-axis (.Axes(xlCategory))

7) if you want to set a title on a chart, you have to tell it that it first has a title (.HasTitle = True), and then you can set the axis title name (.AxisTitle = "July Sales")

If you go C:\Program Files\Microsoft Office\OFFICE11\1033\VBAGR10.CHM, that'll give you the reference help file for MSGraph, which gives you all the objects, properties, and methods for formatting your charts. There aren't all that many and it's actually pretty easy to work with charts.
 

MikeSr

Registered User.
Local time
Today, 12:16
Joined
Jul 30, 2009
Messages
24
Thanks for the detailed response. I guess I am still confused.
I have a report called "ph1", There isn't any object container that I can see other than the graph object iteself "Graph0". So my syntax would be :
Set Mychart = ph1.graph0.????
What object within the frame?
The application that created the object ? example?
Isn't the actual chart itself Graph0?

I would love to get my arms around this, but I not following your very detailed example well enough.
Thanks for being so patient. :)
 

darbid

Registered User.
Local time
Today, 17:16
Joined
Jun 26, 2008
Messages
1,428
Thanks for the detailed response. I guess I am still confused.
I have a report called "ph1", There isn't any object container that I can see other than the graph object iteself "Graph0". So my syntax would be :
Set Mychart = ph1.graph0.????
What object within the frame?
The application that created the object ? example?
Isn't the actual chart itself Graph0?

I would love to get my arms around this, but I not following your very detailed example well enough.
Thanks for being so patient. :)

I am not as experienced as some people here so maybe I will explain this the dumb way.

I assume you have used the wizard to put a graph on a form.
You talk about Graph0 - If you click on the form to bring up the properties sheet for the graph then you will be able to call it a name.
So you can keep the default name or call it some thing else.
Next as you see above people are suggesting to "set the graph as an object"
There is another way (i am not commenting on which way is best, just informing you)
Code:
Me.Graph0.ChartTitle.Text =  "My First Graph"
Me![Graph0].ChartTitle.Text = "My First Graph"

Using the Me might make you feel better. But Intellisense will not work for you.

Now MSGraph which is what you are using here is a basic version of the Chart in excel and there are a lot of similarities. So one way to get to know how to do things is make a similar chart in an excel sheet and then while recording a macro make your changes. This will give you an idea of what to do with the graph.

Remember you will always have to work out what comes after the "Me.Graph0." or you will have to work out what to replace from the Excel macro with "Me.Graph0".

It will error sometimes as they are different in some ways.
 

MikeSr

Registered User.
Local time
Today, 12:16
Joined
Jul 30, 2009
Messages
24
Thanks for the reply. I think the problem is this :
When I enter the code Me.Graph0. xxxx this is where the intellisense offers specific methods, like Backcolor. When I use those they work, however the methods like "ChartTitle" don't show up. I enter them but they don't work.
It seems as though something is missing in my installation.
Shouldn't the "charttitle show up in the drop down when I am entering the method?
I hope Method is the correct term here.

Thanks again
:)
 

darbid

Registered User.
Local time
Today, 17:16
Joined
Jun 26, 2008
Messages
1,428
Thanks for the reply. I think the problem is this :
When I enter the code Me.Graph0. xxxx this is where the intellisense offers specific methods, like Backcolor. When I use those they work, however the methods like "ChartTitle" don't show up. I enter them but they don't work.
It seems as though something is missing in my installation.
Shouldn't the "charttitle show up in the drop down when I am entering the method?
I hope Method is the correct term here.

Thanks again
:)

I have never used intellisense for Graph. To use intellisense you would have to have a reference to MSGraph and you would have to set an object to an MSGraph. But I do not do this because I do not want to add yet another reference to break or have problems with.

In my "other suggested method" intellisense will not work and you cannot trust what is suggested.
 

MikeSr

Registered User.
Local time
Today, 12:16
Joined
Jul 30, 2009
Messages
24
Any idea why when I use the syntax you illustrate that I get the following error:
"Run-time error 438"
Object doesn't support this property or method

me.graph0.chartTitle.text = "something"
 

darbid

Registered User.
Local time
Today, 17:16
Joined
Jun 26, 2008
Messages
1,428
Not sure but does your graph have a title? You could add one at design time then just change the text later.

Or I think - and I think cause I cannot check this, at run time try this

Me.Graph0.ChartTitle.HasTitle = True

But I am not sure this is correct. You need to look in the object browser.
 

MikeSr

Registered User.
Local time
Today, 12:16
Joined
Jul 30, 2009
Messages
24
After googling I appears that there might be a problem when upgrading from Access 2003 to Access 2007. The Microsoft Graph 12.0 object library is obviously not working.
Now the question is how to fix it. Don't know where to go from here. But I think this has been the problem right along.
 

MikeSr

Registered User.
Local time
Today, 12:16
Joined
Jul 30, 2009
Messages
24
Ok, here is what I have so far,

I add the following code:

Dim mygraph as chart

Set mygraph = me.graph0.object

etc...

What happens is I get error message 2771 "The bound or unbound object frame you tried to edit doesn't conatin an OLE object"

How do I fix this? I have a graph on a report. The graph object is "Graph0"
Sure wish I new more to get through this:
 

MikeSr

Registered User.
Local time
Today, 12:16
Joined
Jul 30, 2009
Messages
24
Learned a bit more. I was using a report with a chart object on it. Apparently you cannot use a report. Once I used a standard form with the "Default View" property set to "Single Form". I was then able to access the Chart properties programaticly.
Try this using a report, and it doesn't work.
 

nwhaught

New member
Local time
Today, 10:16
Joined
Nov 24, 2014
Messages
1
This thread is long dead, but in case anyone finds this thread like I did, there is a workaround to the issue of setting chart properties on a report. Basically, you need to set the focus on the report before the OLE objects load. Like so:
Private Sub Report_Open(Cancel As Integer)
Dim ch As Object
Me.Check12.SetFocus
Set ch = Me.Graph3.Object.Application.Chart
ch.ChartTitle.text = OpenArgs
End Sub
 

Users who are viewing this thread

Top Bottom