how to trap ADO update error instead of a message box 
Author Message
 how to trap ADO update error instead of a message box

vb6
win95
ado2.5
access97

code:
Public Function readSystemInfo(ByRef rs As ADODB.Recordset, _
                         sDomainName As String, sComputerName As
String)
    Dim sCmd As String

    On Error GoTo errSystemInfo
    rs.CursorLocation = adUseServer
    sCmd = "SELECT * " & _
           "  FROM SYSTEM_INFO" & _
           " WHERE DOMAIN_NAME = '" & sDomainName & "'" & _
           "   AND COMPUTER_NAME = '" & sComputerName & "'"

    rs.Open sCmd, cnnDB, adOpenKeyset, adLockOptimistic
    ' code to use recordset here
    rs.AddNew
    rs!COMPUTER_NAME = "ROGER"
    rs!DOMAIN_NAME = "TEST"
    rs!WIN_VERSION = 1
    On Error Resume Next
    rs.Update
    If (Err.Number <> 0) Then
        Debug.Print ("Error " & Err.Number & " " & Err.Description)
    End If

    On Error GoTo 0
    readSystemInfo = Not (rs.EOF)
    Exit Function

errSystemInfo:
    readSystemInfo = False
End Function

Problem:
there's a unique index on fields COMPUTER_NAME and DOMAIN_NAME
step through the code in VB IDE to make sure error handling is correct

first time through the code, the row is inserted (this is good)
second time through the update should fail and the debug.print should
happen
   it does fail, but instead of getting the debug.print, I get a vb
message "run time error 2147217887 ..." with continue, end, debug
buttons

what do I need to do for the ON ERROR code to work ?



Mon, 30 Aug 2004 15:36:42 GMT  
 how to trap ADO update error instead of a message box
Hi Roger:

You need to trap the ADO Connection level error for this
purpose

If cnnDB.Errors.Count > 0 then
  Debug.Print cnnDB.Errors(0)
  'You could also scroll thru this collection
End if

Quote:
>-----Original Message-----
>vb6
>win95
>ado2.5
>access97

>code:
>Public Function readSystemInfo(ByRef rs As
ADODB.Recordset, _
>                         sDomainName As String,
sComputerName As
>String)
>    Dim sCmd As String

>    On Error GoTo errSystemInfo
>    rs.CursorLocation = adUseServer
>    sCmd = "SELECT * " & _
>           "  FROM SYSTEM_INFO" & _
>           " WHERE DOMAIN_NAME = '" & sDomainName & "'" &
_
>           "   AND COMPUTER_NAME = '" & sComputerName
& "'"

>    rs.Open sCmd, cnnDB, adOpenKeyset, adLockOptimistic
>    ' code to use recordset here
>    rs.AddNew
>    rs!COMPUTER_NAME = "ROGER"
>    rs!DOMAIN_NAME = "TEST"
>    rs!WIN_VERSION = 1
>    On Error Resume Next
>    rs.Update
>    If (Err.Number <> 0) Then
>        Debug.Print ("Error " & Err.Number & " " &
Err.Description)
>    End If

>    On Error GoTo 0
>    readSystemInfo = Not (rs.EOF)
>    Exit Function

>errSystemInfo:
>    readSystemInfo = False
>End Function

>Problem:
>there's a unique index on fields COMPUTER_NAME and
DOMAIN_NAME
>step through the code in VB IDE to make sure error
handling is correct

>first time through the code, the row is inserted (this is
good)
>second time through the update should fail and the
debug.print should
>happen
>   it does fail, but instead of getting the debug.print,
I get a vb
>message "run time error 2147217887 ..." with continue,
end, debug
>buttons

>what do I need to do for the ON ERROR code to work ?
>.



Mon, 30 Aug 2004 15:52:41 GMT  
 how to trap ADO update error instead of a message box
Mohammed

you are correct, I knew of this error collection

    On Error Resume Next
    rs.Update
    If cnnDB.Errors.Count > 0 Then
        Debug.Print cnnDB.Errors(0)
        'You could also scroll thru this collection
    End If

    On Error GoTo 0

once the error occurs as I step through 'rs.Update',
I get the VB message box mentioned earlier, and once I click the 'debug'
option to get back to the IDE, I can display        
         cnnDB.Errors.Count = 1
         cnnDB.Errors(0) = "The changes you requested to the table were
not successful"

but I'm still trying to understand why I'm getting the VB message box,
the "on error resume next" should prevent it from displaying .....

Roger

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Mon, 30 Aug 2004 20:12:07 GMT  
 how to trap ADO update error instead of a message box

just for the hell of it, I did this

On Error Resume Next
rs.Update
If cnnDB.Errors.Count > 0 Then
     msgbox "update error : " &cnnDB.Errors(0)

End If

On Error GoTo 0

then I created an executable and run the executable and I correctly get
the msgbox information above. Which means the little VB message that I
have been getting is coming from the VB IDE.

Why isn't the IDE following the 'on error' processing ?

Because of this IDE issue, I can't proceed past the 'rst.update'
statement to properly clean up resources and gracefully exit in debug
mode...

Is there an IDE setting to resolve this ?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Mon, 30 Aug 2004 21:16:21 GMT  
 how to trap ADO update error instead of a message box

just for the hell of it, I did this

On Error Resume Next
rs.Update
If cnnDB.Errors.Count > 0 Then
     msgbox "update error : " &cnnDB.Errors(0)
     exit function
End If

On Error GoTo 0

then I created an executable and ran the executable and I correctly got
the msgbox information above. Which means the little VB message that I
have been getting is coming from the VB IDE only.

Why isn't the IDE following the 'on error' processing ?

Because of this IDE issue, I can't proceed past the 'rst.update'
statement to properly clean up resources and gracefully exit in debug
mode...

Is there an IDE setting to resolve this ?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Mon, 30 Aug 2004 21:20:31 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Trapping Warning Messages, NOT Error Messages

2. ADO Data Controls + Using SQL instead of recordset.update

3. ado errors not trapped by vb error object???

4. error message after Update a cell in datagrid error

5. trapping info in an error message

6. Trap and Replace Error Messages

7. How do I trap spelling error message fr embedded word OLE object

8. creating a text box errors message for empty text box

9. Update Links Message Box - How to Hide

10. ADO error trapping in VB + SQL Server 2000

11. VB6 + ADO Error trapping

12. ADO Error trap

 

 
Powered by phpBB® Forum Software