Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 14th, 2003, 12:46 PM
Authorized User
 
Join Date: Nov 2003
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default "On Error.." statement does not work


Hi,

I have the follwing code :

Set cnn1 = New ADODB.Connection

strCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\Access DataStore\..."

On Error Resume Next
cnn1.Open strCon 'the program stops here and generates an error...
If Err.Number > 0 Then
   ...
   End if

I intentionally run the code so that it generates an error because I want to test my error trapping functionality.

It doesn't work - only the VB Error Message Window keeps popping up.

What am I missing ?

Thank you

Mike



 
Old November 14th, 2003, 01:29 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Your sequence of events puzzles me. Specifically, the "On Error" declaration should be at the top to catch all errors. Otherwise errors can happen before it! How about...

Code:
Private Sub MyProcedure()

   Dim {variables here, e.g. strCon as String}

   On Error GoTo Err_MyProcedure

   Set cnn1 = New ADODB.Connection

   strCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\Access DataStore\..."

   cnn1.Open strCon

Exit_MyProcedure:
   Exit Sub

Err_MyProcedure

   'Error Trapping Here
   If Err.Number > 0 Then
      ...
   End if
   Resume Exit_MyProcedure

End Sub
Of course, you'd replace "MyProcedure" with the actual name of your procedure.



Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old November 14th, 2003, 02:00 PM
Authorized User
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You should also check for error different from 0. Most of the time ADO return negative error number.

Code:
   'Error Trapping Here
   If Err.Number <> 0 Then
      ...
   End if
Stéphane Lajoie
 
Old November 14th, 2003, 03:15 PM
Authorized User
 
Join Date: Nov 2003
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

thanks for your suggestions (hope I didn't puzzle you too much :-) ). The problem was the Error Trapping setting in the Tools/Options Menu, which was set to "Break on all errors". And yes, error codes CAN be < 0 (I forgot that).

Regards,

Mike







Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete Statement Error Jane SQL Language 1 October 21st, 2005 01:45 PM
READPAST Hint in SELECT statement won't work mike_abc SQL Server 2000 0 June 29th, 2005 08:08 AM
Getting error in sql statement Calibus Classic ASP Databases 7 August 11th, 2004 07:11 AM
SELECT STATEMENT error sinner Classic ASP Databases 5 February 28th, 2004 04:05 PM
SQL Statement Error riskey_457 Access ASP 4 June 9th, 2003 11:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.