Results 1 to 12 of 12
  1. #1
    knov is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2022
    Posts
    3

    The same values in primary key?

    Welcome,
    I have encountered a problem, I have two records in the database with a duplicate value that should be unique (because its primary key).


    Why did this happen? Are there any white marks I can't see?
    Is there a query that fixes this problem by adding for duplicate keys e.g. at the end the values _1, _2, _3 etc. ?

    thank you in advance

    Equipment.mdb

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Access query doesn't think these values are duplicates. Do a DISTINCT or GROUP BY query. Still returns two records. I can only suggest some sort of corruption.

    How did this happen? No idea.

    You can type whatever you want as suffix.
    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
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    They are not dupes. That cannot happen as you set dupes to No?
    You have two similar values, but one is 10 chars long, the other 12.

    You really should use an autonumber as PK, no matter if you need a visual key for users.
    Attached Thumbnails Attached Thumbnails dupes.PNG  
    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

  4. #4
    knov is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2022
    Posts
    3
    thanks for help,
    I can't add autonumber to this ms access database, these are client databases.
    I am migrating these databases to sqlite format.

    yes, they actually differ in length

  5. #5
    Join Date
    Apr 2017
    Posts
    1,792
    I.e. one of them is "0294150010", and another one is "0294150010 " - as follows they aren't equal, and your Primary Key doesn't have any problems with them!

  6. #6
    knov is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2022
    Posts
    3
    So why
    this query: SELECT * FROM CABLE WHERE CODE = "0294150010 " OR CODE = "0294150010" show only one record?

  7. #7
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Quote Originally Posted by knov View Post
    So why
    this query: SELECT * FROM CABLE WHERE CODE = "0294150010 " OR CODE = "0294150010" show only one record?
    Because only one record matches the criteria.

    try this

    SELECT *
    FROM CABLE
    WHERE CABLE.[CODE]="0294150010 " Or len(CABLE.[CODE]) > 10;

    to see both.

  8. #8
    Join Date
    Apr 2017
    Posts
    1,792
    Quote Originally Posted by knov View Post
    So why...?
    Leading characters aren't really spaces (I checked). Last 2 characters of second row Code field have ASCII codes 13 and 10.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by davegri View Post
    Because only one record matches the criteria.

    try this

    SELECT *
    FROM CABLE
    WHERE CABLE.[CODE]="0294150010 " Or len(CABLE.[CODE]) > 10;

    to see both.
    Dave, can you explain that please? In fact if you click into the field, the cursor goes to the end of the visible characters, so I am not sure what the invisible 2 characters might be. I just expected them to be spaces?

    @knov
    Try
    SELECT *FROM CABLE
    WHERE (((CABLE.[CODE]) Like "0294150010*"));

    Edit:
    Never mind, Notepad+ has shown me what is there.
    Attached Thumbnails Attached Thumbnails notepad.PNG  
    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

  10. #10
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Something like this in query field should help you to find such values. Should be able to use either 10 or 13 as I suspect they'll be there as a pair.

    IIf(InStr([rtftext],Chr(13)),"T","F")

    Or perhaps don't use rtf field for the data. Methinks it's the only field format that will hold hidden characters and trailing spaces?
    Last edited by Micron; 09-16-2022 at 08:59 AM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    I cannot get regular text field to hold trailing Cr or Lf by typing Ctrl+Enter or copy/paste but I can with an SQL INSERT (not UPDATE).

    OP's field is a normal text, not MEMO (Long Text) set to RTF. So I presume some SQL INSERT was involved in causing this issue.
    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.

  12. #12
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Ahh, ok; I confess to not uploading and looking at the sample.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 14
    Last Post: 12-24-2018, 07:55 AM
  2. Replies: 3
    Last Post: 11-10-2017, 05:35 PM
  3. Replies: 4
    Last Post: 04-19-2012, 11:01 AM
  4. Replies: 37
    Last Post: 08-10-2011, 09:43 AM
  5. UNION two tables with same primary key values
    By carillonator in forum Queries
    Replies: 1
    Last Post: 02-02-2010, 08:54 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