Unable to set scale for second chart on a form

Alc

Registered User.
Local time
Yesterday, 23:02
Joined
Mar 23, 2007
Messages
2,421
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?

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
 
The code looks okay!
Try:

  • Compact & Repair
  • Delete the problem graph and put in a new one.
Else post a stripped down version of your database with some sample data.
 
Thanks for the response.

I managed to locate that the issue was caused by having "hidden" the axis on the second and third graph, so that I could display them overlapping the first. I added the axis back in and, instead, changed the font colour to be white, so that it still can't be seen.

All appears to be working now.
 

Users who are viewing this thread

Back
Top Bottom