Error when adding data in Access Database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Raven

    Error when adding data in Access Database

    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


  • Douglas J. Steele

    #2
    Re: Error when adding data in Access Database

    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

    (No private e-mails, please)



    "Raven" <raviram@tiscal i.nl> wrote in message
    news:40081bd9$0 $41757$5fc3050@ dreader2.news.t iscali.nl...[color=blue]
    > 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
    >
    >[/color]


    Comment

    • Mike Storr

      #3
      Re: Error when adding data in Access Database

      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





      "Raven" <raviram@tiscal i.nl> wrote in message
      news:40081bd9$0 $41757$5fc3050@ dreader2.news.t iscali.nl...[color=blue]
      > 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
      >
      >[/color]


      Comment

      • Andrej

        #4
        Re: Error when adding data in Access Database

        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" <raviram@tiscal i.nl> wrote in message
        news:40081bd9$0 $41757$5fc3050@ dreader2.news.t iscali.nl...[color=blue]
        > 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
        >
        >[/color]


        Comment

        • Raven

          #5
          Re: Error when adding data in Access Database

          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.CreateOb ject("ADODB.Rec ordset")
          objRS.Open "Hotels", objConn, 2, 2
          objRS.addnew
          objRS("Soort") = request.form("S oort")
          objRS("Naam") = request.form("N aam")
          objRS("Adres") = request.form("A dres")
          objRS("URL") = request.form("U RL")
          objRS("Omschrij ving") = request.form("O mschrijving")
          objRS.update
          %>

          Raven


          "Mike Storr" <nobody@somewhe re.con> wrote in message
          news:2eVNb.2380 9$1K1.303481@ne ws20.bellglobal .com...[color=blue]
          > 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".[/color]
          Check[color=blue]
          > the relationships between these two tables and see which fields have a[/color]
          join[color=blue]
          > set up ( a line drawn between them ). The field in TableX with the join,[/color]
          is[color=blue]
          > 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[/color]
          listed[color=blue]
          > anywhere in Classes.FieldX
          >
          > Mike Storr
          > www.veraccess.com
          >
          >
          >
          >
          > "Raven" <raviram@tiscal i.nl> wrote in message
          > news:40081bd9$0 $41757$5fc3050@ dreader2.news.t iscali.nl...[color=green]
          > > 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[/color][/color]
          in[color=blue][color=green]
          > > table 'Classes'."
          > >
          > > How can I solve this problem??
          > > A sollution or a push in the right direction will be appreciated.
          > >
          > > Thanx in advance,
          > > Raven
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Raven

            #6
            Re: Error when adding data in Access Database

            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.CreateOb ject("ADODB.Rec ordset")
            objRS.Open "Hotels", objConn, 2, 2
            objRS.addnew
            objRS("Soort") = request.form("S oort")
            objRS("Naam") = request.form("N aam")
            objRS("Adres") = request.form("A dres")
            objRS("URL") = request.form("U RL")
            objRS("Omschrij ving") = request.form("O mschrijving")
            objRS.update
            %>

            Raven

            "Raven" <raviram@tiscal i.nl> wrote in message
            news:40081bd9$0 $41757$5fc3050@ dreader2.news.t iscali.nl...[color=blue]
            > 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
            >
            >[/color]


            Comment

            • Douglas J. Steele

              #7
              Re: Error when adding data in Access Database

              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

              (No private e-mails, please)



              "Raven" <raviram@tiscal i.nl> wrote in message
              news:40084e7c$0 $41747$5fc3050@ dreader2.news.t iscali.nl...[color=blue]
              > 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.CreateOb ject("ADODB.Rec ordset")
              > objRS.Open "Hotels", objConn, 2, 2
              > objRS.addnew
              > objRS("Soort") = request.form("S oort")
              > objRS("Naam") = request.form("N aam")
              > objRS("Adres") = request.form("A dres")
              > objRS("URL") = request.form("U RL")
              > objRS("Omschrij ving") = request.form("O mschrijving")
              > objRS.update
              > %>
              >
              > Raven
              >
              > "Raven" <raviram@tiscal i.nl> wrote in message
              > news:40081bd9$0 $41757$5fc3050@ dreader2.news.t iscali.nl...[color=green]
              > > 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[/color][/color]
              in[color=blue][color=green]
              > > table 'Classes'."
              > >
              > > How can I solve this problem??
              > > A sollution or a push in the right direction will be appreciated.
              > >
              > > Thanx in advance,
              > > Raven
              > >
              > >[/color]
              >
              >[/color]


              Comment

              • Fletcher Arnold

                #8
                Re: Error when adding data in Access Database

                "Raven" <raviram@tiscal i.nl> wrote in message
                news:40084e0b$0 $41747$5fc3050@ dreader2.news.t iscali.nl...[color=blue]
                > 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.CreateOb ject("ADODB.Rec ordset")
                > objRS.Open "Hotels", objConn, 2, 2
                > objRS.addnew
                > objRS("Soort") = request.form("S oort")
                > objRS("Naam") = request.form("N aam")
                > objRS("Adres") = request.form("A dres")
                > objRS("URL") = request.form("U RL")
                > objRS("Omschrij ving") = request.form("O mschrijving")
                > objRS.update
                > %>
                >
                > Raven[/color]

                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("W hatever")

                HTH
                Fletcher


                Comment

                • Raven

                  #9
                  Re: Error when adding data in Access Database

                  Ok, thanx for the support.

                  "Fletcher Arnold" <fletch@home.co m> wrote in message
                  news:bua1ud$kop $1@titan.btinte rnet.com...[color=blue]
                  > "Raven" <raviram@tiscal i.nl> wrote in message
                  > news:40084e0b$0 $41747$5fc3050@ dreader2.news.t iscali.nl...[color=green]
                  > > 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[/color][/color]
                  table[color=blue][color=green]
                  > > Hotels.
                  > > The "Enforce Referential Integrity" is checked as well the "Cascade[/color][/color]
                  Update[color=blue][color=green]
                  > > Related Fields" and the "Cascade Delete Related Records".
                  > >
                  > > This is my Code for Add a record into the table. It works fine for[/color][/color]
                  tables[color=blue][color=green]
                  > > with no ralationship. I gues i'm doing something wrong here?
                  > >
                  > > <%
                  > > Dim objRS
                  > > Set objRS = Server.CreateOb ject("ADODB.Rec ordset")
                  > > objRS.Open "Hotels", objConn, 2, 2
                  > > objRS.addnew
                  > > objRS("Soort") = request.form("S oort")
                  > > objRS("Naam") = request.form("N aam")
                  > > objRS("Adres") = request.form("A dres")
                  > > objRS("URL") = request.form("U RL")
                  > > objRS("Omschrij ving") = request.form("O mschrijving")
                  > > objRS.update
                  > > %>
                  > >
                  > > Raven[/color]
                  >
                  > You are adding a record to the Hotels table, but you have not given a[/color]
                  value[color=blue]
                  > 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[/color]
                  Classes[color=blue]
                  > table.
                  > You will need something like:
                  > objRS("Class") = request.form("W hatever")
                  >
                  > HTH
                  > Fletcher
                  >
                  >[/color]


                  Comment

                  Working...