Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 Data Fields in Pivot Chart

Status
Not open for further replies.

spongie1

Technical User
Nov 24, 2003
57
US
I am using Access 2002.

I want to use VBA to add two data fields to my pivot chart.

I want the chart to contain Employee names across the X axis, and two plots, one of efficiency and one of shifts worked on the same chart.

I have a working example that I was able to construct by dragging and dropping the fields in the proper locations.

However, I am not familiar enough with VBA to get the same results through coding.

Here is a snippet of my code. I believe that I am close... maybe..

Code:
'************************************
' Open form in pivotchart view
'************************************
  
  frmNm = "frmPEOperatorProductLine12"
  'close the form first
  DoCmd.Close acForm, frmNm, acSaveNo
  
  'then open the form
  DoCmd.OpenForm frmNm, acFormPivotChart
  
  Set frm = Forms(frmNm)
  
  
'************************************
' Connect to Data Source
'************************************
  
  Set sConn = New ADODB.Connection
  
  sConn.ConnectionString = CurrentProject.Connection.ConnectionString
  sConn.CursorLocation = adUseClient

  sConn.Open
  
  Set oRS = New ADODB.Recordset
  
  oRS.Open strSQL, sConn, 3, 3
  Set objChartSpace = frm.ChartSpace
  objChartSpace.Clear
  
  Set objChartSpace.DataSource = oRS
  objChartSpace.DisplayFieldButtons = False
  
  Set objPivotChart = objChartSpace.Charts.Item(0)

  '************************************
  ' Add Data To Chart
  '************************************
     
 [b]    
  objChartSpace.SetData chDimCategories, chDataBound, Array("PE", "mOperator", "Shifts")
  objChartSpace.SetData chDimValues, chDataBound, "PE"
[/b]
  
  '************************************
  ' Add Axis Titles
 '************************************
  
  Dim NwScale As ChScaling
  Dim NwAxis As ChAxis
  
  Set NwScale = objChartSpace.Charts.Item(0).Axes.Item(1).Scaling
  Set NwAxis = objChartSpace.Charts.Item(0).Axes.Add(NwScale)
  
  
  'Category Axis or X Axis
  objChartSpace.Charts.Item(0).Axes(0).HasTitle = True
  objChartSpace.Charts.Item(0).Axes(0).Title.Caption = "Performance / Operator / Shift"
  
  
  'Value Axis 1 or Y Axis 2
  objChartSpace.Charts.Item(0).Axes(1).HasTitle = True
  objChartSpace.Charts.Item(0).Axes(1).Title.Caption = "Performance"
  objChartSpace.Charts.Item(0).Axes(1).NumberFormat = "Percent"
  objChartSpace.Charts.Item(0).Axes(1).MajorUnit = 0.1
  
  'Value Axis 2 or Y Axis 2
  objChartSpace.Charts.Item(0).Axes(2).HasTitle = True
  objChartSpace.Charts.Item(0).Axes(2).Position = chAxisPositionRight
  objChartSpace.Charts.Item(0).Axes(2).Title.Caption = "Shifts"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top