ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
楼主: jsgj2023

[原创] [e殿云]系列之Access财务记账管理系统

  [复制链接]

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-1-17 11:03 | 显示全部楼层
本帖最后由 jsgj2023 于 2019-1-17 14:02 编辑

模块2.会计凭证
  1. Public dic As Object '三级科目
  2. Public dicAbstract As Object '摘要
  3. Public dicSumAccount As Object '总账科目
  4. Public dicSecondarySubject As Object '二级科目

  5. Sub 会计科目存为数组()
  6.     Dim data As New data查询
  7.     Dim SQL As String
  8.     Dim arr, y
  9.     Set dic = CreateObject("scripting.dictionary")
  10.     Set dicAbstract = CreateObject("scripting.dictionary")
  11.     Set dicSumAccount = CreateObject("scripting.dictionary")
  12.     Set dicSecondarySubject = CreateObject("scripting.dictionary")
  13.     SQL = "Select * from 科目维护"

  14.     arr = data.筛选结果(SQL)
  15.     For y = 0 To UBound(arr, 2)
  16.         dic(UCase(arr(2, y))) = ""
  17.         dicAbstract(UCase(arr(4, y))) = ""
  18.         dicSumAccount(UCase(arr(1, y))) = ""
  19.         dicSecondarySubject(UCase(arr(0, y))) = ""
  20.     Next y
  21. End Sub
复制代码


TA的精华主题

TA的得分主题

 楼主| 发表于 2019-1-17 11:04 | 显示全部楼层
本帖最后由 jsgj2023 于 2019-1-17 14:05 编辑

模块3.凭证录入
  1. Sub 凭证录入()
  2.     Dim arr, arr1, x As Integer, mydate As Date, hm As String, sr As String, SQL As String
  3.     Dim mydata As New data查询
  4.     With Sheets("凭证录入")
  5.                 mydate = .[C3]: hm = .[f3]
  6.                 If mydata.是否存在("和美贸易", "凭证号", hm) = True Or Len(Range("a5")) = 0 Then
  7.                     MsgBox "该凭证已存在或没有数据,请不要重复录入并添加数据!"
  8.                     Exit Sub
  9.                 Else
  10.                     r = .Cells(Rows.Count, 2).End(xlUp).Row - 2
  11.                     arr = .Range("a5:f" & r)
  12.                     
  13.                     If 借贷平衡检查(arr) Then
  14.                         For x = 1 To UBound(arr)
  15.                                 If Len(arr(x, 2)) Then
  16.                                     arr(x, 3) = IIf(IsEmpty(arr(x, 3)), 0, arr(x, 3))
  17.                                     arr(x, 4) = IIf(IsEmpty(arr(x, 4)), 0, arr(x, 4))
  18.                                     arr(x, 5) = IIf(IsEmpty(arr(x, 5)), 0, arr(x, 5))
  19.                                     arr(x, 6) = IIf(IsEmpty(arr(x, 6)), 0, arr(x, 6))
  20.                                     sr = "#" & mydate & "#" & ",'" & hm & "','" & arr(x, 1) & "','" & arr(x, 2) & "','"
  21.                                     sr = sr & arr(x, 3) & "','" & arr(x, 4) & "'," & Round(arr(x, 5), 2) & "," & arr(x, 6)
  22.                                     SQL = "Insert into 和美贸易 (记账日期, 凭证号, 摘要,总账科目,二级科目,三级科目,借方金额,贷方金额) VALUES(" & sr & ")"
  23.                                     mydata.执行sql命令 (SQL)
  24.                                 End If
  25.                         Next x
  26.                         Call 清空已录数据及凭证号
  27.                         MsgBox "成功录入数据库"
  28.                     Else
  29.                         MsgBox "借贷不平衡,请检查!"
  30.                         Exit Sub
  31.                     End If
  32.                 End If
  33.     End With
  34. End Sub

  35. Function 借贷平衡检查(arr) As Boolean
  36.      Dim a  As Single
  37.      Dim b As Single
  38.         a = Application.Sum(Application.Index(arr, , 5))
  39.         b = Application.Sum(Application.Index(arr, , 6))
  40.         If a <> b Then
  41.             借贷平衡检查 = False
  42.         Else
  43.             借贷平衡检查 = True
  44.         End If
  45. End Function
  46. Sub 清空已录数据及凭证号()
  47.     Dim currentNum As Integer '当前凭证号
  48.     With Sheets("凭证录入")
  49.         r = .Cells(Rows.Count, 1).End(xlUp).Row - 2 - 4
  50.         .Range("a5").Resize(r, 6).ClearContents
  51.         currentNum = .Range("f3")
  52.         currentNum = currentNum + 1
  53.         .Range("f3") = currentNum
  54.     End With
  55. End Sub
复制代码


TA的精华主题

TA的得分主题

 楼主| 发表于 2019-1-17 11:10 | 显示全部楼层
本帖最后由 jsgj2023 于 2019-1-18 08:41 编辑

模块4.填表助手
  1. Public UserInput As Boolean
  2. Public txt

  3. Public Sub 初始化切换按键()
  4.     On Error Resume Next
  5.     Application.MacroOptions Macro:="输入状态切换", Description:="切换输入形式", ShortcutKey:="e"
  6. End Sub
  7. Public Sub 输入状态切换()
  8.     UserInput = Not UserInput
  9.     If UserInput Then
  10.         s = "关闭列表辅助输入状态!"
  11.         ActiveSheet.TextBox1.Visible = False
  12.         ActiveSheet.ListBox1.Visible = False
  13.     Else
  14.         s = "打开列表辅助输入状态!"
  15.     End If
  16.     MsgBox s
  17. End Sub
复制代码


TA的精华主题

TA的得分主题

 楼主| 发表于 2019-1-17 11:11 | 显示全部楼层
本帖最后由 jsgj2023 于 2019-1-18 08:43 编辑

以上为模块下的代码,接下来是类模块下的代码,共4个,名称分别为:Data查询  金额本月合计和本年累计  金额合计  日记账的合计与累计

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-1-17 11:13 | 显示全部楼层
本帖最后由 jsgj2023 于 2019-1-18 08:44 编辑


类模块1.Data查询
  1. Function 筛选结果(sq As String)
  2.     Dim conn As Object
  3.     Dim rst As Object
  4.     Set conn = CreateObject("adodb.connection")
  5.     Set rst = CreateObject("ADODB.Recordset")
  6.     conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "/Database/会计凭证.mdb"
  7.     Set rst = conn.Execute(sq)
  8.     筛选结果 = rst.GetRows
  9.     conn.Close
  10.     Set conn = Nothing
  11. End Function

  12. Sub 执行sql命令(sq As String)
  13.     Dim conn As Object
  14.     Dim rst As Object
  15.     Set conn = CreateObject("adodb.connection")
  16.     Set rst = CreateObject("ADODB.Recordset")
  17.     conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "/Database/会计凭证.mdb"
  18.     conn.Execute (sq)
  19.     conn.Close
  20.     Set conn = Nothing
  21. End Sub


  22. Function 是否存在(ku As String, zd As String, zh As String)
  23.     Dim conn As Object
  24.     Dim rst As Object
  25.     Set conn = CreateObject("adodb.connection")
  26.     Set rst = CreateObject("ADODB.Recordset")
  27.     Dim SQL As String, arr
  28.     conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "/Database/会计凭证.mdb"
  29.     SQL = "Select * from " & ku & " where " & zd & "='" & zh & "'"
  30.     rst.Open SQL, conn, 1, 1
  31.     If rst.RecordCount = 0 Then
  32.     是否存在 = False
  33.     Else
  34.     是否存在 = True
  35.     End If
  36.     conn.Close
  37.     Set rst = Nothing
  38.     Set conn = Nothing
  39. End Function

  40. Sub 执行筛选(sq, rg As String)
  41.     Dim conn As Object
  42.     Set conn = CreateObject("adodb.connection")
  43.     With ActiveSheet
  44.         conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "/Database/会计凭证.mdb"
  45.         .Range(rg).CopyFromRecordset conn.Execute(sq)
  46.         arrgetsource = conn.Execute(sq).GetRows
  47.     End With
  48.     conn.Close
  49.     Set conn = Nothing
  50. End Sub
复制代码


TA的精华主题

TA的得分主题

 楼主| 发表于 2019-1-17 11:26 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
本帖最后由 jsgj2023 于 2019-1-18 08:45 编辑

类模块2.金额本月合计与本年累计
  1. Function theMonthTotal_CurrentYearCumulative() '本月合计 本年累计 the month total   current year cumulative
  2.     With ActiveSheet
  3.         Dim d  As Object
  4.         Dim dRow As Object
  5.         Dim dRowTotal As Object
  6.         Dim arr As Variant
  7.         Dim r&, x&, y&, z&
  8.         Set d = CreateObject("scripting.dictionary") '金额
  9.         Set dRow = CreateObject("scripting.dictionary") '本月小计行号
  10.         Set dRowTotal = CreateObject("scripting.dictionary") '本年累计行号
  11.         r = .Cells(Rows.Count, 1).End(xlUp).Row
  12.         arr = .Range("a1:f" & r)
  13.         For x = UBound(arr) To 3 Step -1
  14.             If Month(arr(x, 1)) <> Month(arr(x - 1, 1)) Then
  15.                 .Rows(x).Insert
  16.                 .Cells(x, 5) = "本年累计"
  17.                 .Rows(x).Insert
  18.                 .Cells(x, 5) = "本月小计"
  19.             End If
  20.         Next
  21.         ' 末尾写入本年累计和本月小计 字段
  22.         r = .Cells(.Rows.Count, 3).End(xlUp).Row
  23.         yy = .Cells(r, 3)
  24.         i = r
  25.         Do While .Cells(i, 3) = yy
  26.             i = i - 1
  27.         Loop
  28.         .Cells(r + 1, 5) = "本月小计"
  29.         .Cells(r + 2, 5) = "本年累计"
  30.         Dim arrInserted As Variant
  31.          r = .Cells(.Rows.Count, 5).End(xlUp).Row
  32.         '重新获取表格数据并写入数组
  33.          arr1 = .Range("a1:h" & r)
  34.          For x = 2 To UBound(arr1)
  35.             If arr1(x, 5) = "本月小计" Then dRow(x) = ""
  36.             If arr1(x, 5) = "本年累计" Then
  37.                 n = n + 1
  38.                 dRowTotal(x) = n
  39.             End If
  40.             If Len(arr1(x, 3)) Then
  41.                  If Not d.exists(arr1(x, 3)) Then
  42.                    d(arr1(x, 3)) = Array(arr1(x, 6), arr1(x, 7), arr1(x, 8))
  43.                Else
  44.                    k = d(arr1(x, 3))
  45.                    k(0) = k(0) + arr1(x, 6)
  46.                    k(1) = k(1) + arr1(x, 7)
  47.                    k(2) = k(2) + arr1(x, 8)
  48.                    d(arr1(x, 3)) = k
  49.                End If
  50.              End If
  51.          Next
  52.          
  53.         Dim strdItems As Variant
  54.         Dim strdRowKeys As Variant
  55.          strdItems = d.items
  56.          strdRowKeys = dRow.keys
  57.          For z = 0 To d.Count - 1
  58.             .Cells(strdRowKeys(z), 6).Resize(1, 3) = Application.Transpose(Application.Transpose(strdItems(z))) '本月合计
  59.          Next
  60.   '求本年累计
  61.         Dim sMonth As Variant
  62.         strdtotalitems = dRowTotal.items
  63.         strdtotalKeys = dRowTotal.keys
  64.         For i = 0 To dRowTotal.Count - 1
  65.             '借方金额
  66.             s = strdtotalitems(i)
  67.             sMonth = Application.Index(strdItems, , 1)
  68.             .Cells(strdtotalKeys(i), 6) = MonthlySum(s1, sMonth)
  69.             '贷方金额
  70.             sMonth = Application.Index(strdItems, , 2)
  71.             .Cells(strdtotalKeys(i), 7) = MonthlySum(s2, sMonth)
  72.             '余额
  73.             sMonth = Application.Index(strdItems, , 3)
  74.             .Cells(strdtotalKeys(i), 8) = MonthlySum(s, sMonth)
  75.         Next
  76.     End With
  77. End Function

  78. Function MonthlySum(strMonth, arr)
  79.     For x = 1 To strMonth
  80.         sSum = sSum + arr(x, 1)
  81.     Next
  82.     MonthlySum = sSum
  83. End Function
复制代码


TA的精华主题

TA的得分主题

 楼主| 发表于 2019-1-17 11:28 | 显示全部楼层
本帖最后由 jsgj2023 于 2019-1-18 08:56 编辑

类模块3.金额合计
  1. Function 日记账金额合计(initialBalance As Double)
  2.     With ActiveSheet
  3.         intRow = .Cells(Rows.Count, 1).End(xlUp).Row
  4.         intCol = .Cells(intRow, Columns.Count).End(xlToLeft).Column
  5.         arr = .Range(.Cells(2, 4), .Cells(intRow, intCol))
  6.         a = Application.Sum(Application.Index(arr, , 1))
  7.         b = Application.Sum(Application.Index(arr, , 2))
  8.         .Cells(intRow + 1, 4) = a
  9.         .Cells(intRow + 1, intCol) = b
  10.         .Cells(intRow + 1, intCol + 1) = a + initialBalance - b
  11.         .Cells(intRow + 1, intCol - 2) = "合计"
  12.     End With
  13. End Function

  14. Function 应收明细查询合计()
  15.     With ActiveSheet
  16.         intRow = .Cells(Rows.Count, 1).End(xlUp).Row
  17.         intCol = .Cells(intRow, Columns.Count).End(xlToLeft).Column
  18.         arr = .Range(.Cells(2, 4), .Cells(intRow, intCol))
  19.         a = Application.Sum(Application.Index(arr, , 1))
  20.         b = Application.Sum(Application.Index(arr, , 2))
  21.         c = Application.Sum(Application.Index(arr, , 3))
  22.         .Cells(intRow + 1, 4) = a
  23.         .Cells(intRow + 1, 5) = b
  24.         .Cells(intRow + 1, 6) = a - b
  25.         .Cells(intRow + 1, intCol - 3) = "合计"
  26.     End With
  27. End Function

  28. Function 应付明细查询合计()
  29.     With ActiveSheet
  30.         intRow = .Cells(Rows.Count, 1).End(xlUp).Row
  31.         intCol = .Cells(intRow, Columns.Count).End(xlToLeft).Column
  32.         arr = .Range(.Cells(2, 4), .Cells(intRow, intCol))
  33.         a = Application.Sum(Application.Index(arr, , 1))
  34.         b = Application.Sum(Application.Index(arr, , 2))
  35.         c = Application.Sum(Application.Index(arr, , 3))
  36.         .Cells(intRow + 1, 4) = a
  37.         .Cells(intRow + 1, 5) = b
  38.         .Cells(intRow + 1, 6) = b - a
  39.         .Cells(intRow + 1, intCol - 3) = "合计"
  40.     End With
  41. End Function

  42. Function 应收_付账款汇总查询合计()
  43.     With ActiveSheet
  44.         intRow = .Cells(Rows.Count, 1).End(xlUp).Row
  45.         intCol = .Cells(intRow, Columns.Count).End(xlToLeft).Column
  46.         arr = .Range(.Cells(2, 2), .Cells(intRow, intCol))
  47.         a = Application.Sum(Application.Index(arr, , 1))
  48.         .Cells(intRow + 1, 2) = a
  49.         .Cells(intRow + 1, 1) = "合计"
  50.     End With
  51. End Function
复制代码

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-1-17 11:30 | 显示全部楼层
本帖最后由 jsgj2023 于 2019-1-18 10:29 编辑

类模块4.日记账合计与累计
  1. Function dayBook_theMonthTotal_CurrentYearCumulative(initialBalance As Double) '日记账本月合计 本年累计 the month total   current year cumulative
  2.     With ActiveSheet
  3.         Dim d  As Object
  4.         Dim dRow As Object
  5.         Dim dRowTotal As Object
  6.         Dim arr As Variant
  7.         Dim r&, x&, y&, z&
  8.         Set d = CreateObject("scripting.dictionary") '金额
  9.         Set dRow = CreateObject("scripting.dictionary") '本月小计行号
  10.         Set dRowTotal = CreateObject("scripting.dictionary") '本年累计行号
  11.         r = .Cells(Rows.Count, 1).End(xlUp).Row
  12.         arr = .Range("a1:h" & r)
  13.         '*************在第一行添加上年结转余额********************
  14.         For j = 2 To UBound(arr)
  15.             If j = 2 Then Cells(j, 8) = Cells(j, 8) + initialBalance: Exit For
  16.         Next
  17.         '*************在第一行添加上年结转余额********************
  18.         For x = UBound(arr) To 3 Step -1
  19.             If Month(arr(x, 1)) <> Month(arr(x - 1, 1)) Then
  20.                 .Rows(x).Insert
  21.                 .Cells(x, 5) = "本年累计"
  22.                 .Rows(x).Insert
  23.                 .Cells(x, 5) = "本月小计"
  24.             End If
  25.         Next
  26.         
  27.         ' 末尾写入本年累计和本月小计 字段
  28.         r = .Cells(.Rows.Count, 3).End(xlUp).Row
  29.         yy = .Cells(r, 3)
  30.         i = r
  31.         Do While .Cells(i, 3) = yy
  32.             i = i - 1
  33.         Loop
  34.         .Cells(r + 1, 5) = "本月小计"
  35.         .Cells(r + 2, 5) = "本年累计"
  36.         Dim arrInserted As Variant
  37.          r = .Cells(.Rows.Count, 5).End(xlUp).Row
  38.         '重新获取表格数据并写入数组
  39.          arr1 = .Range("a1:h" & r)
  40.          For x = 2 To UBound(arr1)
  41.             If arr1(x, 5) = "本月小计" Then dRow(x) = ""
  42.             If arr1(x, 5) = "本年累计" Then
  43.                 n = n + 1
  44.                 dRowTotal(x) = n
  45.             End If
  46.             If Len(arr1(x, 3)) Then
  47.                  If Not d.exists(arr1(x, 3)) Then
  48.                    d(arr1(x, 3)) = Array(arr1(x, 6), arr1(x, 7), arr1(x, 8))
  49.                Else
  50.                    k = d(arr1(x, 3))
  51.                    k(0) = k(0) + arr1(x, 6)
  52.                    k(1) = k(1) + arr1(x, 7)
  53.                    k(2) = k(2) + arr1(x, 8)
  54.                    d(arr1(x, 3)) = k
  55.                End If
  56.              End If
  57.          Next
  58.          
  59.         Dim strdItems As Variant
  60.         Dim strdRowKeys As Variant
  61.          strdItems = d.items
  62.          strdRowKeys = dRow.keys
  63.          For z = 0 To d.Count - 1
  64.             .Cells(strdRowKeys(z), 6).Resize(1, 3) = Application.Transpose(Application.Transpose(strdItems(z))) '本月合计
  65.          Next
  66.          

  67.   '求本年累计
  68.         Dim sMonth As Variant
  69.         strdtotalitems = dRowTotal.items
  70.         strdtotalKeys = dRowTotal.keys
  71.         For i = 0 To dRowTotal.Count - 1
  72.             '借方金额
  73.             s = strdtotalitems(i)
  74.             sMonth = Application.Index(strdItems, , 1)
  75.             .Cells(strdtotalKeys(i), 6) = MonthlySum(s1, sMonth)
  76.             '贷方金额
  77.             sMonth = Application.Index(strdItems, , 2)
  78.             .Cells(strdtotalKeys(i), 7) = MonthlySum(s2, sMonth)
  79.             '余额
  80.                 sMonth = Application.Index(strdItems, , 3)
  81.                 .Cells(strdtotalKeys(i), 8) = MonthlySum(s, sMonth)
  82.         Next
  83.     End With
  84. End Function

  85. Function MonthlySum(strMonth, arr)
  86.     For x = 1 To strMonth
  87.             sSum = sSum + arr(x, 1)
  88.     Next
  89.     MonthlySum = sSum
  90. End Function
复制代码


TA的精华主题

TA的得分主题

 楼主| 发表于 2019-1-17 11:33 | 显示全部楼层
本帖最后由 jsgj2023 于 2019-1-18 10:53 编辑

表格交互部分全部分享完毕,接下来分享数据库部分!

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-1-17 11:38 | 显示全部楼层
本帖最后由 jsgj2023 于 2019-1-18 11:16 编辑

1.负债类科目归集数据表
1.负债类科目归集.png
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-4-27 08:31 , Processed in 0.031559 second(s), 7 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表