Re: Can't seem to use FileSystemObject
- From: "Bob Bridges" <rhbridg@xxxxxxxxxxxxx>
- Date: Tue, 6 Mar 2007 14:02:01 -0600
1) I'm a little skeptical about this csv situation. It seems to me that any
csv file with fields that contain commas themselves isn't in csv
format...unless, of course, those fields have quotes around them. But I
shouldn't think Access would be confused by them (though I admit I've never
tried it).
Be that as it may, I'm really here about the second part of the question.
2) What message, exactly, are you getting? And since you mention Access and
Excel both, I suppose I'd better ask: Which application are you running
this code in?
Notice that in your code snippet, "opentextfile" has no capital letters; I
take that as a hint that your application didn't recognize it as a valid
method. In Access, the way to import a text file is TransferText; in Excel
it seems to be OpenText (though I've never used it in VBA). So I suspect
the problem isn't the fs object but the method you're trying to use on it.
Does that point you in the right direction?
---
Bob Bridges, rhbridg@xxxxxxxxxxxxx, cell 336 382-7313
(hotel) 612 869-7704 xt 118, fax 612 869-7383
/* A crooked politician may be faithful to his wife, but a man who deceives
his own wife can't be relied on to deal honestly with the public. We have
been getting this backward lately. We've been assuming that you can have
public virtue without private virtue. -Joseph Sobran, 1998 */
--- <brigitte@xxxxxx> wrote in message
news:1173208054.316647.298850@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
The original problem:
I need a procedure to import a csv file created by a third party
application into an Access database. This file contains fields which
may include commas, and when they do, Access confuses the commas for
field separators, so that a block of text which should all be in one
field ends up in two fields. I've seen by reading through this group
that this is a pretty common problem with csv files.
The solution I came up with:
I noticed Excel, for some reason, always read the file correctly. I
can't explain it, I would have thought it would have the same problem
as Access, but for whatever reason, it reads the file just fine.
Because of that, I thought I could use automation to open the file in
Excel, convert it to a tab delimited file, then import the tab
delimited file in Access. This is complicated by another aspect to the
problem: the file can be over 65,536 lines long.
To solve that problem, I'm in the process of building a procedure that
reads the file and splits it in two when it has too many lines. If
anybody can suggest a better way to handle the third party csv file
and make it behave when imported, I'd be very happy to read about it:
the workaround described above doesn't exacly feel ideal.
Now here's the real problem: I declared a FileSystemObject and
referenced the Microsoft Scripting Runtime library, but the reference
doesn't seem to work. The visual basic editor can't list the
properties and methods for the object, and doesn't recognize the
OpenTextFile method (Typed it in all lowercase, and typed it all since
I can't get a pull-down list from the fs object, and the editor does
not change any letter to uppercase, or give me any cool-tip for the
arguments).
Here's the code I'm using:
*******
Function fnFirstHalf(strFullPath As String) As String
'This function creates the first part of the file specified by
'strFullPath and returns the full path for that file.
Dim fs, fileOrig, fileA As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Set fileOrig = fs.opentextfile(strFullPath, False)
End Function
*****
So, hoping for one of two things:
1. Somebody can tell me how to avoid the whole messy thing and make
the csv behave and import correctly
or
2. Somebody can tell me how to make my FileSystemObject work. As
mentionned above, I do have the Microsoft Scripting Runtime library
referenced.
.
- References:
- Can't seem to use FileSystemObject
- From: brigitte
- Can't seem to use FileSystemObject
- Prev by Date: Re: Followup to design question
- Next by Date: Re: Followup to design question
- Previous by thread: Can't seem to use FileSystemObject
- Next by thread: Re: Can't seem to use FileSystemObject
- Index(es):
Relevant Pages
|