Reputation: 3799
I am running VB with the follwing piece of code
conider strSQL to be a update string .
conDB.Execute (strSQL) ;
Sheet1.Cells(intStart, 5) = "Success"
If there are no rows updated , the below lines still runs and i get a success message printed in the cell. How do i avoid this?
Upvotes: 0
Views: 253
Reputation: 33484
dim recordsAffected as long
conDB.Execute strSQL, recordsAffected
Sheet1.Cells(intStart, 5) = IIF(recordsAffected > 0, "Success", "Failure")
Upvotes: 1
Reputation: 53593
The problem is that your Success message is displayed regardless of whether or not your Update actually updated.
I believe you can call the conDB.RecordsAffected function to return the number of records that were updated. Check the return value of this function and display the appropriate message.
Try something like this:
conDB.Execute (strSQL)
If (conDB.RecordsAffected > 0) Then
Sheet1.Cells(intStart, 5) = "Success"
Else
Sheet1.Cells(intStart, 5) = "Failed"
End If
Upvotes: 0