Checking Error Codes after executing a SQL query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

Is there a way to check for error codes or condition codes that indicate the
result of a SQL statement?

For example, if executing a query to search for a specific record based on
an ID number, is there some code that can be checked to determine the result
of the query? If a row is found, the code may be set to 100. If no row is
found, the code is set to 0. Are there other ways to check for various types
of conditions?

I know that VB has Err object. Can this be used?

TIA,
Rich
 
If you are using DAO and the Execute Method, you can use the RecordsAffected
property of CurrentDb.

With CurrentDb
.Execute("DELETE * FROM SomeTable;"), dbFailOnError
MsgBox .RecordsAffected & " Where Deleted"
End With

Including the dbFailOnError will throw an error if there is an execution
problem with the query. Include an error handler to trap them just as you
would for Access errors.
 
Back
Top