Search code examples
ms-accesschartsproperties

How to change primary and secondary unit of a chart (scatter plot) in vba in MS-Access?


I make a scatter plot chart with Access and I preset the primary unit to 250000 and the secondary unit to 50000. Initial chart To change the minimum and maximum of the chart with the textbox above the chart, I finally find the right chart properties with this code :

        Graphique1.Object.axes(1, 1).minimumscale = Texte2.Value  ' For minimum x axe 
        Graphique1.Object.axes(2, 1).minimumscale = Texte2.Value  ' For minimum y axe 
        
        Graphique1.Object.axes(1, 1).maximumscale = Texte4.Value  ' For maximum x axe 
        Graphique1.Object.axes(2, 1).maximumscale = Texte4.Value  ' For maximum y axe

But, when, for example, I focus on my chart and set the maximum scale to 120000, I lost the primary unit. So, I want to change its value, but I don't know where I can find this variable.

I tried to find something in MS-Access documentation, so I tried this code but it makes an Execution error '438'

        Graphique1.Object.axes(1, 1).primaryunit = 1000
'''
or
'''
        Graphique1.Object.axes(1, 1).PrimaryValuesAxisDisplayUnits = 1000

Does someone know how to change this chart property ? Thanks


Solution

  • Example below will modify Y axis units. Instead of repeating Graphique1.Object, could use With:

    With Graphique1.Object         
    ...
       .Axes(xlValue).MinorUnit = 200
       .Axes(xlValue).MajorUnit = 1000
    ...
    End With
    

    Use xlCategory for X axis.

    If you prefer numeric equivalents:
    xlValue = 2
    xlCategory = 1