|
楼主 |
发表于 2009-12-12 10:20
|
显示全部楼层
请看看我为什么出error?
我参照书上的例子自己写了个代码,但是在执行到:
mysheet.Cells(rowi, 20).CopyFromRecordset cnn.Execute(Sql)
的时候,总是出现error,要么是“microsoft jet引擎无法找到contract表”,要么是“至少一个参数没有指定值”。请高手指点一下该如何修改?谢谢!
Public Sub contractrate()
Dim mydata As String, mytable As String
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim mysheet As Worksheet
Dim Sql
mydata = ThisWorkbook.Path & "\Contract.mdb"
Set cnn = CreateObject("Adodb.connection")
With cnn
.Provider = "microsoft.jet.oledb.4.0;"
.Open mydata
End With
Set mysheet = ThisWorkbook.Sheets(1)
Set rs = New ADODB.Recordset
rowj = 2
rowi = 2
With mysheet
Do Until .Cells(rowi, 1) = ""
Sql = "Select 运价 from Contract where 目的港='" & .Cells(rowi, 6) & "'"
mysheet.Cells(rowi, 20).CopyFromRecordset cnn.Execute(Sql)
rowk = rowj
flag = 0
If mysheet.Cells(60000, 1).End(xlUp).Row = rowj Then flag = 1
Do Until mysheet.Cells(rowk, 1) = ""
rowk = rowk + 1
Loop
rowj = rowk
rowi = rowi + 1
Loop
End With
cnn.Close
Set cnn = Nothing
End Sub |
|