Use Text Files with ADO
Connect to text file(s) and perform advanced queries using ADO. You can even return recordsets on CSV file without a header.
Original Author: Brian Bender
Inputs
Save following Data in the app.path and name file Data.txt
ID,Name,Price
1,"Chairs",$40.00
2,"Table",$75.00
3,"Fork",$1.50
4,"Lamp",$15.00
5,"Rug",$35.00
6,"Desk",&150.00
Code
Option Explicit
Dim oConn As New ADODB.Connection
Dim oRS As New ADODB.Recordset
Private Sub Form_Load()
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & App.Path & ";" _
& "Extended Properties='text;FMT=Delimited'"
'-- Use Following connection string if text file doesn't have a header for field names
'oConn.Open "Provider=Microsoft.Jet" _
& ".OLEDB.4.0;Data Source=" & App.Path _
& ";Extended Properties='text;HDR=NO;" _
& "FMT=Delimited'"
Set oRS = oConn.Execute("Select * from Data.txt ")
Dim ofield As ADODB.Field
Do Until oRS.EOF
For Each ofield In oRS.Fields
Debug.Print "Field Name = " & ofield.Name & " Field Value = " & ofield.Value
Next ofield
oRS.MoveNext
Loop
End Sub
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.