README.md

December 5, 2022 ยท View on GitHub

Use Text Files with ADO

Description

Connect to text file(s) and perform advanced queries using ADO. You can even return recordsets on CSV file without a header.

More Info

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

Submitted On
ByBrian Bender
LevelBeginner
User Rating4.7 (33 globes from 7 users)
CompatibilityVB 5.0, VB 6.0
CategoryDatabases/ Data Access/ DAO/ ADO
WorldVisual Basic
Archive File

Source 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