|

楼主 |
发表于 2022-1-6 10:01
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
还是这个图片,选择项目名称中数据,选择统计项目(项目名称),区间单位,图表式样能在子窗体显示,代码执行卡在了统计项目这里,对应代码如下:
Dim strField As String
Dim strFieldxm As String
Dim strFieldlb As String
Dim strFormat As String
Dim strCaption As String
Dim strCaptionlb As String
Dim strCaptionxm As String
Const xlCategory = 1
If Nz(Me.开始日期) <> "" Then strWhere = strWhere & " AND 生产日期 >= #" & Format$(Me.开始日期, "yyyy-mm-dd") & "#"
If Nz(Me.截止日期) <> "" Then strWhere = strWhere & " AND 生产日期 <= #" & Format$(Me.截止日期, "yyyy-mm-dd") & "#"
If Nz(Me.项目名称) <> "" Then strWhere = strWhere & " AND ([项目名称] Like '*" & Me.项目名称 & "*')"
If strWhere <> "" Then strWhere = " WHERE " & Mid(strWhere, 6)
Select Case Me.区间单位
Case 1
strCaption = "日"
strField = "生产日期"
strFormat = "yyyy-mm-dd"
Case 2
strCaption = "周"
strField = "Year([生产日期]) & '-' & Format(DatePart('ww',[生产日期]),'00')"
strFormat = "yyyy-mm"
Case 3
strCaption = "月"
strField = "Format([生产日期],'yyyy-mm')"
strFormat = "yyyy-mm"
Case 4
strCaption = "季"
strField = "Year([生产日期]) & '-' & DatePart('q',[生产日期])"
strFormat = "yyyy-mm"
Case 5
strCaption = "年"
strField = "Year([生产日期])"
strFormat = "0"
End Select
strFieldxm = "统计项目"
Select Case Me.统计项目
Case 1
strCaptionxm = "平均值"
strFieldxm = "项目名称"
Case 2
strCaptionxm = "最大值"
strFieldxm = "项目名称"
Case 3
strCaptionxm = "最小值"
strFieldxm = "项目名称"
End Select
strFieldlb = "项目名称"
Select Case Me.项目名称
Case 1
strCaptionlb = "项目名称"
strFieldlb = "项目名称"
End Select
Me.子窗体!周期.Controls(0).Caption = strCaption
Me.子窗体!项目名称.Controls(0).Caption = strCaptionlb
Me.子窗体!统计项目.Controls(0).Caption = strFieldxm
Me.子窗体.Form.RecordSource = " SELECT " & strField & " AS 周期," _
& strFieldlb & " AS 项目名称,Avg(" & strFieldxm & ") AS 平均值 , Min(" & strFieldxm & ") AS 最小值 , Max(" & strFieldxm & ") AS 最大值 " _
& " FROM mainlist" & strWhere _
& " GROUP BY " & strField & "," & strFieldlb & ";"
Me.Graph.RowSource = " TRANSFORM Avg(" & strFieldxm & ") AS 平均值 , Min(" & strFieldxm & ") AS 最小值 , Max(" & strFieldxm & ") AS 最大值" _
& " SELECT " & strField & " AS 周期" _
& " FROM mainlist" & strWhere _
& " GROUP BY " & strField & "" _
& " PIVOT " & strField
On Error Resume Next
Me.Graph.Axes(xlCategory).TickLabels.NumberFormatLocal = strFormat
请老师帮我排查一下,谢谢
|
-
|