Results 1 to 12 of 12
  1. #1
    alexpmi is offline Novice
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    1

    Can't update data using form keep getting message saying will create duplicate values

    Hello, I don't know much about Access, so I would first of all, like to apologize if my question is silly and obvious, but I have been trying for some time and can't figure it out.

    I am creating a database to keep track of a set of art pieces. Each piece has a series of attributes, one of which is style, a piece can have more than one style.

    I have created one table with a series of fields for each piece (name, author, etc.) which has a field called PieceID as the primary key and another table with the different styles which only has two fields, StyleID (Primary key) and StyleName.



    I have created a third junction table which has two primary keys, PieceID and StyleID to link the two tables. The two tables are linked one-to-many to this table via their respective primary keys.

    I wanted to have a form to introduce and edit all the info for the pieces and when it comes to choosing the style be able to choose from the list of existing styles. I thought of using a form with the main table fields and then a subform with the different styles for the piece. The problem is I wanted this subform to only have one combobox which would use the list of existing Styles as its source, so I can choose StyleName not StyleID . I can't figure out how to do this and get it to work.

    Any help would be greatly appreciated.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    With main form bound to Pieces, subform should be bound to junction table and have a combobox to select style.

    Combobox properties:

    RowSource: SELECT StyleID, StyleName FROM Styles ORDER BY StyleName;
    BoundColumn: 1
    ColumnCount: 2
    ColumnWidths: 0";1.0"
    ControlSource: StyleID (field from junction table - advise not to use exact same field name in multiple tables)

    This will allow selecting style by name but save ID.

    Be sure to set subform Master/Child Links properties.
    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
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    You can have a pk field in the junction table, but the 2 other fields should be foreign keys, not primary. You would not be able to repeat any given value from either of the 2 related tables in the junction table. Or did I misinterpret the original post?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    Have a look at this link to see examples of handling many-to-many tables and data entry.

    Many-To-Many, two ways to update Junction table, includes Not In List handling (accessforums.net)

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Micron, I expect junction table has compound primary key using two number fields which should be fine although could just be compound index.
    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.

  6. #6
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    I considered that. Could also be exactly as described
    a third junction table which has two primary keys
    which is pretty much guaranteed to cause the issue.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Isn't two primary keys impossible? Whereas a compound key is possible and not an issue, just not needed unless junction table will have related child table. I have used compound key only once.
    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.

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    I have created a third junction table which has two primary keys, PieceID and StyleID to link the two tables. The two tables are linked one-to-many to this table via their respective primary keys.
    I believe the O/P means they are FKs from their respective table PK?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #9
    xps35's Avatar
    xps35 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jun 2022
    Location
    Schiedam, NL
    Posts
    300
    Quote Originally Posted by alexpmi View Post
    I have created one table with a series of fields for each piece (name, author, etc.) which has a field called PieceID as the primary key and another table with the different styles which only has two fields, StyleID (Primary key) and StyleName.
    I have created a third junction table which has two primary keys, PieceID and StyleID to link the two tables. The two tables are linked one-to-many to this table via their respective primary keys.
    Can you please share a copy of your database?
    Groeten,

    Peter

  10. #10
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    Isn't two primary keys impossible?
    Don't think I've ever tried. Did so just now and you're correct, so OP is not - technically speaking, that is.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    Perhaps op is talking about a multi field pk?

  12. #12
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    Time to upload the DB methinks?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 2
    Last Post: 06-26-2019, 02:22 PM
  2. Replies: 1
    Last Post: 06-18-2014, 04:08 AM
  3. Customise the duplicate values error message
    By lsmcal1984 in forum Forms
    Replies: 2
    Last Post: 10-09-2013, 04:36 PM
  4. Duplicate data message for a data entry form
    By JulieMarie in forum Access
    Replies: 5
    Last Post: 07-30-2013, 08:18 AM
  5. Replies: 20
    Last Post: 09-12-2012, 06:52 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