Not getting error msg on failed insert query (1 Viewer)

expat1000

Registered User.
Local time
Today, 12:15
Joined
Apr 6, 2012
Messages
18
Access FE, SQL Server BE. I run a simple insert query in Access in the GUI. A no dup index on two fields in the table rejects it with an error message as it should. However
Code:
Set qry = CurrentDb.QueryDefs("query2")
qry.Execute dbSeeChanges

also fails but without an error being displayed so I can't trap it. Same goes for CurrentDb.Execute sSQL, dbSeeChanges I have preceded that statement with docmd.setwarnings(true). Is this expected behaviour?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:15
Joined
May 7, 2009
Messages
19,237
maybe:

qry.Execute dbFailOnError
 

expat1000

Registered User.
Local time
Today, 12:15
Joined
Apr 6, 2012
Messages
18
maybe:

qry.Execute dbFailOnError
I think the dbSeeChanges is required. This gives me argument error
Code:
qry.Execute dbSeeChanges, dbFailOnError
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:15
Joined
May 7, 2009
Messages
19,237
it's because it only accepts 1 argument:

qry.Execute dbSeeChanges + dbFailOnError
 

expat1000

Registered User.
Local time
Today, 12:15
Joined
Apr 6, 2012
Messages
18
OK. That's got it - sort of. I get a generic error "ODBC--call failed" - better than nothing! Thank you.
 

Isaac

Lifelong Learner
Local time
Today, 12:15
Joined
Mar 14, 2017
Messages
8,777
OK. That's got it - sort of. I get a generic error "ODBC--call failed" - better than nothing! Thank you.

Something that would be PRICELESS for Microsoft to solution....getting actual SQL Server error messages back to Access.

I've put significant time into this issue and concluded that the closest an Access/T-SQL developer can come who wants to create server-side error handling with Access FE-side knowledge of it is a stored proc
How to capture SQL Server error via MS Access, after error not generated by DAO VBA code (microsoft.com)
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 14:15
Joined
Feb 28, 2001
Messages
27,175
Apparently there IS a way to get back an ODBC detailed code.



You get back some indication of an error from the basic call, so you call SQLGetDiagRec (get diagnostic record) to find out what went wrong.
 

Isaac

Lifelong Learner
Local time
Today, 12:15
Joined
Mar 14, 2017
Messages
8,777
Apparently there IS a way to get back an ODBC detailed code.



You get back some indication of an error from the basic call, so you call SQLGetDiagRec (get diagnostic record) to find out what went wrong.

Let me know if you know how to make Access use SQLFetch odbc.

Note in the post I linked to, the great need is to return errors when executing a saved query....not just when using an ado/dao connection
 

Users who are viewing this thread

Top Bottom