I have three graphs (two line and a bar) on a form. I want each to display their data on the same scale and I'm trying to accomplish this using VBA I found on this forum and elsewhere.
The following code works fine down to the bold red line, then errors with the message "Run-time error '1004': Unable to set the MaximumScale property of the axis class".
1) The recordsource for each graph definitely returns some records and each graph displays without problems if I just open it, so I know an empty recordset isn't the problem.
2) I've tried changing the sequence of events, in case Access was just having problems setting more than the first graph. This didn't help
3) I've tried commenting out the code relating to all bar one of the charts. This didn't help.
3) I've tried converting the problematic graphs from line (which I want) to bar, in case the type was the problem. This didn't help.
I'm using Access 2010, if that makes any difference.
Any thoughts?
The following code works fine down to the bold red line, then errors with the message "Run-time error '1004': Unable to set the MaximumScale property of the axis class".
1) The recordsource for each graph definitely returns some records and each graph displays without problems if I just open it, so I know an empty recordset isn't the problem.
2) I've tried changing the sequence of events, in case Access was just having problems setting more than the first graph. This didn't help
3) I've tried commenting out the code relating to all bar one of the charts. This didn't help.
3) I've tried converting the problematic graphs from line (which I want) to bar, in case the type was the problem. This didn't help.
I'm using Access 2010, if that makes any difference.
Any thoughts?
Code:
Dim strCamp As String
Dim llMaxScale As Long
Dim lobjAxisY1 As Object
Dim lobjAxisY2 As Object
Dim lobjAxisY3 As Object
Dim lobjChart1 As Object
Dim lobjChart2 As Object
Dim lobjChart3 As Object
Dim Rst As Recordset
Dim QDF As QueryDef
Dim strSQL As String
Set QDF = CurrentDb.QueryDefs("qryCampaignDaysElapsed")
strSQL = QDF.SQL
Set Rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
If Not Rst.EOF Then
llMaxScale = DMax("DaysElapsed", "qryCampaignDaysElapsed")
If llMaxScale < 60 Then
llMaxScale = 72
Else
llMaxScale = llMaxScale * 1.2
End If
Set lobjChart1 = Me!GraphBar.Object
Set lobjAxisY1 = lobjChart1.Axes(2)
lobjAxisY1.maximumscale = llMaxScale
lobjAxisY1.minimumscale = 0
Me!GraphBar.Requery
Set lobjChart2 = Me!GraphOfficialTarget.Object
Set lobjAxisY2 = lobjChart2.Axes(2)
[COLOR=red][B]lobjAxisY2.maximumscale = llMaxScale[/B][/COLOR]
lobjAxisY2.minimumscale = 0
Me!GraphOfficialTarget.Requery
Set lobjChart3 = Me!GraphInternalTarget.Object
Set lobjAxisY3 = lobjChart3.Axes(2)
lobjAxisY3.maximumscale = llMaxScale
lobjAxisY3.minimumscale = 0
Me!GraphInternalTarget.Requery
Else
MsgBox "no records"
End If