Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 14th, 2003, 12:46 PM
Authorized User
Points: 236, Level: 4
Points: 236, Level: 4 Points: 236, Level: 4 Points: 236, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: Bucharest, , Romania.
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



Reply With Quote
  #2 (permalink)  
Old November 14th, 2003, 01:29 PM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
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
Reply With Quote
  #3 (permalink)  
Old November 14th, 2003, 02:00 PM
Authorized User
 
Join Date: Jun 2003
Location: , Quebec, Canada.
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
Reply With Quote
  #4 (permalink)  
Old November 14th, 2003, 03:15 PM
Authorized User
Points: 236, Level: 4
Points: 236, Level: 4 Points: 236, Level: 4 Points: 236, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: Bucharest, , Romania.
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


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:26 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.