没有办法,给你代码,你自己琢磨吧。首先在通用部分定义有个数组。 Dim AA(0 To 3) As String 启动,并且在 Combo1 控件加载“产品名称”。 Private Sub Form_Load() Label1.Caption = "" Adodc1.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & App.Path & "\123.accdb" Adodc1.RecordSource = "select 产品名称 from 产品销售" Adodc1.Refresh Combo1.Clear Combo1.AddItem "全部" Do While Not Adodc1.Recordset.EOF '搜索 For i = 0 To Combo1.ListCount - 1 If Combo1.List(i) = Adodc1.Recordset.Fields(0) Then Exit For Next If i = Combo1.ListCount Then Combo1.AddItem Adodc1.Recordset.Fields(0) Adodc1.Recordset.MoveNext Loop AA(0) = "硬盘": AA(1) = "显示卡": AA(2) = "CPU": AA(3) = "内存" Dim X As Integer For X = 0 To 3 With MSChart1 .RowCount = UBound(AA) + 1 .Row = X + 1 .ColumnCount = 1 If X = 0 Then .Data = 100 ElseIf X = 1 Then .Data = 200 ElseIf X = 2 Then .Data = 50 ElseIf X = 3 Then .Data = 420 End If .RowLabel = AA(X) End With Next X Label1.Caption = "MSChart1控件预览" End Sub Combo1的单击事件,显示图表。 Private Sub Combo1_Click() Dim CP As String, XSE0 As Long, XSE1 As Long, XSE2 As Long, XSE3 As Long, MT As Integer CP = Combo1.Text If CP = "全部" Then Adodc1.RecordSource = "select * from 产品销售 " Else Adodc1.RecordSource = "select * from 产品销售 Where 产品名称='" & CP & "'" End If Adodc1.Refresh Do While Not Adodc1.Recordset.EOF If Adodc1.Recordset.Fields("产品名称") = "硬盘" Then XSE0 = XSE0 + Adodc1.Recordset.Fields("销售数量") ElseIf Adodc1.Recordset.Fields("产品名称") = "显示卡" Then XSE1 = XSE1 + Adodc1.Recordset.Fields("销售数量") ElseIf Adodc1.Recordset.Fields("产品名称") = "CPU" Then XSE2 = XSE2 + Adodc1.Recordset.Fields("销售数量") ElseIf Adodc1.Recordset.Fields("产品名称") = "内存" Then XSE3 = XSE3 + Adodc1.Recordset.Fields("销售数量") End If Adodc1.Recordset.MoveNext Loop Label1.Caption = CP & "的销售总量是:" & XSE0 + XSE1 + XSE2 + XSE3 Dim X As Integer For X = 0 To 3 With MSChart1 .RowCount = UBound(AA) + 1 .Row = X + 1 .ColumnCount = 1 If X = 0 Then .Data = XSE0 ElseIf X = 1 Then .Data = XSE1 ElseIf X = 2 Then .Data = XSE2 ElseIf X = 3 Then .Data = XSE3 End If .RowLabel = AA(X) End With Next X End Sub
Adodc1控件+MSChart1控件+Combo1控件,统计销售数量的程序做好了,如果你需要加企鹅 265 304 33 92,做好了没有办法上传工程文件。
万分感谢
万分感谢
Dim AA(0 To 3) As String
启动,并且在 Combo1 控件加载“产品名称”。
Private Sub Form_Load()
Label1.Caption = ""
Adodc1.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & App.Path & "\123.accdb"
Adodc1.RecordSource = "select 产品名称 from 产品销售"
Adodc1.Refresh
Combo1.Clear
Combo1.AddItem "全部"
Do While Not Adodc1.Recordset.EOF '搜索
For i = 0 To Combo1.ListCount - 1
If Combo1.List(i) = Adodc1.Recordset.Fields(0) Then Exit For
Next
If i = Combo1.ListCount Then Combo1.AddItem Adodc1.Recordset.Fields(0)
Adodc1.Recordset.MoveNext
Loop
AA(0) = "硬盘": AA(1) = "显示卡": AA(2) = "CPU": AA(3) = "内存"
Dim X As Integer
For X = 0 To 3
With MSChart1
.RowCount = UBound(AA) + 1
.Row = X + 1
.ColumnCount = 1
If X = 0 Then
.Data = 100
ElseIf X = 1 Then
.Data = 200
ElseIf X = 2 Then
.Data = 50
ElseIf X = 3 Then
.Data = 420
End If
.RowLabel = AA(X)
End With
Next X
Label1.Caption = "MSChart1控件预览"
End Sub
Combo1的单击事件,显示图表。
Private Sub Combo1_Click()
Dim CP As String, XSE0 As Long, XSE1 As Long, XSE2 As Long, XSE3 As Long, MT As Integer
CP = Combo1.Text
If CP = "全部" Then
Adodc1.RecordSource = "select * from 产品销售 "
Else
Adodc1.RecordSource = "select * from 产品销售 Where 产品名称='" & CP & "'"
End If
Adodc1.Refresh
Do While Not Adodc1.Recordset.EOF
If Adodc1.Recordset.Fields("产品名称") = "硬盘" Then
XSE0 = XSE0 + Adodc1.Recordset.Fields("销售数量")
ElseIf Adodc1.Recordset.Fields("产品名称") = "显示卡" Then
XSE1 = XSE1 + Adodc1.Recordset.Fields("销售数量")
ElseIf Adodc1.Recordset.Fields("产品名称") = "CPU" Then
XSE2 = XSE2 + Adodc1.Recordset.Fields("销售数量")
ElseIf Adodc1.Recordset.Fields("产品名称") = "内存" Then
XSE3 = XSE3 + Adodc1.Recordset.Fields("销售数量")
End If
Adodc1.Recordset.MoveNext
Loop
Label1.Caption = CP & "的销售总量是:" & XSE0 + XSE1 + XSE2 + XSE3
Dim X As Integer
For X = 0 To 3
With MSChart1
.RowCount = UBound(AA) + 1
.Row = X + 1
.ColumnCount = 1
If X = 0 Then
.Data = XSE0
ElseIf X = 1 Then
.Data = XSE1
ElseIf X = 2 Then
.Data = XSE2
ElseIf X = 3 Then
.Data = XSE3
End If
.RowLabel = AA(X)
End With
Next X
End Sub