Solved

Read Text Files Into a Recordset - Semicolon Delimiter

Posted on 2001-06-18
8
4,859 Views
Last Modified: 2008-03-17
Hi experts,
I am very new in Visual Basic and still learning.
I try to use ADO and the ODBC text driver to open a text file an read it into a recordset.
Below is what I'm doing now in my program :

'=============================================
Dim connCSV As New ADODB.Connection
Dim rsTest As New ADODB.Recordset

connCSV.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
 & path & ";Extended Properties='text;HDR=NO;FMT=Delimited'"

rsTest.Open "Select * From test.txt", _
       connCSV, adOpenStatic, adLockReadOnly, adCmdText
Do While Not rsTest.EOF
MsgBox rsTest(0)  
rsTest.movenext
Loop
'==========================================

If I have a text file like this :
John, Los Angeles, USA
Mary, New York, USA
I will have rsTest(0) as John, and then Mary.
So far it works, but I must use comma delimiter in my text file.

My question is :
Is it possible to use other character as delimiter in my text file, like semicolon (;) ?
FYI :
- I use Oracle 8, VB 6, Win2K Pro
- At the first time I didn't have any Schema.ini file, then I tried to copy schema.ini file to c:\WinNT\System32\ and configured it by adding 1 line : "Format=Delimited(;)", but still can't work.
 
I look forward to your early reply :-)
Your help will be very much appreciated.

Rgds,
Kiky
0
Comment
Question by:kiky
8 Comments
 
LVL 1

Expert Comment

by:darthg8r
ID: 6204901
The default FMT is CSV try
connCSV.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
& path & ";Extended Properties='text;HDR=NO;FMT= "_
"Delimited(ascii)'"
where ascii is any character besides a double quote "
0
 

Author Comment

by:kiky
ID: 6204921
Hi dartq8r,
Thanks for your reply.
I tried this one :
connCSV.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
& path & ";Extended Properties='text;HDR=NO;FMT=Delimited(#59)'"

But still can't work.
The rsTest(0) still contain the first row data, not only the first field.

Rgds,
Kiky
0
 

Author Comment

by:kiky
ID: 6204928
I'm sorry this is the first time I ask question to expert-exchange.
This question is still open to anyone else, but I don't know how to change the status...






0
 
LVL 5

Expert Comment

by:gbaren
ID: 6207548
You need to reject the answer. There should be an option at the bottom of the page.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 7

Expert Comment

by:Z_Beeblebrox
ID: 6208451
Hi,

Try:

connCSV.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
& path & ";Extended Properties='text;HDR=NO;FMT=Delimited(;)'"
0
 

Author Comment

by:kiky
ID: 6209419
Hi dartq8r, Z_Beeblebrox, gbaren
Thanks for your reply.

I tried this one :
connCSV.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
& path & ";Extended Properties='text;HDR=NO;FMT=Delimited(#59)'"

connCSV.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
& path & ";Extended Properties='text;HDR=NO;FMT=Delimited(;)'"

Both of them can't work.
I think I need to reject the answer so I can change the status.
Anyway thank you very much for the help.

Rgds,
Kiky
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 260 total points
ID: 6211324
Try this:

Give this text file (d:\temp\test.txt):
John*Los Angeles*USA
Mary*New York*USA

And this Schema file (d:\temp\schema.ini):

[test.txt]
ColNameHeader=False
Format=Delimited(*)
MaxScanRows=0
CharacterSet=OEM
Col1=F1 Char Width 255
Col2=F2 Char Width 255
Col3=F3 Char Width 255

The following code works for me:

Dim rs As ADODB.Recordset
Dim fld As Field

Set rs = New ADODB.Recordset
With rs
   .Source = "Select * From test.txt"
   .ActiveConnection = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=d:\temp\;Extensions=asc,csv,tab,txt;"
   .CursorType = adOpenForwardOnly
   .LockType = adLockReadOnly
   .Open Options:=adCmdText
   Do While Not .EOF
      For Each fld In .Fields
         Debug.Print fld.Value,
      Next
      Debug.Print
      .MoveNext
   Loop
   .Close
End With
Set rs = Nothing
0
 

Author Comment

by:kiky
ID: 6213625
Dear acperkins,
It works ! :-)
Thank you very much for your help.

The point is yours :-)

Regards,
Kiky
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now