🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.databases.ms-access
Article #322

How to Trap Oracle 7.3/ODBC Errors in Access 97?

#322
From: C�sar Arias Juan
Date: Thu, 25 May 2000 00:00
87 lines
3826 bytes
(Excuse my english, please).
We have Oracle 7.3 in our Unix server (tables & views).
Clients run an Access 97 app (front-end & code).

Everything is fine except when a client tries to add a new register and the primary key (unique) already exist. The Oracle constraint complains and my app receives an error message through ODBC. Then Access 97 shows two error message boxes:
1) the 1st one tells ODBC call failed.
2) the 2nd one has a ODBC error standard format:
[Microsoft][ODBC driver for Oracle][Oracle]ORA-00001: unique constraint (<constraint name>) violated (#1)

I want to trap that kind of messages from inside my app and show meaningfull messages to the final users. Something like "Error: that <key name> already exist".

So, I've written an "On Error.." trapping procedure inside the form's "Before_Update Event" (is there a better place?). For debugging propose, I've set a flag and a alert message box that explains if the code logic passes through the trapping routine, but it doesn't anytime.

Anyway, it doesn't work. This is that routine:

Private Sub Form_BeforeUpdate(Cancel As Integer)

On Error GoTo Trapping_Errors

Dim nError As Integer
Dim cError As String
Dim oError As Error
Dim bError As String

bError = "No errors"     ' Flag

Bye_Sub:
    MsgBox ("Ready to exit. " & bError) ' For debugging. Allways says "No errors"!
    Cancel = True     'Don't accept that operation
    Exit Sub

Trapping_Errors:
    bError = "ERRORS!"    ' Flag. Never shown. But error ocurred!
    nError = Err.Number
    cError = Err.Description

    ' 1st try: "normal errors"
    ' Next message is NEVER shown
    MsgBox ("Error Befor Updating: " & Trim(Str(nError)) & " " & cError)

    ' 2nd try: "normal & advanced errors"
    ' Next messages are NEVER shown
    MsgBox ("# of Errors: " & Trim(Str(Errors.Count)))
    For Each oError In DBEngine.Errors
        MsgBox (oError.Description & Chr(13) & Chr(10) & oError.Source & Chr(13) & Chr(10) & _
        Str(oError.Number))
    Next oError

    Resume Bye_Sub

End Sub

' **** End of Code ****

Before exit, if I set Cancel = False, I'm accepting that erroneous operation (wrong), my own messages are not shown. But Access shows that couple of ODBC messages.

If I set Cancel = True, I'm not accepting that erroneous operation (right), my own messages are not shown, ODBC errors are not shown. But the user is locked in the current form's record (he can't move outside the current record pushing tab or enter keys. He must push Escape to undo that operation. That isn't bad but is not what I'm looking for).

SO, I NEED SOME HELP:

1) Any suggestion about that code?
2) Any file containing the list of that kind of errors (number & description)?

Thanks

-- 

Saludos
C. Arias
Technical Details
Message-ID: <8givpo$hco$1@talia.mad.ttd.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111a5a,7f0ec301d264a96b,start
X-Google-Attributes: gid111a5a,public
X-Google-Thread: ff0ac,7f0ec301d264a96b,start
X-Google-Attributes: gidff0ac,public
X-Google-Thread: f99a8,7f0ec301d264a96b,start
X-Google-Attributes: gidf99a8,public
X-Google-Thread: fcacf,7f0ec301d264a96b,start
X-Google-Attributes: gidfcacf,public
From: "C�sar Arias Juan" <carias@renfe.es>
Subject: How to Trap Oracle 7.3/ODBC Errors in Access 97?
Date: 2000/05/25
Message-ID: <8givpo$hco$1@talia.mad.ttd.net>
X-Deja-AN: 627103619
Content-Transfer-Encoding: quoted-printable
Organization: Telefonica Transmision de Datos
X-MSMail-Priority: Normal
X-Priority: 3
Content-Type: text/plain; charset="Windows-1252"
Mime-Version: 1.0
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
Newsgroups: comp.databases.ms-access,comp.databases.oracle.misc,es.comp.bd.ms-access,microsoft.public.data.odbc