Results 1 to 6 of 6
  1. #1
    surfdragon is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    5

    Import excel data to access with an auto number field

    Hi,



    This could be a long one so please bear with me.......

    Whilst carrying out some work on a database last week I inadvertently deleted the back end (aaaaaaaaaaah).
    Due to a lack of IT support there is now no chance of recovery (we were led to believe all our databases were backed up daily, wrong!)

    I have an old version of the back end which I had backed up a while back, and an Excel spreadsheet which is a direct copy of the table (completely up to date). However I am having trouble changing the spreadsheet to a direct copy of the table as one of the fields which is the primary key is an auto-number field.

    My first question is should an append query allow me to do this?
    If not can it be done?

    Many thanks and please go gently as I only have a limited grasp of access

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,895
    Why is an autonumber field causing issue? When you import data it is creating primary keys that don't agree with foreign key in dependent records?

    It is possible to force the value saved into autonumber field. Do this test. Create a table with an autonumber field and couple other fields and maybe 10 records then copy that table - Structure Only. Run code in VBA immediate window:

    CurrentDb.Execute "INSERT INTO Table2 SELECT * FROM table1"

    Table1 and table2 should be identical. Delete a couple of records from table2. Run the code again. Tables should still be identical.

    Set a link to spreadsheet and run code similar to above.


    After doing an edit like this, good idea to run Compact & Repair.
    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
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,002
    If the Spreadsheet has everything in it then simply import it as is into a new table.
    Rename you old data table and then change your new table name to the original data table name. (Make sure you have Auto-Correct names option switched off.!)

    Now change the field type to of the ID field to Primary key and then to Autonumber, and you should be good to go.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,895
    Can't change a field to autonumber type (even if there is no data in it). Just tried it.
    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
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,002
    @June - You are correct - I'm sure you used to be able to to do that in earlier versions.

    @OP apologies, the only way is to have an empty table and then append query as per June's instructions.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,895
    Make table query also works. Don't have to pre-build table. Issue is won't be able to immediately see the new table. Run C&R.

    CurrentDb.Execute "SELECT * INTO Table2 FROM Table1"
    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. Replies: 2
    Last Post: 01-12-2017, 10:35 AM
  2. Auto Import Excel Data into a Running Access Database
    By novice1979 in forum Programming
    Replies: 5
    Last Post: 12-02-2014, 08:19 AM
  3. Replies: 6
    Last Post: 07-31-2014, 12:53 PM
  4. Import access query data into excel file, using excel vba
    By exceljockey in forum Import/Export Data
    Replies: 3
    Last Post: 11-15-2013, 02:36 PM
  5. Primary Key Auto Number not available in Excel for import
    By justphilip2003 in forum Import/Export Data
    Replies: 1
    Last Post: 04-30-2013, 07: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