MS Access Query Join 2 Tables Together for one Subform Master Child Link and cannot add record Join key of table 'ProdLocations' not in recordset

Posted on 2016-10-25
Last Modified: 2016-10-26
I have a subform that is made by query of two tables joined.  The two tables are "ProdLocations" and "Products". This Subform is Linked to the Mainform by "SkuID".  I have most of it figured out but two thing.

1: The field "SkuID" which is found in the "Products" table is not auto populating like it should on a new entry.

2: If I was to click on the field "QtyLoc"  it errors with: cannot add record Join key of table 'ProdLocations' not in recordset. BUT if I click on the new record row and then back on "QtyLoc" then it will allow me to enter a Quantity. (Which I believe has to do with the "SkuID" above.

It is putting the information into the tables all correctly accept the "SkuID" in the "Products" Table

I know query joining tables for a subform isn't the best approach but I need a single form to enter fields"Condition ID" "Price" in the Products table and "QtyLoc" into the "Locations Table.

Subform Query:

SELECT Products.ConditionID, Products.Price, Products.ProductID, Products.ProdConSku, ProdLocations.ProdLocID, ProdLocations.LocID, ProdLocations.QtyLoc, Products.SkuID
FROM Products INNER JOIN ProdLocations ON Products.ProductID = ProdLocations.ProductID
WHERE (((ProdLocations.LocID)=1));

Open in new window


Question by:Dustin Stanley
  • 4
  • 4

Expert Comment

ID: 41859615
because of the 1:M relationship between products and prodlocations, the product must exist before location can be added.
Clicking the 'new record' creates the required (product) record in the clone (ready for insert)
Is the SkuID in products defined as autonum?

Author Comment

by:Dustin Stanley
ID: 41859617
because of the 1:M relationship between products and prodlocations, the product must exist before location can be added.

My thoughts exactly but I didn't know if there was a work around in a nice clean fashion.

Is the SkuID in products defined as autonum?

It is a autonumber in SKUs table and then a Integer in the Products Table with no default.

Expert Comment

ID: 41859632
the skuid isn't auto populating because it isn't autonum (correct) but a foreign key. You need a drop-down (based on data from the SKUs table) for the user to select this in the subform.
Maybe put the Product fields first in the form?

I'm not convinced your design is sound. It looks as if you should have many products in a location, not many locations for a product. Alternatively, location would be an attribute of product?

Maybe the subform should be just location, and have a dropdown to select the product?
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.


Accepted Solution

COACHMAN99 earned 250 total points
ID: 41859638
Sorry, disregard the above comment re design - I just noticed your M:M situation

Author Comment

by:Dustin Stanley
ID: 41859668
Redesign are you crazy! Seriously though I already started redesigning. I didn't see it working but kept praying it would. Thanks for the help. I could use some of your input though on the redesign. I will tell you want I need and if you could point me in the direction.

When a new product comes in and is entered into the database. I need the user to fill out 3 fields for the two tables.

Products table = ConditionID & Price

ProdLocations table = QtyLoc (Quantity)

Of course Products has to be filled out before Prodlocations and I have beforeinsert codes on the current Subforms for that to block the user and make them do it in a sequence.

There is a unique index on the ( ProductID & LocID).

Location 1 is the default in the ProdLocations and that is basically receiving area.

The user is responsible to enter the quantity they have available. It will default to the receiving location  (LocID 1) Automatically.

****If there is more items coming in and or found at a later time while there are still items currently in (LocID 1) then the user needs to be able to increase the quantity in (LocID 1)

What I have currently as my redesign it allows the user (Which I don't Like or want) to add multiple rows of quantity but then errors because of the unique index.

the Subform Products is linked by SkuID to the main form called frmSkusEntry.

The 2nd Subform for Prodlocations is linked to the Products Subform by Child ProductID and Master:


Open in new window

So if you could take that all in and give any suggestions that would be awesome.

I would like the subform (Subforms) to appear to be one combined subform and have only 4 records max showing (One for Each ConditionID: NSOP,NSSP,USOP,USSP) in the products and then Prodlocations to have 4 lines to match for the Quantity in (LocID 1).

Thank you for your time and thought!

Expert Comment

ID: 41859680
because you only want 1 qty for each prod/loc combination you don't want to have multiple rows. The user must 'update' the qty instead of adding a new record.

The alternative design-approach is transaction-based,  where users enter 'debits' or 'credit' transactions and you derive a total based on initial value plus sum of debits and credits, This is a bunch of work so I would stay with a single record as you have.

I am signing-off now but suggest you solve the first issue before going to 'One for Each ConditionID'
LVL 36

Assisted Solution

PatHartman earned 250 total points
ID: 41861027
Please excuse me if I am off the wall.  I didn't try to digest the thread so far BUT - if the form is not populating the foreign key for the subform then -
1. Make sure that the query for the subform is selecting the correct foreign key.  You said the subform query uses multiple tables.  I don't know if one of those is the parent table.  If it is, you should delete the parent table since you don't need anything from the parent table in the subform.  If you keep it, you have to select the foreign key from the child table rather than the primary key from the main table since it is the foreign key that Access will populate based on the master/child links.
2. Make sure the master/child links are set correctly.

Author Comment

by:Dustin Stanley
ID: 41861035
Thanks pat. I have been redesigning and left this open for any advice I might use. I will come back and decide on what to do. Thanks again.

Author Closing Comment

by:Dustin Stanley
ID: 41861500
Redesign was necessary. Thank you for your time and ideas!

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records ( and Building a Custom Filter ( — discuss in some detail how a form can be…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question