LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Want to read text files of random extensions into recordset

Hi,

This is an excerpt of some code I have been working on:
-------start------------
FileToOpen = Application.GetOpenFilename
If FileToOpen < False Then
'Set path
path = Left(FileToOpen, InStrRev(FileToOpen, "\"))
'Open connection to file
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & path & ";Extended
Properties='text;HDR=NO;FMT=Delimited'"
'Set file
file = Right(FileToOpen, Len(FileToOpen) - InStrRev(FileToOpen, "\"))
'Open recordset with Earnie data
rsEarnie.Open "Select * From " + file, cn, adOpenStatic, adLockReadOnly,
adCmdText
-------end------------

It works fine when the source file has an extension of "txt", but I want it
to work regardless of the extension. The file that will be selected will be
produced by our payroll package and is created as payroll.001 or
payroll.002. Rather than ask users to rename the file with a "txt"
extension, is there a way to read the data in the file as text without the
file explicitly being named as a text file? I have tried adCmdUnknown and
all the others but they don't work. I get: "Run-time error'-2147217911
(80040e09': Automation error"

Any ideas?

TIA

Jarryd

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Read of excel spreadsheet with ADO recordset ER Excel Programming 2 September 16th 08 01:47 PM
help with macro to read and sort data from multiple text files [email protected] Excel Programming 0 March 15th 07 11:02 PM
ADO recordset closed, cannot read Michael Kellogg Excel Programming 2 May 6th 05 10:22 PM
How to read multiple text files into excel? Together Excel Programming 3 February 29th 04 09:00 AM
Read/Write data to/from text files from a spreadsheet. lothario[_37_] Excel Programming 8 November 2nd 03 03:10 PM


All times are GMT +1. The time now is 11:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"