467,134 Members | 1,047 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,134 developers. It's quick & easy.

MS Graph - Late Binding Question

Hi .. I have an issue I have been beating my head against
the wall on for some time. I am trying to use late
binding for MS graph so that my end users don't have to
worry about having the right version of the MS Graph type
library. Up until now I have been walking them through
the process of setting the references to include their
version of MS Graph library.

My problem is that I can not seem to get the syntax
correct .. or perhaps something else is wrong. Typically
what I have done is created a chart in a report by using
the chart wizard (i.e. Insert menu - Chart). I then walk
through the chart wizard select data source etc. The
datasource is typically set to be a query. A form is used
to gather user input and based on that input the qurey
definition is adjusted. In this way (i.e. adjusting the
query datasource of the chart) the same chart "template"
is used to display many different specific charts.

The report which contains the chart has some code which
controls display features. For example, if the user wants
to see the data in a pie chart display vs a column display
he or she can select the corresponding radio button on the
form and based on that selection the code behind the
report sets the chart type. In addition, the report
module controls what the title will be etc. I have been
trying to use late binding in this code so that I don't
need to be concerned with what version of MS Graph a given
computer may have. I have been having trouble doing this
though and I have had a very hard time finding any really
good info on this in the newsgroups or elsewhere (MSDN for
Specific Questions:
1. What type of object results when a chart wizard is used?
When I create a chart on a report from the chart wizard
(i.e. insert-chart) what type of object is created? Is
this an unbound frame or some different animal. The title
bar in the properties window indicates it is a "chart".
If I create a unbound object frame for a microsoft graph
by dragging an unbound object frame from the toolbox and
selecting Microsoft Graph... the title bar of the property
window for the resulting object indicates it is
an "unbound object frame". As such I am gathering that
the two objects are different but I am unclear on how they
are different.

2. How do I correctly impliment late binding?
The "chart" I have created in chart wizard is
named "gphSiteBreakdown". I have code in the onformat
event for the report which controls certain display
options for the chart. The code uses early binding and is
listed below.

Private Sub Detail_Format(Cancel As Integer, FormatCount
As Integer)
Dim txtTitle As String
Dim MyGraph As Graph.chart

Set MyGraph = Me!gphSiteBreakdown.Object


txtTitle = Forms!frmReports!cboChartType
'The following determines what option the users
selected for filtering the data and sets the title
Select Case Forms!frmReports!fraFilterBy
Case 1 'State
MyGraph.ChartTitle.Caption = txtTitle & "
Frequency - " & Forms!frmReports!cboState
Case 2 ' RPM
MyGraph.ChartTitle.Caption = txtTitle & "
Frequency - " & Forms!frmReports!cboRPM.Column(1)
Case 3 ' Region
MyGraph.ChartTitle.Caption = txtTitle & "
Frequency - Region IV"
End Select
MyGraph.ChartTitle.HorizontalAlignment = xlCenter

'The following code determines what style chart the
user has selected (pie or chart) and sets up certain
display options accordingly.
Select Case Forms!frmReports!fraChartStyle
Case 1 'Column
MyGraph.ChartType = xlColumnClustered
MyGraph.HasLegend = False
With MyGraph.PlotArea
.Width = 600
.Height = 600
.Left = 75
.Top = 75
End With
With MyGraph.SeriesCollection(1)
.HasDataLabels = False
End With
With MyGraph.Axes(xlCategory).TickLabels
.Font.Size = 8
.Orientation = 90
End With
With MyGraph.Axes(xlValue)
.MinorUnit = 1
.CrossesAt = 0
.HasTitle = True
.TickLabels.Font.Size = 14
With .AxisTitle
.Text = "Number of Sites"
.Orientation = 90
.Font.Size = 12
End With
End With
Case 2 'Pie
MyGraph.ChartType = xlPie
MyGraph.HasLegend = True
MyGraph.Legend.Font.Size = 12
With MyGraph.PlotArea
.Width = 450
.Left = 75
.Top = 75
End With
With MyGraph.SeriesCollection(1)
.HasDataLabels = True
.DataLabels.Position =
.DataLabels.Font.Size = 8
End With
End Select
End Sub

If I have the appropriate MS Graph library referenced all
is well and it works fine. If I don't however I get
errors. This all makes sense. The solution (I gather)
is to use late binding so that a specific version of the
MS Graph library is not required. My attempts at late
binding have failed however. I presume that to change the
code so as to use late binding as opposed to early binding
all I need to do is change the way the object variables
are dimensioned. In late binding I should dimension them
as object variables as opposed to specific graph object
variables. The only object variable I have used in the
above code is "MyChart" which is used to reference the
chart. If I change the declaration of this variable from:
dim MyGraph as Graph.Chart
dim MyGraph as object

and run the code with the graph library reference intact
it still works fine. However, if I remove the
reference ... which latebinding should allow me to do I
get an error which indicates it is unable to set the
horizontal alignment property of the charttitle class
(error 1004). If I comment out this line I get a
different error (error 13 - type mismatch for the line:
MyGraph.ChartType = xlColumnClustered).
Can anyone tell me what I might be doing wrong?

Thanks much .... JD
Nov 12 '05 #1
  • viewed: 7524
1 Reply
Without the library reference, Access does not know the integer value of
"xlColumnClustered"...not any other named constants referenced in the target

The best way to get around this is to create a Constant variable of the same
name within your Access module, at the top, after the Dim statements, like so:

Const xlColumnClustered As Long = 51

I've also had issues with nested With structures using automation...I avoid
Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Zlatko Matić | last post: by
8 posts views Thread by scorpion53061 | last post: by
5 posts views Thread by eBob.com | last post: by
30 posts views Thread by lgbjr | last post: by
6 posts views Thread by Tim Roberts | last post: by
6 posts views Thread by Stephany Young | last post: by
14 posts views Thread by Siv | last post: by
4 posts views Thread by =?Utf-8?B?Y2xhcmE=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.