Results 1 to 3 of 3
  1. #1
    Tyork is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Oct 2010
    Posts
    35

    Code for data import with calculated field

    I have an access table named SalesData with the following fields:

    UID Autonumber


    SaleDate
    Test1
    Test2
    Test3
    Test4

    I want to import an excel sheet into the table but the table only has the Test1, Test2, Test3 and Test4 fields. The UID automatically generates upon import. The final field (SalesDate) I want to have is a date based on the name of the imported file. Ideally it would be the last 10 digits of the file name which would be a shortdate. Current code is:

    Code:
    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "TestImport", "C:\Documents and Settings\tyork\Desktop\TestImport.xlsx", True
    which successfully imports the excel file without the saledate field to the SalesData table also without the SalesDate field. Any help would be greatly appreciated.

  2. #2
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    make a new table: ImportTemp that has all the fields you import plus the SalesDate field - but not the autonumber field.

    import into a temp table ImportTemp - the SalesDate field will be empty (if I understand your post)

    then apply an InsertQuery to ImportTemp table that populates your SalesDate field, all records - with the correct info.

    then apply an AppendData query that puts all the ImportTemp records into the permanent table (which will trigger the autonumber values).

    then apply a DeleteQuery to clear out all the records from ImportTemp table so it is clear for the next run (actually it is best to put this at the beginning of the process)

    done this a million times - hope it helps.

  3. #3
    Tyork is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Oct 2010
    Posts
    35
    Perfect, thank you. I didn't consider breaking it up into multiple steps.

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

Similar Threads

  1. Calculated Field Help
    By Alex Motilal in forum Queries
    Replies: 2
    Last Post: 01-06-2011, 04:54 AM
  2. Replies: 2
    Last Post: 12-03-2010, 09:33 AM
  3. Calculated field
    By nashr1928 in forum Forms
    Replies: 9
    Last Post: 08-01-2010, 01:59 PM
  4. Calculated field
    By nashr1928 in forum Forms
    Replies: 3
    Last Post: 07-22-2010, 05:10 AM

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