Results 1 to 5 of 5
  1. #1
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    136

    Can do DoCmd.TransferSpreadSheet work for a csv file?

    I have a csv file.



    I want to transfer the data in this file into a new table in Access.

    I currently have this code in VBA:

    Code:
    Public Sub ImportExcelSpreadSheet(fileName As String, tableName As String)
        DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, tableName, fileName, True
    End Sub
    filename is "C:\Temp\xyz.csv"
    tablename is "xyz"


    but I get an error saying "External table is not in the expected format"

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    A CSV file is just a text file with a specific structure
    Use TransferText instead
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    136
    Yes, it was the DoCmd.TransferText method I needed

    But, my table does not have the column headings from the csv file.
    Instead, it is just showing as "Field1, Field2,,,,,,,,,,,,,,Field37"
    I did specify "True" for "had headings" in the DoCmd.TransferText

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    This syntax works & imports first row as field names
    Code:
    DoCmd.TransferText acImportDelim, , "TableName", "FullFileName&Path.csv", True
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,426
    perhaps your .csv file has a blank line at the top?

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

Similar Threads

  1. DOcmd.Transferspreadsheet with a Table name
    By mcucino in forum Programming
    Replies: 1
    Last Post: 08-01-2018, 01:20 PM
  2. Docmd.Transferspreadsheet
    By RayMilhon in forum Programming
    Replies: 5
    Last Post: 06-30-2017, 08:49 PM
  3. How do I use DoCmd.TransferSpreadsheet acExport
    By morerockin in forum Access
    Replies: 6
    Last Post: 09-24-2015, 03:28 PM
  4. Importing Excel file: ADODB, DAO or DoCmd.TransferSpreadsheet
    By Monterey_Manzer in forum Import/Export Data
    Replies: 3
    Last Post: 08-13-2013, 11:34 AM
  5. Replies: 4
    Last Post: 11-09-2011, 08:40 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