Xuân Thanh > 13-06-13, 01:12 PM
Trích dẫn:Có thể do mình ko phải là dân KToán, chưa hiểu về việc bút toán nên số liệu hơi lôm côm
Option Compare Database
Option Explicit
Sub LapSo()
Dim PSN As Recordset, PSC As Recordset
Dim SO As Recordset
Dim TK As Recordset
Dim SoHieu As String
Set SO = CurrentDb.OpenRecordset("SoPhatSinh", dbOpenTable)
If SO.RecordCount > 0 Then
DoCmd.SetWarnings False
DoCmd.RunSQL "Delete * From Sophatsinh"
DoCmd.SetWarnings True
End If
Set TK = CurrentDb.OpenRecordset("tblDanhmuctaikhoan", dbOpenTable)
Dim STT As Integer: STT = 1
Dim i As Integer
For i = 1 To 12
TK.MoveFirst
Do Until TK.EOF
SoHieu = TK!SoHieuTK
Set PSN = CurrentDb.OpenRecordset("Select * From Dinhkhoan Where Month(Ngaychungtu) =" & i & " And TKNo = '" & SoHieu & "'" & " And XuLy = False Order By TKNo, TKCo")
If PSN.RecordCount > 0 Then
PSN.MoveFirst
Do Until PSN.EOF
STT = STT
SO.AddNew
SO!SCTGS = STT
SO!Ngay = DateSerial(Year(PSN!Ngaychungtu), Month(PSN!Ngaychungtu) + 1, 1) - 1
SO!DienGiai = PSN!DienGiai
SO!TKNo = SoHieu
SO!TKCo = PSN!TKCo
SO!Tien = PSN!Tien
SO.Update
PSN.Edit
PSN!Xuly = True
PSN.Update
PSN.MoveNext
Loop
End If
If PSN.RecordCount > 0 Then
STT = STT + 1
Else
STT = STT
End If
Set PSC = CurrentDb.OpenRecordset("Select * From Dinhkhoan Where Month(Ngaychungtu) =" & i & " And TKCo = '" & SoHieu & "'" & " And Xuly = False Order By TKNo, TKCo")
If PSC.RecordCount > 0 Then
PSC.MoveFirst
Do Until PSC.EOF
STT = STT
SO.AddNew
SO!SCTGS = STT
SO!Ngay = DateSerial(Year(PSC!Ngaychungtu), Month(PSC!Ngaychungtu) + 1, 1) - 1
SO!DienGiai = PSC!DienGiai
SO!TKCo = SoHieu
SO!TKNo = PSC!TKNo
SO!Tien = PSC!Tien
SO.Update
PSC.Edit
PSC!Xuly = True
PSC.Update
PSC.MoveNext
Loop
End If
If PSC.RecordCount > 0 Then
STT = STT + 1
Else
STT = STT
End If
TK.MoveNext
Loop
Next
Call Update
PSN.Close: PSC.Close: SO.Close: TK.Close
End Sub
Sub Update()
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("Dinhkhoan", dbOpenTable)
If rs.RecordCount > 0 Then
rs.MoveFirst
Do Until rs.EOF
If rs!Xuly = True Then
rs.Edit
rs!Xuly = False
rs.Update
End If
rs.MoveNext
Loop
End If
rs.Close
End Sub
Minh Tiên > 14-06-13, 11:03 AM