运行时错误'-2147217904(80040e10)':至少一个参数没有被指定值
Sub test11()Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
Dim mybook As String
mybook = ThisWorkbook.FullName
With cnn
If Application.Version = "11.0" Then
.Provider = "microsoft.jet.oledb.4.0"
.ConnectionString = "extended properties=""excel 8.0;HDR=YES;"";data source=" & mybook
Else
.Provider = "microsoft.ACE.oledb.12.0"
.ConnectionString = "extended properties=""excel 12.0;HDR=YES;"";data source=" & mybook
End If
.Open
End With
sql = "select * from [期中$a2:e] where 编码 in (select 编码 from [期末$a2:e])"
rs.Open sql, cnn, adOpenKeyset, adLockOptimistic
With Worksheets("期中期末共有")
.Range("a4").CopyFromRecordset rs
End With
rs.Close
sql = "select * from [期末$a2:e] where 编码 in (select 编码 from [期中$a2:e])"
rs.Open sql, cnn, adOpenKeyset, adLockOptimistic
With Worksheets("期中期末共有")
.Range("g4").CopyFromRecordset rs
End With
rs.Close
sql = "select * from [期中$a2:e] where 编码 not in (select 编码 from [期末$a2:e])"
rs.Open sql, cnn, adOpenKeyset, adLockOptimistic
With Worksheets("期中有期末没有")
.Range("a4").CopyFromRecordset rs
End With
rs.Close
sql = "select * from [期末$a2:e] where 编码 not in (select 编码 from [期中$a2:e] where not isnull(编码))"
rs.Open sql, cnn, adOpenKeyset, adLockOptimistic
With Worksheets("期末有期中没有")
.Range("a4").CopyFromRecordset rs
End With
End Sub
运行上述宏时,出现以下错误:运行时错误'-2147217904(80040e10)':至少一个参数没有被指定值,点调试时显示错误在:rs.Open sql, cnn, adOpenKeyset, adLockOptimistic
劳烦大师们施救