Results 1 to 6 of 6
  1. #1
    revvedmoto is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2014
    Posts
    32

    How to import csv file over existing table records with vba.

    I have 6-8 csv files that I need to import and overwrite existing records in there corresponding table. I thought this was going to be easy but when researching code it seemed more complex then originally thought. My limited experience with vba isnt helping much either. Any help would be appreciated.

    This is some of the code that I picked through that I thought would be a rough start.



    DoCmd.SetWarnings False
    DoCmd.RunSQL "DELETE * FROM NameOfTable"
    DoCmd.SetWarnings True

    DoCmd.TransferText acExportDelim, "Standard Output", _
    "External Report", "C:\Txtfiles\April.doc"

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    49,229
    It's a start.

    You need acImportDelim.

    The "Standard Output" is referencing a saved import or export specification. This is an optional argument.

    Replace "NameOfTable" with the actual name of your table. Same for "External Report". And of course use the path/filename for your text file.
    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
    revvedmoto is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2014
    Posts
    32
    Heres what I got but Im getting an error. I imported the file manually and saved the import as "import-pu". I can go to the saved imports and it imports just fine but gives me the following error when I click my update button.
    Click image for larger version. 

Name:	error.JPG 
Views:	8 
Size:	21.4 KB 
ID:	15517
    Private Sub Delupdate_Click()
    DoCmd.SetWarnings False
    DoCmd.RunSQL "DELETE * FROM PartsUnlimited"
    DoCmd.SetWarnings True


    DoCmd.TransferText acImportDelim, "Import-PU", _
    "PartsUnlimited", "C:\Users\Revved Up\Desktop\Price Files\Parts\MT0376_DealerPrice.csv"
    End Sub

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    49,229
    I don't do much importing and the few times I've experimented with saved specification, found very frustrating. Don't think I ever got to work.
    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
    revvedmoto is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2014
    Posts
    32
    Here we go. I think I got it.

    DoCmd.RunSavedImportExport "Import-PU"

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    49,229
    Guess that explains my frustrating experiences.

    Glad you found 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.

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

Similar Threads

  1. Import Excel data into existing Access Table
    By octsim in forum Import/Export Data
    Replies: 4
    Last Post: 10-24-2013, 07:21 AM
  2. Replies: 2
    Last Post: 05-21-2012, 08:46 PM
  3. Adding records to existing table
    By Mclaren in forum Programming
    Replies: 5
    Last Post: 05-18-2011, 12:44 PM
  4. Replies: 7
    Last Post: 04-15-2011, 08:46 AM
  5. Import multiple dbf files into existing table?
    By sbg2 in forum Import/Export Data
    Replies: 0
    Last Post: 06-12-2006, 02:06 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 - Senior Forums