|
楼主 |
发表于 2012-3-6 19:02
|
显示全部楼层
marco 发表于 2012-3-6 10:02
第一个问题很简单,改动如下即可,第二个问题你的实现什么功能?放正没看懂需求是什么。
mycnn.Open ("p ...
十分感谢marco 解答,这段代码要达二个目的,一是把原表中把制造费用明细提取出来,二是根据提取来的明细把会计凭证提取出来。
我在VBA版提问已得到解答,代码如下。
Sub CommandButton2_Click()
Dim mySQL As String, i As Long, k As Long, total As Long
Dim mycnn, rs, str$
Set mycnn = CreateObject("adodb.connection")
Application.ScreenUpdating = False
mycnn.Open ("provider=microsoft.jet.oledb.4.0;extended properties='Excel 8.0;hdr=no;';data source=" & ThisWorkbook.FullName)
mySQL = "select * from [原表$] where f7 like '生产成本%' ORDER BY f8 DESC"
ActiveWorkbook.Sheets.Add after:=Worksheets(Worksheets.Count)
ActiveSheet.Range("a2").CopyFromRecordset mycnn.Execute(mySQL)
Range("a1:h1").Value = Sheets(1).Range("a1:h1").Value
mycnn.Close
Set mycnn = Nothing
Rem 重新建立连接
Set mycnn = CreateObject("adodb.connection")
mycnn.Open ("provider=microsoft.jet.oledb.4.0;extended properties='Excel 8.0;hdr=no;';data source=" & ThisWorkbook.FullName)
str = ActiveSheet.Name
mySQL = "select a.* from [原表$] a,[" & str & "$] b where a.f1=b.f1 and a.f4=b.f4 ORDER BY a.f5 DESC"
ActiveWorkbook.Sheets.Add after:=Worksheets(Worksheets.Count)
ActiveSheet.Range("a2").CopyFromRecordset mycnn.Execute(mySQL)
Range("a1:h1").Value = Sheets(1).Range("a1:h1").Value
mycnn.Close
Set mycnn = Nothing
End Sub |
|