tags:

views:

14

answers:

1

Hi , My code is as below

 conDB.Execute strSQL, recordsAffected
         Sheet1.Cells(intStart, 5) = IIf(recordsAffected > 0, "Success", "Failure")

Intread of printing failure i want to print the error description. I tried

Sheet1.Cells(intStart, 5) = IIf(recordsAffected > 0, "Success", Err.Des)

but it doesn't work. Any ideas?

+1  A: 

The Err object has a value only after an error occurs. So try this

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  
renick