Detecting a specific error using OLE DB Provider for Jet

Posted on 2001-06-05
Last Modified: 2012-08-14

I am trying to detect a specfic error when adding a new record using the .AddNew method.

The table in question is from SQL Server, linked to an Access '97 Database - hence the OLD DB Provider.

My problem is that I cannot seem to extract a specific error code - in this instance a 3022 (duplicate record).

I have tried the standard VB error object and the ADO errors collection, but all I get is -2147217887 (error detected, big help).

I assume there must be an API call I must use or something but cannot figure out what it is.

Any help would be appreciated.


Pete Brassett
Question by:pbrasset

Expert Comment

ID: 6155913
In my experience, ADO is notoriously undescriptive about it's errors, cf. the well-known but useless "Errors Occured" message.

Have you tried examining the NativeError property of the ADODB Error object? This property will sometimes (...) return the original error ID as raised by the provider, e.g. the 3022 you mentioned above. No guarantees though.


LVL 70

Expert Comment

by:Éric Moreau
ID: 6155936
Loop the Errors collection of the Connection object.

Author Comment

ID: 6155958
The NativeError property just returns a 3146 (ODBC Error - again, big help).

I have tried looping thru the errors collection which doesn't provide any more info.
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Expert Comment

ID: 6156322
I assume the "SQLState" property of the ADO error object doesn't return anything useful either?

Try this:

   On Error Goto ErrHandler:

   ... your code ...

   If Err.Number = 3146 Then ' ODBC Call failed
       MsgBox Error$
   End If

According to the Knowledge Base article Q120763, this should (...) return the original error description, followed by the original error number between parentheses.


Author Comment

ID: 6156502
SQLState gives the 3146, which doesn't help.

The err.number returned is -2147217887, while the error$ (and err.description) gives ODBC--call failed.

Expert Comment

ID: 6156639
As a last resort, you could try to wrap the insert in a SQL-Server stored procedure, catching any errors there.

Other than that, I suspect you're out of options ;-(

Accepted Solution

niklausj earned 50 total points
ID: 6157261
You say you linked a SQL Table into AccessDB then use the Jet-Ole-db-Provider ( from a VB app? ).
Problem is not OLEDB, but Accessing a remoteDB via Jet.
This hides the Actual Error, you'll get the Access ( JET ) interpretation of the OLEDB Error. Why can't you just connect directly to SQL via SQL-Driver (and If needed to Access via Jetdriver)from VB, this gives you the Error Raised in SQL-Server, not what Jet thinks SQL-Error was.
LVL 49

Expert Comment

ID: 7132902
Hi pbrasset@devx,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Accept niklausj's comment(s) as an answer.

pbrasset@devx, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with my recommendation, please post an explanatory comment.
DanRollins -- EE database cleanup volunteer

Expert Comment

ID: 7167834
Comment from expert accepted as answer

E-E Moderator

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question