我的代码如下
conDB.Execute strSQL, recordsAffected
Sheet1.Cells(intStart, 5) = IIf(recordsAffected > 0, "Success", "Failure")
打印失败的内插我想打印错误说明。我试过了
Sheet1.Cells(intStart, 5) = IIf(recordsAffected > 0, "Success", Err.Des)
但它不起作用。有什么想法吗?
答案 0 :(得分:1)
Err对象仅在发生错误后才有值。所以试试这个
Sub MySub(strSQL as string)
On error goto CATCH
conDB.Execute strSQL, recordsAffected
Sheet1.Cells(intStart, 5) = IIf(recordsAffected > 0, "Success", "Hmm ?")
exit sub
CATCH:
Sheet1.Cells(intStart, 5) = Err.Description
on error goto 0
end sub