Solved

Read Text Files Into a Recordset - Semicolon Delimiter

Posted on 2001-06-18
8
4,983 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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
 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

770 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