473,498 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't seem to use FileSystemObject

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.

Thanks a bunch to anyone who tries! :D

Mar 6 '07 #1
3 5888
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, rh*****@attglobal.net, 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 */

--- <br******@mun.cawrote in message
news:11**********************@8g2000cwh.googlegrou ps.com...
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.

Mar 6 '07 #2
Tom
Have you tried Chuck Grimsby's solution at: http://www.mvps.org/access/modules/mdl0057.htm.
It might solve both your issues.

Tom

Mar 6 '07 #3
On 6 mar, 17:24, "Tom" <rtmn...@swbell.netwrote:
Have you tried Chuck Grimsby's solution at: http://www.mvps.org/access/modules/mdl0057.htm.
It might solve both your issues.

Tom

I didn't even know this existed.

Thank you Tom, I'll check it out!

Bob:
I can't confirm that the file is a genuine csv. It has the csv
extension and is comma delimited, despite the lack of quotation marks
around text fields.
I'm working in Access, and I would be using automation to make Excel
open the file (because for unexplainable reasons, Excel reads it
properly and Access does not).

I haven't got as far as getting an error message. The editor doesn't
recognize the object or the function, so I'm assuming something along
the line of "undefined function". Is there any instance of the editor
not recognizing a function like that but still running it fine?

I was avoiding using TransferText on the csv because since Access does
not read the file properly, I was reluctant to put it into a table (I
would have extra fields for some records, which I'm afraid would
complicate things). Unless I'm reading the help file wrong and
TransferText doesn't put the data in a table?

OpenTextFile is an alternate way of reading a file, this time line by
line and as straight text, that I found in the help of the visual
basic editor. I've seen it refered to in this group when I searched
for it, but I can't honestly tell you whether it works in Access 2003.
All I know is that it's not working for me, thus my initial post.

I hope this clears things up, thanks for your reply. I'm going to
check Chuck Grimsby's solution and I'll post again if that doesn't
help.


Mar 7 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3832
by: Marcelo Rizzo | last post by:
I am trying to get the name of a file with a specific extension (tmw) from several different directories. The problem I am having is that the program stops working on the second pass with an run...
5
4036
by: John Dewbert | last post by:
*** post for FREE via your newsreader at post.newsfeed.com *** Hello, I have trouble passing a folder object (from a FileSystemObject) to a sub procedure. Consider the following code: ...
7
3977
by: Aaron Bertrand - MVP | last post by:
Based on a complaint that one of my articles just links to the MS documentation, I'm writing a tutorial on FileSystemObject. However I'm currently getting stalled by this bug. Environment:...
3
2098
by: Steve | last post by:
Hi all, FileSystemObject question... I'm trying to check if files exist or not, but the files are not sitting on the same server as our Intranet. Basically we have about 5000 photos in a...
2
2159
by: Sean S - Perth, WA | last post by:
Hi all, If I create a FileSystemObject Object is it appropriate to reuse it to perform operations on different files/folders? Or should I create a new FileSystemObject Object for each file and...
4
1271
by: Stimp | last post by:
This is a query to do with classic ASP (written through vbscript). I apologise in advance to posting to an ASP.NET forum, but my newsserver doesn't have any others listed... plus it's a permissions...
4
10349
by: Astra | last post by:
Hi All I know there are numerous postings on the web about this, but none of them seem definitive and they haven't resolved my issue. I'm running WinXP Professional and IIS v5.1 to create my...
1
17067
by: G Gerard | last post by:
Hello I am using the FileSystemObject to copy files on a computer Dim MyObject as Object
2
1657
by: John Bailo | last post by:
I have an IBM iSeries that lets me use part of its file system via Windows. I wanted to write a file monitor for files put there from the as400 side. However, after writing and testing my code...
0
7165
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7203
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4908
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4588
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3081
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1417
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
290
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.