Solved

import csv file into Access via VBA

Posted on 2011-03-15
4
793 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 500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

734 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