|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Private Sub cmdNewBook_Click()
On Error Resume Next
Dim intMonth%
Dim douBalance#
Dim douJF#, douDF#, douLJF#, douLDF#
Dim rskm As New ADODB.Recordset
Dim rsmx As New ADODB.Recordset
Dim rszb As New ADODB.Recordset
Dim strSQL$, strMXBM$
DoCmd.RunSQL "DELETE * FROM 三栏账簿;"
Child114.Requery
' strSQL = "ALTER TABLE 三栏账簿 ALTER COLUMN Id COUNTER (1,1)"
' DoCmd.RunSQL strSQL
rszb.Open "三栏账簿", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
strSQL = "SELECT 年度, 科目编码, 多栏账 FROM 会计科目表 " & _
"WHERE 年度=" & ComboYear & " AND 多栏账=0 AND 是否末级=-1;"
rskm.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Do Until rskm.EOF
strSQL = "SELECT 年度,月份,日期, 凭证号, 摘要, 明细编码,借方, 贷方,余额 FROM 凭证明细 " & _
"WHERE 年度=" & ComboYear & " and [明细编码] = '" & rskm("科目编码") & "' " & _
"ORDER BY 日期,凭证号"
rsmx.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
strMXBM = rsmx("明细编码")
intMonth = rsmx("年度") + rsmx("月份")
With rszb
Do Until rsmx.EOF
If rsmx("年度") + rsmx("月份") = intMonth Then
douJF = douJF + Nz(rsmx("借方"))
douDF = douDF + Nz(rsmx("贷方"))
douLJF = douLJF + Nz(rsmx("借方"))
douLDF = douLDF + Nz(rsmx("贷方"))
If rsmx("摘要") = "结转下年" Then
.AddNew
!id = .RecordCount + 1
!明细编码 = strMXBM
!摘要 = rsmx("摘要")
!借方 = Nz(rsmx("借方"))
!贷方 = Nz(rsmx("贷方"))
!方向 = "平"
.AddNew
!id = .RecordCount + 1
!明细编码 = strMXBM
!摘要 = "本年累计"
!借方 = douLJF
!贷方 = douLDF
douJF = 0
douDF = 0
douLJF = 0
douLDF = 0
douBalance = 0
Else
If rsmx("摘要") = "上年结转" Then
.AddNew
!id = .RecordCount + 1
!明细编码 = strMXBM
!摘要 = rsmx("摘要")
douBalance = douBalance + rsmx("余额")
!方向 = Switch(rsmx("余额") > 0, "借", rsmx("余额") < 0, "贷")
!余额 = Abs(douBalance)
Else
.AddNew
!id = .RecordCount + 1
!明细编码 = strMXBM
!日期 = rsmx("日期")
!凭证号 = rsmx("凭证号")
!摘要 = rsmx("摘要")
!借方 = rsmx("借方")
!贷方 = rsmx("贷方")
douBalance = douBalance + rsmx("余额")
!方向 = Switch(douBalance > 0, "借", douBalance < 0, "贷", douBalance = 0, "平")
!余额 = Abs(douBalance)
End If
End If
rsmx.MoveNext
Else
If douLJF <> 0 Or douLDF <> 0 Then
.AddNew
!id = .RecordCount + 1
!明细编码 = strMXBM
!摘要 = "本月合计"
!借方 = douJF
!贷方 = douDF
.AddNew
!id = .RecordCount + 1
!明细编码 = strMXBM
!摘要 = "本年累计"
!借方 = douLJF
!贷方 = douLDF
End If
intMonth = rsmx("年度") + rsmx("月份")
douJF = 0
douDF = 0
End If
Loop
If douJF <> 0 Or douDF <> 0 Then
.AddNew
!id = .RecordCount + 1
!明细编码 = strMXBM
!摘要 = "本月合计"
!借方 = douJF
!贷方 = douDF
.AddNew
!id = .RecordCount + 1
!明细编码 = strMXBM
!摘要 = "本年累计"
!借方 = douLJF
!贷方 = douLDF
End If
rsmx.Close
.UpdateBatch
End With
douJF = 0
douDF = 0
douLJF = 0
douLDF = 0
douBalance = 0
rskm.MoveNext
Loop
rskm.Close
rsmx.Close
rszb.Close
Child114.Requery
End Sub
Private Sub ComboYear_AfterUpdate()
RecordSource = "SELECT 科目编码, 科目名称, 多栏账 FROM 会计科目表 WHERE 年度=" & ComboYear & " AND 多栏账=0 AND 是否末级=-1; "
List116.RowSource = RecordSource
List116.Selected(0) = True
cmdNewBook_Click
End Sub
Private Sub Form_Current()
Child114.Form.Filter = "[明细编码] = '" & 细目 & "' "
Child114.Form.FilterOn = True
End Sub
Private Sub Form_Load()
RecordSource = "SELECT 科目编码, 科目名称, 多栏账 FROM 会计科目表 WHERE 年度=" & ComboYear & " AND 多栏账=0 AND 是否末级=-1; "
List116.RowSource = RecordSource
List116.Selected(0) = True
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyPageUp, vbKeyPageDown, vbKeyDown, vbKeyUp
KeyCode = 0
End Select
End Sub
Private Sub cmdClose_Click() '
DoCmd.Close
End Sub
Private Sub List116_Click()
Const QQ = """"
With RecordsetClone
.FindFirst "科目编码=" & QQ & List116 & QQ
Bookmark = .Bookmark
End With
End Sub
Private Sub 命令First_Click()
On Error GoTo err
DoCmd.GoToRecord , , acFirst
List116.Selected(0) = True
err:
End Sub
Private Sub 命令Previous_Click()
On Error GoTo err
DoCmd.GoToRecord , , acPrevious
List116.Selected(List116.ListIndex - 1) = True
err:
End Sub
Private Sub 命令Next_Click()
On Error GoTo err
DoCmd.GoToRecord , , acNext
List116.Selected(List116.ListIndex + 1) = True
err:
End Sub
Private Sub 命令Last_Click()
On Error GoTo err
DoCmd.GoToRecord , , acLast
List116.Selected(List116.ListCount - 1) = True
err:
End Sub
Private Sub cmdPreView_Click()
On Error GoTo err
Dim stDocName As String
stDocName = "明细账"
' DoCmd.OpenReport stDocName, acPreview, , "年度=" & ComboYear & " AND 明细编码='" & 细目 & "'"
DoCmd.OpenReport stDocName, acPreview, , "明细编码='" & 细目 & "'"
err:
End Sub
Private Sub cmdPrint_Click()
On Error GoTo err
Dim stDocName As String
stDocName = "明细账"
DoCmd.OpenReport stDocName, acNormal, , "明细编码='" & 细目 & "'"
err:
End Sub
|
|