CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: Error handling using ADO 2.0

  1. #1
    Join Date
    Sep 2010
    Costa Rica

    Red face Error handling using ADO 2.0

    I have a fear to good understanding of Using Visual Basic 6.0 Codes.

    Im using code to create ADO Cmdobjects & RecordSets to connect and handle records in an Access 2003 mdb. In the Accounts table, I have indexed the field Name property to Yes (No Duplicates).
    I using the following code inside the BtnSave botton to trap duplication error:

    Private Sub CmdGuardar_Click()
    ' guardar modificaciones y nuevos registros cuentas
    On error goto Trap
    Call Valide_Encabezados
    If Valida = False Then Exit Sub
    If LblMODE.Caption = "Aņadir Indicadores" Then Ctas.AddNew
    Exit sub

    MsgBox "Duplicate entry", vbCritical, "Error Information"

    End Sub

    I'm traping the error, but need extra code the prevent a couple of issues:
    1- The Datagrid is still been populated with the new entry.
    2- I have tried CtasCancel, CtasCancelUpdate but nothing seens to help clering the error
    completely, messages like "Update was canceled", "To prevent duplicate entries
    change field name property etc
    3- Upon closing the form using unload botton and including code to close the table as well
    as follows: Ctas.Close, I getting another error message "Operation is not allowed in this

    I'm using a MDI form from wich I connect to the Access Database, and only open tables as needed in the forms.

    Do not know what I'm doing wrong, any one out there with any sudgestions, thank you
    in advance for any help provided.

  2. #2
    Join Date
    Jan 2006
    Fox Lake, IL

    Re: Error handling using ADO 2.0

    If you are BINDING the table, it won't allow duplicates (if you've set that up correctly)

    You could use code to load the tables. See this article.

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)