Results 1 to 13 of 13
  1. #1
    Mfarr is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2015
    Posts
    6

    the primary key in new records is null

    I recently acquired a database that is already established. When entering new date the primary key is null. I've looked at the properties and the best I can figure is it has something to do with a missing property called New Values. Is there any way to fixed this?


    Thanks for any help!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Can you just set the primary key to autonumber ?, then it will NEVER be null.

  3. #3
    Mfarr is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2015
    Posts
    6
    I cannot. I've tried that and I get the following error: Once you enter data in a table, you can't change the data type for any field to AutoNumber, even if you haven't yet added data to that field.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Would have to create a new field of autonumber type.

    Then if there are dependent records that use the original field as foreign key, would have to run UPDATE query to change the foreign key to the new autonumber value. Then the original primary key field can be deleted. Rename the new field to the old name.

    Might have to break some relationships first before the old field can be deleted.
    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.

  5. #5
    Mfarr is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2015
    Posts
    6
    Unfortunately the primary key is a membership ID. We cannot reassign this number. I'm trying not to reprogram 968 membership ID number if I don't have to. I can also work around the issue and enter the ID number each time but that means I have to keep up with the last ID that was assigned.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Autonumber is not supposed to be used for a value that has meaning to users. And some advocate that a value that has meaning to users should not be a PK/FK.

    Creating a custom unique identifier requires code (common topic in forum) - which may exist in the db but is now failing. What you refer to as a property called 'New Values' may be a VBA function. We would have to see the code for analysis of issue. Or provide db. Follow instructions at bottom of my post.
    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.

  7. #7
    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,726
    Primary key can not be NULL.

    A table can have at most one primary key, but it may have more than one candidate key. A primary key is a combination of columns which uniquely specify a row; it is a special case of unique keys. One difference is that primary keys have an implicit NOT NULL constraint while unique keys do not.
    Please tell us more about your situation. A Primary Key can not be NULL.

  8. #8
    Mfarr is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2015
    Posts
    6
    I understand that the Primary Key is not supposed to be null. In this case the column that should have been the Primary Key was not given that designation. I added it once I received the database. I'm not sure if that has anything to do with the issue.

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    You added (or tried to) the PK designation? But some records are null in that field? Then you must populate the field and values must be unique then set the PK designation.

    As noted in post 6, creating custom unique identifier requires code.
    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.

  10. #10
    Mfarr is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2015
    Posts
    6
    I'm guessing there is some sort of issue in the database. I tired to create a sample to share and after deleting all the records to remove personal information the Primary key would not allow a null value. I cannot identify any SQL code in this database or any of the others we manage. All of these databases were set up year's ago and probably by someone who did not understand how to code. What makes these databases work is the following text in the format option under the General Properties for the Primary Key. "MS"00000.

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Can still provide db for analysis.

    That looks like formatting for an autonumber field.

    A primary key field should not allow Null.
    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
    Mfarr is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2015
    Posts
    6
    Any time I manipulate the database such as removing personal information the Primary key starts to work correctly. I am unable to send a copy for analysis. Is there any way to program the database to AutoNumber again? I'm pretty sure the last administrator was not personally assigning Member ID, however that function was lost when the database was sent to me.

  13. #13
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    The table does NOT now have an autonumber type field? Post 4 describes how to fix the table.

    Without examining db, can't really give more specific guidance.
    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.

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

Similar Threads

  1. Index or Primary Key Cannot Contain a Null Value
    By mrmmickle1 in forum Access
    Replies: 19
    Last Post: 11-12-2014, 06:20 PM
  2. Replies: 5
    Last Post: 11-05-2012, 04:07 PM
  3. Replies: 9
    Last Post: 07-14-2011, 07:20 AM
  4. Replies: 1
    Last Post: 08-03-2010, 01:33 PM
  5. Replies: 6
    Last Post: 02-19-2010, 03: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