473,414 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Capturing SQL error codes in Access

Hi
I'm using Access 2003 with SQL server 2000, linked via ODBC.

Can anybody tell me how to capture SQL error codes in Access? If this
is not possible, is there any way I can simply turn off SQL errors?

Can I use docmd.setwarnings false? If so which event would I put it
on. On error doesn't seem to work.

Thanks

Colin

Sep 13 '07 #1
3 6366
You will need to be a bit more specific here.

If you code:
Set rs = Currentdb.Openrecordset("SELECT DogID FROM Dogs")
you get an error if there is no table/query named Dogs, or of that table
does not contain a field named DogID. You can't recover from that error and
continue using the recordset: that would be meaningless.

Other errors occur if you try to move to a non-existent record, or a linked
table is disconnected, or you try to insert a record without supplying a
value for a required field, or you violate a validation rule or unique
index, or try to alter a foriegn key field to an invalid value, or ...

So, you need different approaches for different kinds of errors. The Error
event of the form catches the engine-level errors. The error handling in a
procedure handles other errors. The program options allow you to suppress
some confirmation messages, and SetWarnings handles some of those as well as
suppressing other things.

If you are talking about distinguishing confirmations and error warnings
when running action queries, this might help:
Action queries: suppressing dialogs, while knowing results
at:
http://allenbrowne.com/ser-60.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bobby" <bo****@blueyonder.co.ukwrote in message
news:11**********************@o80g2000hse.googlegr oups.com...
Hi
I'm using Access 2003 with SQL server 2000, linked via ODBC.

Can anybody tell me how to capture SQL error codes in Access? If this
is not possible, is there any way I can simply turn off SQL errors?

Can I use docmd.setwarnings false? If so which event would I put it
on. On error doesn't seem to work.

Thanks

Colin
Sep 13 '07 #2
Greetings,

In your sql server stored procedures you can use Begin Transaction
Commit Transaction Rollback Transaction and raise errors as follows --
then in Access you can:

-----------------------------------------------
Create Proc...
...parameters
As
... initialize stuff

Begin Transaction

stuff to do here

Commit Transaction

GoTo Finally --Finally is just a label to go to -
--similar to placing an Exit Sub statement
--before the Error Label -
--which I call Catch:
Catch:
RaisError('Problem with Procedure, 16, 10)
Rollback Transaction

--if there were no errors in the processing of the
--procedure the GoTo Finally will bypass the Catch: block

Finally:
Return
GO

-----------------------------------------------

In the Catch block, the RaiseError function takes a custom message 'your
custom message' followed by some error codes

RaiseError('your custom message', 16, 10)
Rollback Transaction

this will undo the entire processing as if it did not happen -- then
proceeds to exit by going to Finally: Return

Sometimes Access can read these error messages which will pop up in a
messagebox. Most of the time Access can't read these error messages
because Access is heavily subclassed (since Access is really an
application and not a full blown Programming environment).

To reliably trap all sql server error messages you should create an
application from a full blown programming environment like Java or .Net.
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Sep 13 '07 #3
On Sep 13, 10:29 am, Bobby <bob...@blueyonder.co.ukwrote:
Hi
I'm using Access 2003 with SQL server 2000, linked via ODBC.

Can anybody tell me how to capture SQL error codes in Access? If this
is not possible, is there any way I can simply turn off SQL errors?

Can I use docmd.setwarnings false? If so which event would I put it
on. On error doesn't seem to work.

Thanks

Colin
may depend on what you're doing

one way ...

Dim c As ADODB.Connection
Dim r As ADODB.Recordset
Set c = New ADODB.Connection
c.Open (CurrentProject.BaseConnectionString)
On Error Resume Next
Set r = c.Execute("SELECT * FROM Phantom")
Debug.Print c.Errors(0).Description
'Invalid object name 'Phantom'.

Sep 13 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
14
by: Brent Burkart | last post by:
I am trying to capture the Windows Authenticated username, but I want to be able to capture the login name that exists in IIS, not Windows. In order to enter my company's intranet through the...
17
by: Lauren Wilson | last post by:
Does anyone know if it is possible to capture FTP responses to various FTP commands when managing an FTP session from a VBA procedure? For example, if we try to login to an FTP server and the...
0
by: HKSHK | last post by:
This list compares the error codes used in VB.NET 2003 with those used in VB6. Error Codes: ============ 3: This Error number is obsolete and no longer used. (Formerly: Return without GoSub)...
3
by: MLH | last post by:
If Err.Number = 2001 Then I have the above line in a procedure I downloaded. I don't know what error that is exactly.
8
by: PW | last post by:
Hi, There is code in Alison Balter's excellant "Mastering Access 2003" to create a list of error codes and descriptions but it only generates error messages 3 through 94. Is there a website...
2
by: GS | last post by:
How can one avoid capturing leading empty or blank lines? the data I deal with look like this "will be paid on the dates you specified. xyz supplier amount: $100.52 when: September 07,...
2
by: RLN | last post by:
Luke Chung at FMS Inc provide this link in another thread that provided a really helpful .pdf file error listing: http://www.fmsinc.com/MicrosoftAccess/Errors/ErrorNumberAccess2007-2000. pdf ...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.