Advertisement

04.22.2008 at 07:22AM PDT, ID: 23343026
[x]
Attachment Details

Reading a large delimited text file using ADO

Asked by StellanRosengren in Microsoft Excel Spreadsheet Software, VB Script

Tags: MS, Excel, 2003

Dear Experts,

We are developing a method to read the content of a large text file which is the exported result of a database query. The intention is to rearrange content in a suitable way to be able to create lists and analysis reports in Excel. We cannot open the text file directly in Excel since it is too large so we would like to investigate if we can use ADO to create a connection and retrieve data by using SQL queries. We have some experience of using that technique together with Access and xls data sources.

The file structure looks like this:

------------------------------------
|Field1      |Field2     |Field 3  |
------------------------------------
|Value1      |Value2     |Value3   |
|Value1      |Value2     |Value3   |
|Value1      |Value2     |Value3   |

To define | as a delimiter, we use a schema.ini file, which is a cofinguration file, according to http://msdn2.microsoft.com/en-us/library/ms974559.aspx

Since the text file must be slightly modified in other ways, we are forced to change it in some way. It would, however, be nice if we didnt have to change every line by removing the first and last character. Even though this is a very fast process (we guess, any comments?), there could be over 100 000 lines to process, why it would take some time to do this.

The code to connect to the text file is attached. Any advice would be greatly appreciated. Are we going in the right direction?

Regards,

StellanStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
'Database connection
    Dim cnDatabaseConnection As ADODB.Connection
    Set cnDatabaseConnection = CreateObject("ADODB.Connection")
 
    'Recordset
    Dim rsRecordset As ADODB.Recordset
    Set rsRecordset = CreateObject("ADODB.Recordset")
 
    'Open the database connection
    cnDatabaseConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ThisWorkbook.Path & "\" & ";Extended Properties='text;HDR=Yes;FMT=Delimited'"
 
    cnDatabaseConnection.Open
[+][-]04.22.2008 at 07:46AM PDT, ID: 21411614

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Excel Spreadsheet Software, VB Script
Tags: MS, Excel, 2003
Sign Up Now!
Solution Provided By: sungenwang
Participating Experts: 2
Solution Grade: A
 
 
[+][-]04.22.2008 at 05:58PM PDT, ID: 21416914

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04.23.2008 at 06:00AM PDT, ID: 21420132

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628