|
已有DAO写好交叉表查询代码,为日后升级至服务器,拟用ADO改写连接方式。请求提示recordset和connection的正确表达。。。。。代码如下:
Private Sub cmdStatics_Click()
Dim strWhere As String
Dim strSql As String
Dim qdf As DAO.QueryDef
strWhere = ""
If Not IsNull(Me.txtInsYear) Then
strWhere = strWhere & "(year([SupervisalPaperList.InspectionDate]) = '" & Me.txtInsYear & "') and "
End If
If Not IsNull(Me.cmbMonth) Then
strWhere = strWhere & "(month(InspectionDate) = '" & Me.cmbMonth & "') and "
End If
If Not IsNull(Me.cmbSupervisor) Then
strWhere = strWhere & "([Supervisor] = '" & Me.cmbSupervisor & "') and "
End If
If Len(strWhere) > 0 Then
strWhere = Left(strWhere, Len(strWhere) - 5)
End If
If Len(strWhere) > 0 Then
strSql = "TRANSFORM Count(SupervisalPaperList.ProjectName) AS ProjectName之计算 "
strSql = strSql & "SELECT SupervisalPaperList.Supervisor, Count(SupervisalPaperList.ProjectName) AS 发整改总数 "
strSql = strSql & "FROM SupervisalPaperList WHERE ((SupervisalPaperList.Reversion) = '是 ') and "
strSql = strSql & "(" & strWhere & ")"
strSql = strSql & " GROUP BY SupervisalPaperList.Supervisor "
strSql = strSql & "PIVOT Format([InspectionDate],'yyyy - mm');"
Else
strSql = "TRANSFORM Count(SupervisalPaperList.ProjectName) AS ProjectName之计算 "
strSql = strSql & "SELECT SupervisalPaperList.Supervisor, Count(SupervisalPaperList.ProjectName) AS 发整改总数 "
strSql = strSql & "FROM SupervisalPaperList WHERE ((SupervisalPaperList.Reversion) = '是 ')"
strSql = strSql & " GROUP BY SupervisalPaperList.Supervisor "
strSql = strSql & " PIVOT Format([InspectionDate],'yyyy - mm');"
End If
Set qdf = CurrentDb.QueryDefs("CrossSupervisalPaperList")
qdf.SQL = strSql
qdf.Close
Set qdf = Nothing
'显示交叉表的内容
Me.fmSubSupervisalPaperList.SourceObject = ""
Me.fmSubSupervisalPaperList.SourceObject = "query.CrossSupervisalPaperList"
' 清除Me.txtCount的controlSource
Me.txtCount.ControlSource = ""
Me.txtCount = DCount("*", "CrossSupervisalPaperList")
End Sub
|
|