VB6 - ADO - addnew,update - error - record cannot be deleted or changed -because of related record.


Hi All!,
here's my problem.
i'm working with Visual basic 6 and microsoft Access 2003 database.
I use ADO objects for connection and manipulation of the database.
In my database there are 3 tables .2 tables(Customers and Events) are the parent tables and 1 table(Orders) is a child table.The order table has one primary key(and 2 foreign keys).
i have no problem with the 2 parent tables.
My Main concern is with the Order table.

In my VB6 program , i have a form with text boxes used for inputing and outputing data and some command butons to save record or add a new record.

In fact ,i am able to use the Addnew and update (ADO)methods to save data entered in text boxes on a VB6 form.
The saving operation(update) goes well when the referential integrity is not enforced between the 3 tables mentionned above.

THE PROBLEM is when i enforce the referential integrity between the 3 tables.IN fact, the save(update method) operation "goes well" BUT a ERROR MESSAGE is always displayed on screen.(Error -2147467259)

in Fact, the complete error message displayed is "Microsoft OLE DB Provider for ODBC Drivers reports[Microsoft][ODBC Microsoft Access Driver]. The record cannot be deleted or changed because table ’orders’ includes related record."

Could you please explain to me why i have this error message ?
What can i do so that the error message doesn't appear any more?
:confused:How could i solve this problem ? :confused:

here are some lines from my code :
Dim objADOConn As ADODB.Connection
Dim objADORst As ADODB.Recordset

...
objADORst.AddNew
...
objADORst.Fields("Order_ID") = Val(Trim$(txtOrderID.Text))
objADORst.Fields("Event_ID") = Trim$(txtEvent_ID2)
objADORst.Fields("Customer_ID") = Trim$(txtCustomerID.Text)
objADORst.Update

.....

Thanks in advance for taking your time to look at my problem!
have a nice day!

If you enjoyed this post, subscribe for updates (it's free)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo].

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.