Article ID: 182131
Article Last Modified on 1/22/2007
Private Sub Form_Current()
Dim chtObj As Object, strRowSource As String
Dim rsRowSourceFiltered As Recordset
Dim intMaxShippers As Integer
Dim i As Integer, j As Integer
Set chtObj = Me!chtSync.Object
intMaxShippers = 3
' In the chart's RowSource, insert a WHERE
' clause based on the value of the form
' field contained in the chart control's
' LinkMasterFields property.
strRowSource = Left(Me!chtSync.RowSource, _
InStr(Me!chtSync.RowSource, "GROUP BY") - 1) _
& "WHERE " & Me!chtSync.LinkChildFields & _
" = '" & Me(Me!chtSync.LinkMasterFields) & _
"'" & " " & Right(Me!chtSync.RowSource, _
Len(Me!chtSync.RowSource) _
- InStr(Me!chtSync.RowSource, "GROUP BY") + 1)
Set rsRowSourceFiltered = CurrentDb. _
OpenRecordset(strRowSource, dbOpenSnapshot)
' Check to see if the filtered recordset has any records.
If rsRowSourceFiltered.BOF And _
rsRowSourceFiltered.EOF Then
MsgBox "There are no records to chart."
Exit Sub
End If
' Clear the rows required for the maximum number of
' data rows. The first row contains the column
' headers. Data rows begin at the second row.
With chtObj.Application.DataSheet
For i = 1 To intMaxShippers
.Rows(i + 1).Include = False
Next
End With
' Ensure the RecordCount value is updated.
rsRowSourceFiltered.MoveLast
' Populate the chart's datasheet with the
' filtered recordset, starting with the
' datasheet's second row.
rsRowSourceFiltered.MoveFirst
For i = 1 To rsRowSourceFiltered.RecordCount
For j = 0 To rsRowSourceFiltered.Fields.Count - 1
' Assign data to the datasheet cells starting
' at row 2, column 1.
chtObj.Application.DataSheet. _
Cells(i + 1, j + 1).Value = _
rsRowSourceFiltered.Fields(j).Value
Next
rsRowSourceFiltered.MoveNext
Next
With Me!chtSync.Object.Application
' Each datasheet row contains two columns for the
' shipper's CompanyName and SumProductSales. The first
' row contains the column headers.
Debug.Print "*** OnCurrent Values ***"
For i = 1 To 4
Debug.Print .DataSheet.Cells(i, 1).Value & _
" - " & .DataSheet.Cells(i, 2).Value
Next
End With
End Sub
Private Sub Form_Current()
Dim i As Integer
With Me!chtSync.Object.Application
' Each datasheet row contains two columns for the
' shipper's CompanyName and SumProductSales. The first
' row contains the column headers.
Debug.Print "*** OnCurrent Values ***"
For i = 1 To 4
Debug.Print .DataSheet.Cells(i, 1).Value & _
" - " & .DataSheet.Cells(i, 2).Value
Next
End With
End Sub
Private Sub cmdGraphData_Click()
Dim i As Integer
With Me!chtSync.Object.Application
' Note that this code is the same as
' that in the Current event procedure.
Debug.Print "*** Form View Values ***"
For i = 1 To 4
Debug.Print .DataSheet.Cells(i, 1).Value & _
" - " & .DataSheet.Cells(i, 2).Value
Next
End With
End Sub
Additional query words: out of synch incorrect not synchronized behind
Keywords: kbprb KB182131