|
会计统计中多数是末级才输入数据,上级是自动累计的。
需要的网友可以来探讨一下。- Public Function GetTotal(strNo As String, curAccount As Currency) As Currency
- Dim rs As New ADODB.Recordset
- Dim cnn As New ADODB.Connection
- Dim strSQL As String
- Dim intQ As Integer
- Dim curTemp As Currency
- On Error GoTo GetTotal_Error
- Set cnn = CurrentProject.Connection
- intQ = Len(strNo)
- If curAccount <> 0 Or intQ = 8 Then '说明其为末级
- GetTotal = curAccount '无需累加
- Exit Function
- ElseIf intQ = 6 Then
- strSQL = "SELECT 金额 FROM 科目表 WHERE LEFT(代码,6)='" & strNo & "'"
- ElseIf intQ = 4 Then
- strSQL = "SELECT 金额 FROM 科目表 WHERE LEFT(代码,4)='" & strNo & "'"
- Else
- MsgBox "此函数只能适应三级统计"
- Exit Function
- End If
- rs.Open strSQL, cnn, adOpenKeyset, adLockOptimistic
- Do While Not rs.EOF
- curTemp = curTemp + rs.Fields(0)
- rs.MoveNext
- Loop
- GetTotal = curTemp
- rs.Close
- Set rs = Nothing
- Set cnn = Nothing
- On Error GoTo 0
- Exit Function
- GetTotal_Error:
- MsgBox "Error " & Err.Number & " (" & Err.Description & ")"
- End Function
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|