Solved

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
9
34 Views
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


db99.jpg
db100.jpg
db101.jpg
db102.jpg




THANK YOU!
0
Comment
Question by:Dustin Stanley
  • 4
  • 4
9 Comments
 
LVL 7

Expert Comment

by:COACHMAN99
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?
0
 

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.
0
 
LVL 7

Expert Comment

by:COACHMAN99
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?
0
 
LVL 7

Accepted Solution

by:
COACHMAN99 earned 250 total points
ID: 41859638
Sorry, disregard the above comment re design - I just noticed your M:M situation
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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:

Forms!frmSkusEntry!sbfrmProducts.Form!ProductID

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!
0
 
LVL 7

Expert Comment

by:COACHMAN99
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'
0
 
LVL 34

Assisted Solution

by:PatHartman
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.
0
 

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.
0
 

Author Closing Comment

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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

705 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now