Reference:
How to detect when an UPDATE fails when using ADODB.Command Execute
Dim update_cmd As New ADODB.Command
lRecordsAffected = 0
update_cmd.ActiveConnection = CurrentProject.Connection
update_cmd.CommandType = adCmdText
update_cmd.CommandText = "your SQL Update command"
Set adoRS = update_cmd.Execute(lRecordsAffected)
If (lRecordsAffected = 0) Then
MsgBox "update fail"
ElseIf (lRecordsAffected > 0) Then
MsgBox "update complete"
End If
註:
Set adoRS = update_cmd.Execute(lRecordsAffected) 這一行一定要有 Set adoRS。
如果只寫 update_cmd.Execute(lRecordsAffected),不會把更新筆數記錄到 lRecordsAffected。
沒有留言:
張貼留言