hi.i have problem adding record into access database because these tables i've created has relationships.i need to add record (from a single vb form) into 2 different tables. these 2 tables refer to the same record id actually.but first i need to add record into the first table because then only will the database automatically generate an id for the record.next, i need to add record into another table(which refers to the same id).i got a run-time error that says:

"You cannot add or change record because a related record is required in Table '1' "

how do i add record in a proper manner then,any suggestion?
thanx in advance..

so simple.
jusy use the addition code two times.
first add in the master table and then add to the child.

thank you for the reply choudry but how do i implement that,can u explain to me?im currently using two Adodc to refer to both tables.

With Adodc1
.Recordset.AddNew
.........................
..........................
...........................
.Recordset.Update
End With

With Adodc2
.Recordset.AddNew
..............................
.............................
.Recordset.Update

i use these addition codes twice but it gives me an error..please help..thank you in advance..

Please follow the steps.

1.Add to master table
2.commit the transaction.
3.Add to Child table and commit.

my database consist of 4 tables and all tables are related following the primary and foreign key.i followed the instruction but still stuck at the second table.my codes are:

With Adodc1
.Recordset.AddNew  'add to Master Table
.Recordset.Fields("reserv_date") = booking_date
.Recordset.Fields("fac_id") = fac_type
.Recordset.Fields("cust_name") = Text1.Text
.Recordset.Fields("cust_contact") = Text2.Text
.Recordset.Fields("booking_time") = Text3.Text
.Recordset.Update 'commit the transaction
End With

With Adodc2
If Check8.Value = Checked Then
.Recordset.AddNew 'add to child table
.Recordset.Fields("time_id") = 8
.Recordset.Update 'commit transaction
End If

i did both transaction in a single form.
n i'm getting the same error..
could you please explain more further about how to add n whether the table i've chosen is the right master table based on the relationships i've made?
thanx very much for any help..

where are you getting the error?
could it be that
if check8.value = checked
should really be
if check8.value = vbchecked
?????

i've made correction on that part
if check8.value = vbChecked but i'm getting the same error which is
run-time error
you cannot add or change record because a related record is required in table ' *** '

With Adodc2
If Check8.Value = Checked Then
.Recordset.AddNew 'add to child table
.Recordset.Fields("time_id") = 8
.Recordset.Update 'the error stops here
End If

any idea??

Kindly post all your table structure with relations .

hi.attached are my table structure with relations.i have tried buliding query using both tables that i need to use,connect it to adodc and try adding data but it still does not work.
table Reservation is the master table and table TF is the child table.
thank you in advance for the help.

i think i might as well give details about my tables.

1.master table(reservation)
fields : reserv_id, reserv_date,cust_name, cust_contact, fac_id.

2.child table(TF)
fields : tf_id,time_id,reserv_id,fac_id,reserv_date.

these 2 tables are related by their reserv_id.

i want to add record into table1(all fields) and table2(time_id fields) in a single click.
but again i receive an error that said "you cannot add or change record because a related record is required in table 'reservation' "

anyone who knows how to solve this please help..
thanx in advance..

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.