Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine if Code Raises an Error

Status
Not open for further replies.

Bonediggler1

Technical User
Jul 2, 2008
156
US
Hi-

In mid-module, how do i test if the following code raises an error, without tampering with the error handler already in place?

"dbs.execute ("select * from table1;")"

If IsError(dbs.execute ("select * from table1;")) = true doesn't seem to do the trick.

Ultimately I need to call a particular function based on whether the dbs.execute works or not.

Thank you!!
 
You cannot Execute a Select query, Execute is for Action queries only. Furthermore, you ned to use dbFailOnError to check for SQL problems.

That being said, if you want to check for an error, it is not uncommon to use:

Code:
On Error Resume Next
DoSomethingThatCausesAnError
If Err.Number>0 Then
   'Some problem
   Err.Clear
Else
   'Ok
End If

However, it is nearly always better to come up with a solution that avoids the error.

 
How are ya Bonediggler1 . . .

The [blue]execute[/blue] method is only valid for [blue]action[/blue] queries!

As far as testing [blue]Select[/blue] queries is concerned ... either they work or they don't!

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top