How do I catch a SQL error in VB6 while updateing a recordset?

Posted on 2006-04-19
Last Modified: 2008-02-01
I have this line in my code:
VB doesn't seem to catch any errors in data that cause this update to fail with the standard "on error" method.
How can I catch an update error?

Question by:yyuubum2
    LVL 48

    Expert Comment

    by:Ryan Chong
    In vb6, we use "on error goto errorHandler" method to capture any error within your codes, sorry, there is no try ... end try statement in vb6, that's only available in

    Author Comment

    Yes..but the   ADORS.UPDATE  error doesn't seem to trip a VB error condition.
    VB doesn't know the recordset didn't update due to data problems.
    Still looking ....
    LVL 44

    Expert Comment

    by:Leigh Purvis
    Have you examined the ADO errors collection after attempting your update?

    Author Comment

    Can you help me out here.
    I'm not familiar with how to do that..
    Maybe an example?
    LVL 44

    Accepted Solution

    An example of examining the error collection after attempting some data update

    Private Sub cmdADOErr_Click()
    On Error GoTo errHere

        Dim cnn As New ADODB.Connection
        Dim errADO As ADODB.Error
        cnn.Open "Your Connect String"
        cnn.Execute "UPDATE tblTable SET Field1 = 'Leigh' WHERE FieldID = 1"
        For Each errADO In cnn.Errors
            MsgBox errADO.Number & " : " & errADO.Description & " : " & errADO.NativeError
    End Sub
    LVL 44

    Expert Comment

    by:Leigh Purvis
    Did the errors collection prove revealing for you then?
    (Not a briliant example I know - just a rough idea :-)

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    26 Experts available now in Live!

    Get 1:1 Help Now