Results 1 to 15 of 15
  1. #1
    erich_18 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    11

    One to Many Issue when adding data via Forms.

    Hi All,



    I created a small database (personal project) to calculate transportation costs. its real simple, pol+pod combination (called a Lane) is subject to a specific slotrate or a slotcost.

    1 lane can only have 1 slotrate or 1 slot cost (the "one" side) assigned to it.
    while 1 slotrate or 1 slotcost can have 1 or more lane(s) (the "many" side) assigned to it.

    attached capture.jpg file with the access relationship for more details.

    When I need to create a Lane I would then need to assign a pre-established slotcost or slotrate to said Lane. I created a form to enter data into the Lanes table, but when I try to assign the new Lane a Slot Rate ID or Slot Cost ID in the Lanes Table I get this error:

    "You cannot add or change a record because a related record is required in table 'tblSlotCosts or tblSlotRates"

    I've googled this error and found a lot of information, the last suggestion I tried was changing the FK field properties in the Lanes table default value to nothing (removing the 0) and required to "No" but this did not work. I still get the same error.

    see attached capture2.jpg

    I understand that I'm entering the data into the Child table (tblLanes first), but this is something I need to do. I need the ability to create a Lane based on a pol and pod combination when required and then assign the SlotRate or SlotCost applicable.

    any help would be appreciated.

    tks

    Eric
    Attached Thumbnails Attached Thumbnails Capture.JPG   Capture2.JPG  

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    This is a split form? Is the RecordSource just tblLanes?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    erich_18 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    11
    Hi June7,

    yes this is a splitform with only tblLanes as the recordsource.

    tks

    Eric

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Then I don't understand why issue occurs. Selecting item in combobox list should work. If you want to provide db for analysis follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Join Date
    Apr 2017
    Posts
    1,792
    Attached is an example of DB how I would do this.
    I haven't a clue, for what are all those fields in tables tblSlotRates and tblSlotCosts, and what kind of values are in those fields, so I created dummy tables with same names instead. You can display any number of return values from either of tables on your form (when you add according fields to tables), but there is no need to save them in tblLanes table (or anywhere else) - you calculate them whenever you need them, or you query them.

    To keep it simple, I used previously stored values for POL, POD and Owner from tblLanes instead of separate registry tables.
    Attached Files Attached Files

  6. #6
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    I have no idea what 'pol' and 'pod' mean though obviously these are locations.
    However in order to add a new record to tblLanes, you need to specify both the slot rate and the slot cost values from the respective tables.
    From your screenshot it appears that you have only supplied one of these so a new record cannot be added
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  7. #7
    erich_18 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    11
    thanks everyone. so let me explain the data on the table.

    so to move a box from point A (POL) to point B (POD) there's either a rate or a cost (rate = our own truck, cost = buying space from a third party truck) but neither both.

    the rates and costs are pre-established and there's only a handful of them:

    Rates = (SlotrateID) only 5 different rates (ID'd from 201 to 205)
    Costs = (SlotcostID) only 2 different rates (ID'd from 301 to 302)

    what determines if a rate or cost is applied? the POL+POD combination (Lane).

    when I create a lane I have to tell the database which rate or cost will apply to the new lane.

    since this is just a personal project there's really nothing confidential here. I've attached copy of the DB I'm working on. the frmLaneManagement is the form I'm trying to use to create a new Lane and establish if the lane will either use a rate or costs depending on the ID I enter in the table. to keep it simple I'v removed some of the other forms.
    Attached Files Attached Files

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    This is bizarre. Removing relationship between tblLanes and tblSlotCosts allows data entry.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    In the realtionship diagram, edit the links and remove the referential integrity.
    Click image for larger version. 

Name:	refint.JPG 
Views:	14 
Size:	16.6 KB 
ID:	35364

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    But why is this necessary? tblSlotRates does not have this issue. Referential integrity should be appropriate setting.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    erich_18 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    11
    Thanks June7 and Davegri,

    June7, it is very bizarre. without tblLanescost it actually works quite well with tblSlotRates. I'll just have to keep trying or figure out how to rearrange the tables maybe if I join both costs and rates into one General Slot table then figure out from there how to make it work.

    Davegri, I tried that, and it saves the data in the tblLanes table but does not match the Lane with the Slotcost. Below images: (LanedID 9 should show under tblSlotRates ID # 302 but it doesnt).
    Attached Thumbnails Attached Thumbnails Capture.jpg   Capture2.JPG  

  12. #12
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    The reason is perfectly simple.
    The PK field in tblLaneCosts is autonumber formatted as \300.
    So record showing 301 is actually 1 and 302 is 2.
    If you try and add either value from the combo it fails because 301 & 302 don't exist in tblLaneCosts.

    Similarly if you remove RI from that link, it won't let you restore it.

    If you remove the formatting and use 1 & 2, it should work (not tested).
    If you need the existing values, do the following:
    - delete the link, delete the PK field, replace with number datatype, repopulate manually, restore the link and RI

    NOTE Before restoring RI, you'll need to MANUALLY enter values for SlotCostID in the table

    After all of this, the form will then work perfectly (tested)
    Last edited by isladogs; 09-04-2018 at 04:22 PM.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  13. #13
    erich_18 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    11
    thanks to everyone who participated in this thread. a lot of your suggestions helped in making my project better.

    Ridders52 that solved my issue, I totally overlooked the auto-number configuration I had, despite having gone through the field properties so many times. appreciate it ! thanks.

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Ahhh, I also missed the formatting. So either don't format or use 1 and 2 as the key values in tblSlotCosts.

    Good eye Ridders. Glad is resolved.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  15. #15
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    You're welcome.
    Out of interest which solution did you go with for that field?
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 02-02-2017, 10:31 AM
  2. Replies: 3
    Last Post: 03-23-2016, 12:45 PM
  3. Replies: 3
    Last Post: 12-02-2012, 04:35 PM
  4. Replies: 7
    Last Post: 04-03-2012, 12:29 PM
  5. Trouble adding data with forms
    By chuck130 in forum Forms
    Replies: 3
    Last Post: 09-02-2010, 09:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums