cannot add or change a record because a related record is required

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Knowlton
    New Member
    • Feb 2011
    • 75

    cannot add or change a record because a related record is required

    I have a subform with a combo box that will not add a record. The form's record source is tblRetreadDetai ls.
    Code:
    tblRetreadDetails structure:
    RetreadDetailsID     Autonumber, Primary key
    RetreadID            Number, foreign key to tblRetreads
    TireID               Number, foreign key to Tires table
    RetreadOptionsID     Number, foreign key to tblRetreadOptions
    tblRetreadOptio ns structure:
    RetreadOptionsI D
    Brand
    Tread
    Style
    TreadDepth

    The relationship is one(tblRetreadO ptions) to many(tblRetread Details).

    The combo's control source is RetreadOptionsI D.
    The combo's rowsource is:
    Code:
    SELECT DISTINCT tblRetreadOptions.RetreadOptionsID
       , tblRetreadOptions.Tread
       , tblRetreadOptions.Brand
       , tblRetreadOptions.Style
       , tblRetreadOptions.TreadDepth
    FROM tblRetreadOptions
    WHERE (((tblRetreadOptions.Brand)
       =[forms]![frmRetreads]
          ![frmRetreadDetails].[form]
          ![cboRetreadBrand]))
    ORDER BY tblRetreadOptions.Tread;
    When trying to add a record I get an error message:
    "You cannot add or change a record because a related record is required in tblRetreadOptio ns".

    The record is in the table or it would not be an option in the combo. What am I missing?
    Thanks!
    Last edited by zmbd; Dec 17 '13, 04:50 PM. Reason: [z{Placed required[CODE/] format for Scrip and formatted text.}{stepped the RowSrc-SQL for easier reading.]
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    What this means is that in the record you are editing the field [tblRetreadDetai ls ]![RetreadOptionsI D] either doesn't have a value set or the value you have selected is not a valid. Given that only the valid values are showing then it's a setting in the control - most likely the bound column.

    Go back into your CBO and make sure the BOUND column is set for the column that contains the [tblRetreadOptio ns]![RetreadOptionsI D]

    Comment

    • Knowlton
      New Member
      • Feb 2011
      • 75

      #3
      The bound column is 1. Column count is 5. Column widths are 0";1";1";0"; 0". I'm using columns 4 and 5 to populate other controls AfterUpdate. Limit To List is set to yes.

      I'm unable to see anything different in the settings for this one than in numerous others I have.

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        Please check:

        [tblRetreadDetai ls]![RetreadOptionsI D]
        Number, foreign key to tblRetreadOptio ns
        verify this in database tools, table relationships

        The combo's control source is
        RetreadOptionsI D.
        verify that this is [tblRetreadDetai ls]![RetreadOptionsI D]
        and NOT [tblRetreadOptio ns]![RetreadOptionsI D]
        (I tend to name fields with..
        tbl_exampletabl e
        [exampletable_pk]
        [exampletable_FK _relatedtable_p k]
        or
        [exampletable_FK _relatedtable]

        I learned the hardway to not use the same field name in multiple tables; thus even if I use [PK] or [ID] in every table it's always prefaced with the table name. Took me two weeks to figure out why an embedded query kept failing and I had the wrong table/field referenced.

        The combo's rowsource is:
        [tblRetreadOptio ns]![RetreadOptionsI D]
        verfiy that this is actually the value being set in the bound column... easy, temporarily set widths from 0;1;1;0;0 to all 1" so that you can see the first value.

        Comment

        • Knowlton
          New Member
          • Feb 2011
          • 75

          #5
          In the edit relationships window - table/query:tblRetrea dOptions!Retrre adOptionsID
          related table/query - tblRetreadDetai ls!RetreadOptio nsID

          Referential integrity is enforced with cascade update and delete.

          The combos control source is tblRetreadDetai ls!RetreadOptio nsID. The forms control source is tblRetreadDetai ls and not a query that includes tblRetrteadOpti ons.

          For what it may or may not be worth, for a while now, I have been having problems with Access closing. If I open a file and only look at something or maybe print a report, when I close it, Access closes completely, but if I enter records and then close, the file closes but Access remains open and will only close by using the task manager to force it to close. I am using Access 2003.
          Thanks a bunch for your help!

          Comment

          • Knowlton
            New Member
            • Feb 2011
            • 75

            #6
            I forgot to mention that the value being set is the RetreadOptionsI D number.

            Comment

            • zmbd
              Recognized Expert Moderator Expert
              • Mar 2012
              • 5501

              #7
              Tied up at the momement so let me digest things...

              In the meantime: IFF you don't have a docmd.close in the on close events then it sounds like your installation is damaged beyond the basic repair.

              I usually don't recommend this; however, you may be due for a complete un-install/re-install of the software.

              Before you do this; make a new, blank database, import all of the items from the old database into the new database.
              See if this fixes things...


              If not... U/R-Install Office.

              Once done, you'll need to run update to receive all of the critical updates. Or you can download the file from Microsoft here: Microsoft Office Service Pack 3 MAKE SURE YOU READ EVERYTHING ON THIS PAGE!

              I can not stress enough the need to backup your harddrive, or at least the importaint files BEFORE you start anything. Gather all of your restore disks for the PC and be prepared to nuke and re-install on the rare oddball fatal event.
              Last edited by zmbd; Dec 17 '13, 04:56 PM.

              Comment

              • zmbd
                Recognized Expert Moderator Expert
                • Mar 2012
                • 5501

                #8
                In the edit relationships window (...)
                tblRetreadOptio ns!RetrreadOptionsID
                I'm guessing this is a typo??

                Comment

                • Knowlton
                  New Member
                  • Feb 2011
                  • 75

                  #9
                  Yes that is a typo. Sorry

                  Comment

                  • Knowlton
                    New Member
                    • Feb 2011
                    • 75

                    #10
                    I had actually thought about recreating my form to see if that made any difference. It seems like I remember having some issues another time and just started over and everything worked fine.
                    Take time to do your work. I've got other things going on also so I'm not in a rush.

                    Comment

                    • zmbd
                      Recognized Expert Moderator Expert
                      • Mar 2012
                      • 5501

                      #11
                      Ok
                      so
                      looking at what you've posted, I'm back down to something got broken.

                      1) Decompile option. Make the shortcut as given in this MS KB article: http://support.microsoft.com/kb/819780
                      However, Instead of altering the file's icon, I make a new shortcut on the desktop and enter the information.
                      Make a backup of the database you are working with and then drag and drop the copy on the new decompile.
                      Once open perform compact and repair
                      save the file
                      open using the "normal" method.

                      2) recreate the database using a new database file and then importing the tables etc...

                      3) complete U&R-Office. Down load the SP3 from MS first and follow the instructions in the download page.

                      Comment

                      • Knowlton
                        New Member
                        • Feb 2011
                        • 75

                        #12
                        I think you're right about something is broken. After reading through the article, I have experienced "Access has encountered a problem and needs to close".

                        I have a couple of questions for clarification.
                        1)I have a split database so do I do this for the data file, the program file or both?

                        2)You say to make the shortcut as given in the MS KB article. I didn't understand anything in it about a shortcut. I guess it may make sense as I go through it but the process makes me a bit nervous. I'm guessing the process is to repair the file(s) and then uninstall and reinstall Office so the file(s) don't damage Access?

                        Sorry for the trouble.

                        Comment

                        • zmbd
                          Recognized Expert Moderator Expert
                          • Mar 2012
                          • 5501

                          #13
                          1) Unless the backend has anything other than tables it should be ok.

                          2) Sorry, that made sense in my head at the time.
                          a) You will need this information:
                          - msaccess.exe
                          - "drive\path \" to access
                          - /decompile
                          so for my install on a windows7(64b) it reads:
                          - msaccess.exe
                          - "C:\Program Files (x86)\Microsoft Office\Office14 " (include the quotes for spaces and symbols)
                          - /decompile
                          b) right click on your desktop, new, shortcut
                          the wizard may open... enter just the path to msaccess and name it decompile - let it finish, if no wizard then enter the properties as follows.
                          c) find the shortcut on the desktop and right click - properties
                          shortcut tab
                          Target = msaccess.exe /decompile
                          Startin = "C:\Program Files (x86)\Microsoft Office\Office14 "
                          (this is for me... you will need your location)
                          [apply]
                          things will alter just a tad, that's ok
                          [ok]
                          At this point the icon should change to the Access icon and the word "decompile" for the title.

                          YEA

                          Now make a copy of the frontend
                          Drag the copy on-top of the new decompile
                          the file should open.
                          1) compact and repair
                          2) vbe - compile
                          save the file


                          Open copy using the normal method. If all goes well then archive your original file, rename and backup the "repaired" copy.

                          Now if this works then you shouldn't need to do anything else... only if there continues to be wierdness with office/access would you need to go with the U/R-Office route. Before doing the U/R check that this is a problem with all of your database files not with just this one.

                          The reason I do this "decompile" with a desktop shortcut is that I do some heavy coding and testing; thus, I occationally get things fouled beyound the normal reboot the pc fix and it's a pain to keep going in and makeing the /decompile at the file level then remove it etc... (BTW: My 1st step in all troubleshooting , close everything, shutdown windows and pc, COLD boot - 90% "cure" rate. :)
                          Last edited by zmbd; Dec 18 '13, 03:09 PM.

                          Comment

                          • Knowlton
                            New Member
                            • Feb 2011
                            • 75

                            #14
                            Sorry for taking so long but I have been tied up with other things. Compact and repair made no difference. I found that I had added another reference to the RetreadOptions table because sometimes there is a different retread applied from what was requested and I wanted to track this. In adding that field, I neglected to remove the "0" default and that was causing the problem.
                            Thanks again for your help!

                            Comment

                            Working...