Results 1 to 3 of 3
  1. #1
    Mikey1987 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jan 2015
    Posts
    19

    Automatically add field to imported csv

    Hello,

    I was wondering if the following was possible.
    My "MainMenuForm" contains a button that imports a specific csv on a specific location.


    Someone should do this import once per day. The problem is that there is no way for me, once the import has been done, to know which records are "new".
    There is no unique field that distinguishes the new records from the old ones.

    I was thinking of adding like a Date() field to that csv (= the date where it was imported). Can this be done automatically?
    So if I import a file today, the final column would be 05/02/2015
    If i import a new file tomorrow, it would be 06/02/2015.

    Is this possible?

    Thanks in advance,
    Mikey

  2. #2
    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,850
    Yes it is possible. Since you know the format/layout of the csv, you could build a template - that is a table with all the fields, data types and sizes as required. This will be the table into which you import your csv data. You could also add a field ImportedDate date data type. (DATE is a reserved word in access).

    You set up code to do the import behind a form -the form is the user interface to the whole process.
    You have a button on the form. When the button is clicked, the import begins with validation to look for errors, if all is OK, the data is appended to the Table. Then an Update query fills the ImportedDate field with today's date and time (where the ImportedDate is empty).
    That's it from the import.

    You can use the same table over and over. You new data when imported doesn't fill in the ImportedDate directly.
    The ImportedDate field is empty when the import is run. A separate update query fills in the ImportedDate value, and only fills those records where there is Not yet a value.

    When you work with the imported data, you specifically select records with the ImportedDate you know/need.

    Good luck.

  3. #3
    Mikey1987 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jan 2015
    Posts
    19
    Yup, that was exactly what I needed, thanks a lot!

    just in case it might help anyone, I wrote these little commands in vba:

    Private Sub Command0_Click()
    DoCmd.SetWarnings (False)


    DoCmd.RunSavedImportExport "ChangesImport"
    DoCmd.OpenQuery "AddDateForNewChangesQ", acViewNormal, acEdit


    DoCmd.SetWarnings (True)


    End Sub

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

Similar Threads

  1. Changing Data Type of Imported Field Name
    By rhubarb in forum Import/Export Data
    Replies: 12
    Last Post: 06-16-2014, 08:20 AM
  2. Replies: 1
    Last Post: 03-01-2013, 11:02 AM
  3. Replies: 7
    Last Post: 04-24-2012, 07:38 AM
  4. Replies: 3
    Last Post: 04-20-2012, 04:33 PM
  5. Replies: 3
    Last Post: 02-17-2010, 02:29 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