CvCG5K1k.rar
(31.52 KB, 下载次数: 48)
Private Sub CommandButton1_Click() Dim summ As Double On Error Resume Next If ComboBox1.Text = "" Or ComboBox2.Text = "" Or (OptionButton1.Value = False And OptionButton2.Value = False) Then ListView1.ListItems.Clear MsgBox "请点选科目的类别、年度、借或贷!", vbExclamation, "凭证处理系统" Exit Sub End If With ListView1 .LabelEdit = lvwManual .ColumnHeaders.Clear .ListItems.Clear .View = lvwReport .FullRowSelect = True .Gridlines = True .ColumnHeaders.Add , , "科目编码", 45 .ColumnHeaders.Add , , "总账科目", 85 .ColumnHeaders.Add , , "明细科目", 100 .ColumnHeaders.Add , , "方向", 28 If CheckBox1.Value = True Then .ColumnHeaders.Add , , "1月", 60 .ColumnHeaders.Add , , "2月", 60 .ColumnHeaders.Add , , "3月", 60 .ColumnHeaders.Add , , "合计", 65 End If If CheckBox2.Value = True Then .ColumnHeaders.Add , , "4月", 60 .ColumnHeaders.Add , , "5月", 60 .ColumnHeaders.Add , , "6月", 60 .ColumnHeaders.Add , , "合计", 65 End If If CheckBox3.Value = True Then .ColumnHeaders.Add , , "7月", 60 .ColumnHeaders.Add , , "8月", 60 .ColumnHeaders.Add , , "9月", 60 .ColumnHeaders.Add , , "合计", 65 End If If CheckBox4.Value = True Then .ColumnHeaders.Add , , "10月", 60 .ColumnHeaders.Add , , "11月", 60 .ColumnHeaders.Add , , "12月", 60 .ColumnHeaders.Add , , "合计", 65 End If End With Stpath = ThisWorkbook.Path & Application.PathSeparator & "分录表.mdb" CNN.Open "provider=Microsoft.jet.OLEDB.4.0;data source=" & Stpath SQL = "select 科目编码,总账科目,明细科目,方向 from kmb where 类型='" & ComboBox2.Text & "' order by 科目编码" RST.Open SQL, CNN, adOpenKeyset, adLockOptimistic ListView1.ListItems.Clear M = RST.RecordCount PBar1.Max = M '进度条的最大值 For I = 1 To M PBar1.Value = I '进度条的动态值 With ListView1.ListItems.Add(, , RST.Fields("科目编码")) .SubItems(1) = IIf(IsNull(RST.Fields("总账科目")), "", RST.Fields("总账科目")) .SubItems(2) = IIf(IsNull(RST.Fields("明细科目")), "", RST.Fields("明细科目")) .SubItems(3) = IIf(IsNull(RST.Fields("方向")), "", RST.Fields("方向")) col = 4 '月份从 col 列开始 For j = 1 To 4 ''遍历 4 个季度 If Me.Controls("CheckBox" & j).Value = True Then summ = 0 For K = col To col + 2 If OptionButton1.Value = True Then SSS = "借方金额" End If If OptionButton2.Value = True Then SSS = "贷方金额" End If SQL = "select sum(" & SSS & ") as 月份合计 from flb " SQL = SQL & " where 年=" & ComboBox1.Value & "" SQL = SQL & " and 月=" & K - 3 & "" SQL = SQL & " and 科目编码='" & RST.Fields("科目编码") & "'" RST1.Open SQL, CNN, adOpenKeyset, adLockOptimistic .SubItems(K) = Format(RST1.Fields("月份合计"), "#,##0.00") summ = summ + RST1.Fields("月份合计") Set RST1 = Nothing Next .SubItems(K) = IIf(summ = 0, "", Format(summ, "#,##0.00")) col = col + 4 End If Next RST.MoveNext End With Next RST.Close: RST1.Close CNN.Close Set RST = Nothing: Set CNN = Nothing PBar1.Value = False End Sub
|