csv File Import

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When importing a csv file into Access 2003, how do I start on a specific line
rather than always starting on the top, and therefore have the header rows
get in the way? I seem to remember a way to do this in '97?
 
What i have done in the past is to import the whole file.
If you have required fields they may not import. If not I
run a delete query based on fileds that would delete all
records that are not desired.

Chris
 
Thank you Chris : )

Unfortunately, I'm trying to create a very user-friendly process for a
non-technical co-worker to import and append a file that has a header row
that gets in the way of column names. I don't want him to have to open and
delete the header row in Notepad, and then go into Access?
 
Hi Kapila,

I don't think Access 97 is any different from later versions in this
regard. Here's a little procedure that removes the first n lines from a
textfile; it only works with 8-bit (ANSI/ASCII) files, not Unicode, and
needs a lot of error trapping to make it bombproof.

'API function declaration needed at start of module
Declare Function GetTempFileName _
Lib "kernel32" Alias "GetTempFileNameA" _
(ByVal lpszPath As String, _
ByVal lpPrefixString As String, _
ByVal wUnique As Long, _
ByVal lpTempFileName As String) As Long



Public Sub DumpFirstLinesOfTextFile(FileSpec As String, _
LinesToDump As Long)

'Removes initial lines of a text file.
'ANSI/ASCII files only.

Dim oFSO As Scripting.FileSystemObject
Dim strFolder As String
Dim strTempFile As String
Dim j As Long
Dim tsIn As Scripting.TextStream
Dim tsOut As Scripting.TextStream
Dim fiF As Scripting.File

'Work out path and names, create temp file with unique name
Set oFSO = CreateObject("Scripting.FileSystemObject")
strFolder = oFSO.GetParentFolderName(FileSpec)
strTempFile = Space(255)
GetTempFileName strFolder, "$$$", 0, strTempFile
'GetTempFileName returns null-terminated string; trim it
strTempFile = Left(strTempFile, InStr(strTempFile, Chr(0)) - 1)

'Open input file
Set tsIn = oFSO.OpenTextFile(FileSpec, ForReading)
'Overwrite temp file
Set tsOut = oFSO.CreateTextFile(strTempFile, True)

'Do the deed
For j = 1 To LinesToDump
tsIn.SkipLine
Next
Do While Not tsIn.AtEndOfStream
tsOut.WriteLine tsIn.ReadLine
Loop

tsIn.Close
tsOut.Close

'Delete source file
'(Alternatively, rename it for a backup copy)
oFSO.DeleteFile FileSpec
'Give the temp file the original name
Set fiF = oFSO.GetFile(strTempFile)
fiF.Name = oFSO.GetBaseName(FileSpec) _
& "." & oFSO.GetExtensionName(FileSpec)

Set fiF = Nothing
Set oFSO = Nothing
End Sub
 
Back
Top