excel2003 vba 中至少一个参数未指定值
[求助]运行时错误‘-2147217904[复制链接]rivateSubCommandButton1_Click()DimCNNAsNewADODB.Connection...
[求助] 运行时错误 ‘-2147217904 [复制链接]
rivate Sub CommandButton1_Click()
Dim CNN As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim SQL As String, cx As String
Range("a3:h65536").ClearContents
ActiveSheet.Range("a3:h65536").ClearContents
CNN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=e:\数据源.xls"
cx = InputBox("请输入要查询的线路")
If cx = "" Then Exit Sub
SQL = "select * from [二类汇总$] where 线路名称='" & cx & "'"
rst.Open SQL, CNN, adOpenKeyset, adLockOptimistic
Range("a3").CopyFromRecordset rst
rst.Close
SQL = "select * from [三类汇总$] where 线路名称='" & cx & "'"
rst.Open SQL, CNN, adOpenKeyset, adLockOptimistic
ActiveSheet.Range("a3").CopyFromRecordset rst
End Sub
当运行到这句时候:rst.Open SQL, CNN, adOpenKeyset, adLockOptimistic
运行时错误 '-2147217904 (80040e10)':
至少一个参数没有被指定值
开始是好的,突然就变成这样,怎么处理啊! 展开
rivate Sub CommandButton1_Click()
Dim CNN As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim SQL As String, cx As String
Range("a3:h65536").ClearContents
ActiveSheet.Range("a3:h65536").ClearContents
CNN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=e:\数据源.xls"
cx = InputBox("请输入要查询的线路")
If cx = "" Then Exit Sub
SQL = "select * from [二类汇总$] where 线路名称='" & cx & "'"
rst.Open SQL, CNN, adOpenKeyset, adLockOptimistic
Range("a3").CopyFromRecordset rst
rst.Close
SQL = "select * from [三类汇总$] where 线路名称='" & cx & "'"
rst.Open SQL, CNN, adOpenKeyset, adLockOptimistic
ActiveSheet.Range("a3").CopyFromRecordset rst
End Sub
当运行到这句时候:rst.Open SQL, CNN, adOpenKeyset, adLockOptimistic
运行时错误 '-2147217904 (80040e10)':
至少一个参数没有被指定值
开始是好的,突然就变成这样,怎么处理啊! 展开
1个回答
展开全部
因为你执行之前已经把rst关闭了
把rst.close 移动到end sub 前
If cx = "" Then Exit Sub
SQL = "select * from [二类汇总$] where 线路名称='" & cx & "'"
rst.Open SQL, CNN, adOpenKeyset, adLockOptimistic
Range("a3").CopyFromRecordset rst
SQL = "select * from [三类汇总$] where 线路名称='" & cx & "'"
rst.Open SQL, CNN, adOpenKeyset, adLockOptimistic
ActiveSheet.Range("a3").CopyFromRecordset rst
rst.Close
End Sub
把rst.close 移动到end sub 前
If cx = "" Then Exit Sub
SQL = "select * from [二类汇总$] where 线路名称='" & cx & "'"
rst.Open SQL, CNN, adOpenKeyset, adLockOptimistic
Range("a3").CopyFromRecordset rst
SQL = "select * from [三类汇总$] where 线路名称='" & cx & "'"
rst.Open SQL, CNN, adOpenKeyset, adLockOptimistic
ActiveSheet.Range("a3").CopyFromRecordset rst
rst.Close
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |