ref: Sub fu() Dim CNN As New ADODB.Connection Dim pthStr As String Dim SQL As String Dim Icount As Integer, iRow As Integer iRow = [D14].End(xlUp).Row + 2 pthStr = ThisWorkbook.Path & "\分录表.mdb" CNN.Open "Provider=Microsoft.Jet.Oledb.4.0;data Source=" & pthStr SQL = "select 摘要,科目编码,总账科目,明细科目,借方金额,贷方金额 from flb where 号 like'" & Sheets("记账凭证").Range("H4").Value & "' and 月 like'" & Month(Sheets("记账凭证").Range("E4").Value) & "'" Cells(iRow, 3).CopyFromRecordset CNN.Execute(SQL) iRow = [D14].End(xlUp).Row + 1 SQL = "select '合计','','','',sum(借方金额),sum(贷方金额) from flb where 号 like'" & Sheets("记账凭证").Range("H4").Value & "' and 月 like'" & Month(Sheets("记账凭证").Range("E4").Value) & "'" Cells(iRow, 3).CopyFromRecordset CNN.Execute(SQL) CNN.Close End Sub
|