-
September 10th, 2010, 12:05 AM
#1
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.
-
September 10th, 2010, 12:38 AM
#2
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.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|