Error handling using ADO 2.0
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Error handling using ADO 2.0

  1. #1
    Join Date
    Sep 2010
    Location
    Costa Rica
    Posts
    1

    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
    Ctas("CtaName")=txtName.text
    Ctas.Update
    DgCtas.Rebind
    Exit sub

    Trap:
    MsgBox "Duplicate entry", vbCritical, "Error Information"
    txtCtas.SetFocus

    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
    context".

    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
    Location
    Chicago, IL
    Posts
    14,875

    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.
    David

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center