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
81 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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
 

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 37

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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…
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…

739 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