Results 1 to 10 of 10
  1. #1
    dipique is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    31

    Cannot Add Record - Join Key of tblMaster not in RecordSet


    This is probably a simple fix, but I'm new to Access and pretty fried from doing a lot of work in an unfamiliar tool.

    I have a massive system that I've developed for tracking inventory, and there's an "Items" table that needs to be added to. Certain columns contain the primary keys of other tables through a normal lookup type function.

    I have a query that patches all this together, creating a table with all the text values rather than just the keys; however, I can't add to that table because I get the error "Cannot Add Record(s) - Join Key of [table] not in RecordSet." I've fiddled and searched but I haven't been able to come up with a solution.

    I boiled down my problem to an ultra-simple database; it's attached here. You can duplicate the error by opening the only query and trying to add a record.

    I'd appreciate assistance; thanks in advance!

    Dan

    testDB.accdb
    testDB.mdb
    Last edited by dipique; 04-11-2012 at 02:00 PM. Reason: Add MDB

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Not everyone has Ac2007 or 2010 so can not read an accdb. You may get more responses if you post an mdb version of your database.

  3. #3
    dipique is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    31
    I've edited to include an MDB. Thanks for the tip!

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    That's a very sparce Inventory database.

    Getting your table structures and relationships correct is key to database.
    Your tables and relationships must "accurately" model your business.
    Here are some free video tutorials that describe the processes of data modelling, normalization and entity relationship diagramming. There are other videos, but this group is by the same presenter and covers an example situation.

    http://www.youtube.com/watch?v=IiVq8M5DBkk Logical data modeling

    http://www.youtube.com/watch?v=BGMwuOtRfqU Candidate key

    http://www.youtube.com/watch?v=ZiB-BKCzS_I Normalization

    http://www.youtube.com/watch?v=pJ47btpjAhA Normalization example

    http://www.youtube.com/watch?v=q3Wg2fZENK0 1st Normal form

    http://www.youtube.com/watch?v=vji0pfliHZI 2nd Normal form

    http://www.youtube.com/watch?v=HH-QR7t-kMo 3rd Normal form

    http://www.youtube.com/watch?v=q1GaaGHHAqM E_R Diagramming

    http://www.youtube.com/watch?v=lXAGQ8vmhCY ERD Part 2

    The first few topics at this site are well worth the read.

    http://www.rogersaccesslibrary.com/forum/topic238.html

    Good luck with your project.

  5. #5
    dipique is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    31
    Orange,

    I appreciate the resources, but as you might imagine I don't have the time to pursue general education in the hopes that I will at some point understand my problem. My goal is to get this project taken care of, and then get me some formal learnin. At which time your links will be very helpful.

    In the meanwhile, can anyone point out the issue with the DB I attached? I can also upload my actual DB if that would be helpful, but the attached DB is much simpler and represents the issue well.

    Thank you,

    Dan

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    It isn't common for the ITEMS table to have a number of links to other Tables. Please describe what you have in plain English.

    The data model in the sample videos deals with Customer , Order, LineItems and Items.

    Can you tell us in real terms what Master represents, and ITEMS because your sample use Master and Things?

  7. #7
    dipique is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    31
    Sure. Master represents the Items table. Things represents a set of options--for example, colors. Black, white, red, and blue. Any item in the Master table could be black, white, red, or blue.

    However, I don't want the Master Table to contain those words, only references (via Row ID) to the Items table.

    Dan

  8. #8
    dipique is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    31
    I would still like to understand why this didn't work, but in the meanwhile I solved my problem. It only took a couple lines of code to add items directly to the Items table instead of adding them to the query that brings in all the lookup values, so that's what I did. It ain't pretty but it works.

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  10. #10
    dipique is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    31
    There's really nothing to post. Based on the DB I uploaded, the issue was not being able to add records to the query. So I stopped adding records to the query and instead just added records to the "Master" table from my form, looking up the "Thing" values in code. I'll post my actual code here, though of course it goes with my full DB and not the example I uploaded.

    Code:
    Public Sub AddItemWithMFG(MFG As String, ModelNumber As String, HasUniqueID As Boolean, IsPhysical As Boolean)
       'Create my database as a variable
       Dim dbInventory As DAO.Database
       Set dbInventory = CurrentDb
       
       'Create my Items table as a variable
       Dim rstItems As DAO.Recordset
       Set rstItems = dbInventory.OpenRecordset("Items")
    
       'Add a new item to my Items table
       rstItems.AddNew
       
       'Look up ID associated with MFG value.  This is what I was trying to use the query for.
       Dim MFGID As Integer
       MFGID = DLookup("ID", "MFGList", "MFG='" & MFG & "'")
       rstItems("Manufacturer").Value = MFGID
       
       'Add more fields...
       rstItems("ModelNumber").Value = ModelNumber
       rstItems("HasUniqueID").Value = HasUniqueID
       rstItems("IsPhysical").Value = IsPhysical
    
       'Update the table
       rstItems.Update
    End Sub
    I tried to simplify and clarify the code a bit, but you get the idea. Instead of having the query look up the manufacturer, I just did it in code so it could be added directly to the Items table.

    Dan
    Last edited by dipique; 04-12-2012 at 07:26 AM. Reason: Spacing issues

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

Similar Threads

  1. Replies: 23
    Last Post: 01-24-2012, 12:46 PM
  2. Join Key of table in recordset
    By Rohit0012 in forum Forms
    Replies: 14
    Last Post: 09-24-2011, 09:04 PM
  3. Replies: 5
    Last Post: 09-19-2011, 12:01 PM
  4. join key not in recordset - what does it mean?
    By geophilus in forum Queries
    Replies: 1
    Last Post: 08-22-2010, 09:32 AM
  5. Join A Recordset to the current db Table
    By mjellis in forum Programming
    Replies: 0
    Last Post: 08-10-2010, 02:44 PM

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