By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,436 Members | 2,979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,436 IT Pros & Developers. It's quick & easy.

Error when adding data in Access Database

P: n/a
Hello,

I get a error message when I try to Add data in a relational Access
Database.

This is the error message:
"You cannot add or change a record because a related record is required in
table 'Classes'."

How can I solve this problem??
A sollution or a push in the right direction will be appreciated.

Thanx in advance,
Raven
Nov 12 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
You've obviously got a situation where you have a 1 to many relationship
between two tables. A typical example of this would be something like an
invoicing situation, where you have an Invoice Header table that's related
to an Invoice Detail table. Each header can have one or more details.

If you've got relationships set up to maintain referential integrity, before
you can insert any of the details in the the Invoice Detail table, you must
insert the corresponding record into the Invoice Header.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)

"Raven" <ra*****@tiscali.nl> wrote in message
news:40**********************@dreader2.news.tiscal i.nl...
Hello,

I get a error message when I try to Add data in a relational Access
Database.

This is the error message:
"You cannot add or change a record because a related record is required in
table 'Classes'."

How can I solve this problem??
A sollution or a push in the right direction will be appreciated.

Thanx in advance,
Raven

Nov 12 '05 #2

P: n/a
This error is indicating that you are trying to Add a record into TableX,
where one of the fields requires a related record in table "Classes". Check
the relationships between these two tables and see which fields have a join
set up ( a line drawn between them ). The field in TableX with the join, is
likely where you are trying to add a value which has no related record in
table Classes ie. the value you are entering in TableX.FieldX is not listed
anywhere in Classes.FieldX

Mike Storr
www.veraccess.com


"Raven" <ra*****@tiscali.nl> wrote in message
news:40**********************@dreader2.news.tiscal i.nl...
Hello,

I get a error message when I try to Add data in a relational Access
Database.

This is the error message:
"You cannot add or change a record because a related record is required in
table 'Classes'."

How can I solve this problem??
A sollution or a push in the right direction will be appreciated.

Thanx in advance,
Raven

Nov 12 '05 #3

P: n/a
I suppose, that you have enforced referential integrity (Relationships). I
hope you will find the answer in Access Help, search for Enforcing
Referential Integrity.

Regards, Andrej

"Raven" <ra*****@tiscali.nl> wrote in message
news:40**********************@dreader2.news.tiscal i.nl...
Hello,

I get a error message when I try to Add data in a relational Access
Database.

This is the error message:
"You cannot add or change a record because a related record is required in
table 'Classes'."

How can I solve this problem??
A sollution or a push in the right direction will be appreciated.

Thanx in advance,
Raven

Nov 12 '05 #4

P: n/a
I have 2 tables joining each other, named Classes and Hotels.
The relationship is One-To-Many.
One record of the table Classes has many related records in the table
Hotels.
Which the ClassID in the table Classes is joined with ClassID in the table
Hotels.
The "Enforce Referential Integrity" is checked as well the "Cascade Update
Related Fields" and the "Cascade Delete Related Records".

This is my Code for Add a record into the table. It works fine for tables
with no ralationship. I gues i'm doing something wrong here?

<%
Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "Hotels", objConn, 2, 2
objRS.addnew
objRS("Soort") = request.form("Soort")
objRS("Naam") = request.form("Naam")
objRS("Adres") = request.form("Adres")
objRS("URL") = request.form("URL")
objRS("Omschrijving") = request.form("Omschrijving")
objRS.update
%>

Raven
"Mike Storr" <no****@somewhere.con> wrote in message
news:2e********************@news20.bellglobal.com. ..
This error is indicating that you are trying to Add a record into TableX,
where one of the fields requires a related record in table "Classes". Check the relationships between these two tables and see which fields have a join set up ( a line drawn between them ). The field in TableX with the join, is likely where you are trying to add a value which has no related record in
table Classes ie. the value you are entering in TableX.FieldX is not listed anywhere in Classes.FieldX

Mike Storr
www.veraccess.com


"Raven" <ra*****@tiscali.nl> wrote in message
news:40**********************@dreader2.news.tiscal i.nl...
Hello,

I get a error message when I try to Add data in a relational Access
Database.

This is the error message:
"You cannot add or change a record because a related record is required in table 'Classes'."

How can I solve this problem??
A sollution or a push in the right direction will be appreciated.

Thanx in advance,
Raven


Nov 12 '05 #5

P: n/a
I have 2 tables joining each other, named Classes and Hotels.
The relationship is One-To-Many.
One record of the table Classes has many related records in the table
Hotels.
Which the ClassID in the table Classes is joined with ClassID in the table
Hotels.
The "Enforce Referential Integrity" is checked as well the "Cascade Update
Related Fields" and the "Cascade Delete Related Records".

This is my Code for Add a record into the table. It works fine for tables
with no ralationship. I gues i'm doing something wrong here?

<%
Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "Hotels", objConn, 2, 2
objRS.addnew
objRS("Soort") = request.form("Soort")
objRS("Naam") = request.form("Naam")
objRS("Adres") = request.form("Adres")
objRS("URL") = request.form("URL")
objRS("Omschrijving") = request.form("Omschrijving")
objRS.update
%>

Raven

"Raven" <ra*****@tiscali.nl> wrote in message
news:40**********************@dreader2.news.tiscal i.nl...
Hello,

I get a error message when I try to Add data in a relational Access
Database.

This is the error message:
"You cannot add or change a record because a related record is required in
table 'Classes'."

How can I solve this problem??
A sollution or a push in the right direction will be appreciated.

Thanx in advance,
Raven

Nov 12 '05 #6

P: n/a
You're not setting a value for ClassID in Hotel. And when you do, it must
already exist in Classes, or you'll get the same message.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)

"Raven" <ra*****@tiscali.nl> wrote in message
news:40**********************@dreader2.news.tiscal i.nl...
I have 2 tables joining each other, named Classes and Hotels.
The relationship is One-To-Many.
One record of the table Classes has many related records in the table
Hotels.
Which the ClassID in the table Classes is joined with ClassID in the table
Hotels.
The "Enforce Referential Integrity" is checked as well the "Cascade Update
Related Fields" and the "Cascade Delete Related Records".

This is my Code for Add a record into the table. It works fine for tables
with no ralationship. I gues i'm doing something wrong here?

<%
Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "Hotels", objConn, 2, 2
objRS.addnew
objRS("Soort") = request.form("Soort")
objRS("Naam") = request.form("Naam")
objRS("Adres") = request.form("Adres")
objRS("URL") = request.form("URL")
objRS("Omschrijving") = request.form("Omschrijving")
objRS.update
%>

Raven

"Raven" <ra*****@tiscali.nl> wrote in message
news:40**********************@dreader2.news.tiscal i.nl...
Hello,

I get a error message when I try to Add data in a relational Access
Database.

This is the error message:
"You cannot add or change a record because a related record is required in table 'Classes'."

How can I solve this problem??
A sollution or a push in the right direction will be appreciated.

Thanx in advance,
Raven


Nov 12 '05 #7

P: n/a
"Raven" <ra*****@tiscali.nl> wrote in message
news:40**********************@dreader2.news.tiscal i.nl...
I have 2 tables joining each other, named Classes and Hotels.
The relationship is One-To-Many.
One record of the table Classes has many related records in the table
Hotels.
Which the ClassID in the table Classes is joined with ClassID in the table
Hotels.
The "Enforce Referential Integrity" is checked as well the "Cascade Update
Related Fields" and the "Cascade Delete Related Records".

This is my Code for Add a record into the table. It works fine for tables
with no ralationship. I gues i'm doing something wrong here?

<%
Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "Hotels", objConn, 2, 2
objRS.addnew
objRS("Soort") = request.form("Soort")
objRS("Naam") = request.form("Naam")
objRS("Adres") = request.form("Adres")
objRS("URL") = request.form("URL")
objRS("Omschrijving") = request.form("Omschrijving")
objRS.update
%>

Raven


You are adding a record to the Hotels table, but you have not given a value
for the field Hotels.ClassID. Look in the table of Hotels and perhaps you
will find that the default value is zero, or perhaps it has no default
value. Either way, the record will not have a matching entry in the Classes
table.
You will need something like:
objRS("Class") = request.form("Whatever")

HTH
Fletcher
Nov 12 '05 #8

P: n/a
Ok, thanx for the support.

"Fletcher Arnold" <fl****@home.com> wrote in message
news:bu**********@titan.btinternet.com...
"Raven" <ra*****@tiscali.nl> wrote in message
news:40**********************@dreader2.news.tiscal i.nl...
I have 2 tables joining each other, named Classes and Hotels.
The relationship is One-To-Many.
One record of the table Classes has many related records in the table
Hotels.
Which the ClassID in the table Classes is joined with ClassID in the table Hotels.
The "Enforce Referential Integrity" is checked as well the "Cascade Update Related Fields" and the "Cascade Delete Related Records".

This is my Code for Add a record into the table. It works fine for tables with no ralationship. I gues i'm doing something wrong here?

<%
Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "Hotels", objConn, 2, 2
objRS.addnew
objRS("Soort") = request.form("Soort")
objRS("Naam") = request.form("Naam")
objRS("Adres") = request.form("Adres")
objRS("URL") = request.form("URL")
objRS("Omschrijving") = request.form("Omschrijving")
objRS.update
%>

Raven
You are adding a record to the Hotels table, but you have not given a

value for the field Hotels.ClassID. Look in the table of Hotels and perhaps you
will find that the default value is zero, or perhaps it has no default
value. Either way, the record will not have a matching entry in the Classes table.
You will need something like:
objRS("Class") = request.form("Whatever")

HTH
Fletcher

Nov 12 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.