Results 1 to 8 of 8
  1. #1
    jscriptor09 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    60

    need vba to scale Pivot chart

    Hi folks



    Right now, I have a query set up to write to a table, and a Pivot chart that plots off the table. The data range in the table changes depending on dept/functions and so forth.

    I need the ability to rescale the pivot chart Y axis on the fly using vba. The line of thought is that I can determine the range from looking at the table before calling the Form that has the PIVOT chart.

    Question:
    Given that I have a pivot chart Form in place, how do I point to it using VBA and what would be the logic to change the scale. Please note that I have several forms with PIVOT chart. I need to be able to select specific one out of the collection

    Many thanks for you help

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    I don't have any pivot charts and don't have any charts on forms. I do have charts on reports and set axis scales with VBA. Example:
    Code:
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    'Plot Graphs procedure
    Dim MinUWT As Double, MaxUWT As Double
    Dim MinDry As Double, MaxDry As Double
    Dim MinSoak As Double, MaxSoak As Double
    Dim MinRet As Double, MaxRet As Double
    With Me
    If Not IsNull(!MinOfA) Then
        MinUWT = Int(!MinOfU) - Int((10 - (Int(!MaxOfU) + 1 - Int(!MinOfU))) / 2)
        MaxUWT = MinUWT + 10
        MinDry = Int(!MinOfD / 5) * 5 - (50 - Int((Int(!MaxOfD / 5) * 5 + 5 - Int(!MinOfD / 5) * 5) / 10) * 10) / 2
        MaxDry = MinDry + 50
        MinSoak = Int(!MinOfS / 5) * 5 - (50 - Int((Int(!MaxOfS / 5) * 5 + 5 - Int(!MinOfS / 5) * 5) / 10) * 10) / 2
        MaxSoak = MinSoak + 50
        MinRet = Int(!MinOfR / 5) * 5 - (50 - Int((Int(!MaxOfR / 5) * 5 + 5 - Int(!MinOfR / 5) * 5) / 10) * 10) / 2
        MaxRet = MinRet + 50
        .gphWeight.Axes(xlValue).MinimumScale = MinUWT
        .gphWeight.Axes(xlValue).MaximumScale = MaxUWT
        .gphITSdry.Axes(xlValue).MinimumScale = MinDry
        .gphITSdry.Axes(xlValue).MaximumScale = MaxDry
        .gphITSsoak.Axes(xlValue).MinimumScale = MinSoak
        .gphITSsoak.Axes(xlValue).MaximumScale = MaxSoak
        .gphITSret.Axes(xlValue).MinimumScale = MinRet
        .gphITSret.Axes(xlValue).MaximumScale = MaxRet
        If Me!Metric = True Then
            .gphWeight.Axes(xlValue, xlPrimary).AxisTitle.Text = "Unit Weight, kg/cu.cm"
            .gphGradation.Axes(xlCategory, xlPrimary).AxisTitle.Text = "Sieve Size (mm)"
            .gphITSdry.Axes(xlValue, xlPrimary).AxisTitle.Text = "ITS Dry, kg/cu.cm"
            .gphITSsoak.Axes(xlValue, xlPrimary).AxisTitle.Text = "ITS Soaked, kg/cu.cm"
        End If
    End If
    End With
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    jscriptor09 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    60
    Thank you June7

    The problem is that I don't know what is the equivalent of Me.gphWeight (for example) in a form that has a PivotChart in it.

    I am hoping someone will have a clue of the object model behind the pivotchart.

    Thanks

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    jscriptor09 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    60
    Hi June7

    Many thanks for the references. One of them hit the mark.

    I would like to set the chart majortick value on the Primary Y as follows:
    1- Get whatever Primary Y value ACCESS decides to give the chart based on the data
    2- Adjust upward so the number is divisible by 10 (or some other logic).
    3- set majorTicks to the value determined in step 2.

    Here is what I have:

    Private oChart As ChChart
    Private oCategoryAxis As ChAxis
    Private oValueAxis As ChAxis
    Private oBackWall As ChSurface

    Private Sub button_Click()
    Dim maxY As Integer
    '
    'Activate the Chart
    If Not CurrentProject.AllForms("frm_VDR_OTD_Chart").IsLoa ded Then
    DoCmd.OpenForm "frm_aChart", acFormPivotChart, , , , acHidden
    End If

    ' theMax = Call getMax <<<<<<<<<< I am stuck here

    Set oChart = Forms("frm_aChart").ChartSpace.Charts(0)
    Set oCategoryAxis = oChart.Axes(0)
    Set oValueAxis = oChart.Axes(1)
    'oValueAxis.MajorUnit = Abs(theMax / 10) ' sort of what I am trying to do
    DoCmd.Close acForm, "frm_aChart", acSaveYes
    End Sub

    The reason I need to control the majortick is because I have a secondary axis % going from 0 to 100% which has own majorTicks. I want to make sure that the Primary and secondary axis majortick lines line-up.

    Is there a way to retrieve the max Y value that the chart object is going to use for the chart (I let the chart auto scale)

    Thanks for the help

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    Of course, how depends on your data.

    All of my graphs are based on UNION queries because of the table structures. Essentially I have to 'normalize' the data for graphing.

    I use a subquery in the Report RecordSource that returns the Max and Min values from the UNION query. This makes the values available for the code to calculate scale range.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    ddk is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    5
    Does the solution above work in a compiled version of the database (.mde, .accde)?

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    I have never used mde or accde. However, I have doubts. Try it and let us know.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Pivot Chart
    By Phoenyxsgirl in forum Forms
    Replies: 4
    Last Post: 11-08-2011, 02:04 PM
  2. pivot chart
    By jscriptor09 in forum Access
    Replies: 0
    Last Post: 07-10-2011, 08:16 AM
  3. Pivot Chart help.
    By lorenambrose in forum Access
    Replies: 8
    Last Post: 02-16-2011, 12:02 PM
  4. Replies: 2
    Last Post: 07-12-2010, 05:39 AM
  5. Creating a Pivot Chart....
    By spcalan in forum Access
    Replies: 0
    Last Post: 01-08-2009, 03:28 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums