|
- Public Function dSumRecordset(Expression As String, tblName As String, Optional Criteria As String = "") As Integer
- On Error GoTo errlbl
- Dim rs As DAO.Recordset
- Dim strSQL As String
- If Criteria <> "" Then
- strSQL = "select * from " & tblName & " where " & Criteria
- Else
- strSQL = "select * from " & tblName
- End If
- Set rs = CurrentDb.OpenRecordset(strSQL)
- Do While Not rs.EOF
- dSumRecordset = dSumRecordset + (Nz(rs.Fields(Expression), 0))
- rs.MoveNext
- Loop
- rs.Close
- Set rs = Nothing
- Exit Function
- errlbl:
- MsgBox Err.Number & " " & Err.Description
- End Function
复制代码 调用- SELECT 表1.a, 表1.b, dSumRecordset("b","表1","a='c'") AS 合计1, dSumRecordset("b","表1") AS 合计2
- FROM 表1;
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|