?
Solved

import csv file into Access via VBA

Posted on 2011-03-15
4
Medium Priority
?
796 Views
Last Modified: 2012-05-11
I am using the following code to import an Excel File. I need import a csv comma delimited. How how do I need to change this

    With fd
        .Title = "Select file for import"
        .Filters.Add "XLS File", "*.xls"
        .InitialFileName = INITIAL_FOLDER
        If .Show = -1 Then FilePath = .SelectedItems(1)
    End With
    Set fd = Nothing
     
        docmd.TransferSpreadsheet , acSpreadsheetTypeExcel3, "Table1", FilePath, True
0
Comment
Question by:Pdeters
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:ruslanin
ID: 35137845
   With fd
        .Title = "Select file for import"
        .Filters.Add "XLS File", "*.xls"
        .InitialFileName = INITIAL_FOLDER
        If .Show = -1 Then FilePath = .SelectedItems(1)
    End With
    Set fd = Nothing

    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;" & FilePath, Destination:=Range("$A$1"))
        .Name = "CSV Data"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 65001
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = True
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
0
 

Author Comment

by:Pdeters
ID: 35138041
I am looing to pulli n a csv file

   docmd.TransferSpreadsheet , acSpreadsheetTypeExcel3, "Table1", FilePath, True

The file will be in the same format each time
0
 
LVL 4

Accepted Solution

by:
ruslanin earned 2000 total points
ID: 35138157
Sorry, not clear understand before

try to this command

docmd.TransferText acImportDelim,"Table1",FilePath,True

more information you can find here:
http://msdn.microsoft.com/en-us/library/bb214141(v=office.12).aspx

0
 

Author Closing Comment

by:Pdeters
ID: 35138405
Thank you
0

Featured Post

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question