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

.....

i've tryed to search for a solution through google. some suggest to use sql insert instead of addnew and update, or remove connection options such as opendynamic,...but nothing seems to help!

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

Recommended Answers

All 2 Replies

as per the rule of referential integrity.

1. No child record can exist without a parent record
i.e.--Parent record must be created first and then the child record.

2. Parent record can't be deleted till there exists a dependent child record
i.e.-- Child record must be deleted first and then the parent record.

please post all of ur code so i can understand it better and give u a solution

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.