Go Premium for a chance to win a PS4. Enter to Win


Detecting a specific error using OLE DB Provider for Jet

Posted on 2001-06-05
Medium Priority
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.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


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 200 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

876 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