Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Read Text Files Into a Recordset - Semicolon Delimiter

Posted on 2001-06-18
8
Medium Priority
?
5,444 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

722 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