by Brian Bender (6 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (7 Votes)
Connect to text file(s) and perform advanced queries using ADO. You can even return recordsets on CSV file without a header.
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
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