供参考: Private Sub cmdStatistic_Click() On Error GoTo ErrMsg Dim strSQL As String Dim rsTemp As ADODB.Recordset Dim i As Integer
Me.MousePointer = 11
strSQL = "..."
Set rsTemp = New ADODB.Recordset rsTemp.Open strSQL, GCon, adOpenKeyset, adLockOptimistic If rsTemp.RecordCount < 1 Then '如果没有记录,清空图表控件的显示 With Me.MSChart1 .ColumnCount = 1 .RowCount = 1 .Data = 0 .RowLabel = ""
.ShowLegend = False End With GoTo ExitLab End If
ReDim arrResult(1 To rsTemp.RecordCount, 1 To 2) rsTemp.MoveFirst For i = 1 To rsTemp.RecordCount arrResult(i, 1) = rsTemp(0) arrResult(i, 2) = rsTemp(1)
rsTemp.MoveNext Next With Me.MSChart1 .ShowLegend = True .ChartData = arrResult .FootnoteText = dtpBegin.Value & " :" & dtpStop.Value
.Column = 1 If mblnKShi = True Then .ColumnLabel = "" ' Else .ColumnLabel = "" End If End With '启用打印按钮 cmdPrint.Enabled = True GoTo ExitLab ErrMsg: MsgBox Err.Description, vbInformation, Err.Source ExitLab: Me.MousePointer = 0 End Sub
Private Sub cmdStatistic_Click()
On Error GoTo ErrMsg
Dim strSQL As String
Dim rsTemp As ADODB.Recordset
Dim i As Integer
Me.MousePointer = 11
strSQL = "..."
Set rsTemp = New ADODB.Recordset
rsTemp.Open strSQL, GCon, adOpenKeyset, adLockOptimistic
If rsTemp.RecordCount < 1 Then
'如果没有记录,清空图表控件的显示
With Me.MSChart1
.ColumnCount = 1
.RowCount = 1
.Data = 0
.RowLabel = ""
.ShowLegend = False
End With
GoTo ExitLab
End If
ReDim arrResult(1 To rsTemp.RecordCount, 1 To 2)
rsTemp.MoveFirst
For i = 1 To rsTemp.RecordCount
arrResult(i, 1) = rsTemp(0)
arrResult(i, 2) = rsTemp(1)
rsTemp.MoveNext
Next
With Me.MSChart1
.ShowLegend = True
.ChartData = arrResult
.FootnoteText = dtpBegin.Value & " :" & dtpStop.Value
.Column = 1
If mblnKShi = True Then
.ColumnLabel = "" '
Else
.ColumnLabel = ""
End If
End With '启用打印按钮
cmdPrint.Enabled = True GoTo ExitLab
ErrMsg:
MsgBox Err.Description, vbInformation, Err.Source
ExitLab:
Me.MousePointer = 0
End Sub