对象关闭VBA时不允许操作

时间:2016-08-01 14:52:43

标签: sql excel vba excel-vba stored-procedures

我的代码在到达以下代码的第4行时失败并出现上述错误。我之前在程序中使用了相同的格式,它运行得很好。如果需要更多代码来解决错误,我很乐意发布。感谢。

With rsTIP19
.ActiveConnection = cnTIP
.Open "exec usp_Service_Data_Query_QA"
ThisWorkbook.Sheets("Service_Data").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).CopyFromRecordset rsTIP19
.Close
End With

1 个答案:

答案 0 :(得分:1)

exec 的目的是什么?您应该测试.BOF.EOF

With rsTIP19

    .ActiveConnection = cnTIP
    .Open "usp_Service_Data_Query_QA"
    If Not .BOF or .EOF then
        ThisWorkbook.Sheets("Service_Data").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).CopyFromRecordset rsTIP19
    End If

    .Close

End With
相关问题