Read CSV file into Recordset in vb 6

In the following code we are using ADODB object so first we need to add a reference of ‘Microsoft ActiveX Data Objects’ in the Visual Basic project before using ADO libraries

Follow below steps:
1. Click the Project menu item and then select References… from the drop-down menu panel.
2. From References, check the box for Microsoft ActiveX Data Objects n.n Library, where where n.n represents the latest version number.
3. Check this Code:

Private Sub Form_Load()
    Dim rs As ADODB.Recordset
   Set rs = ReadRs()
 End Sub
 
Private Function ReadRs() As ADODB.Recordset
 
    Dim path As String
    path = "D:\"
 
    Dim strConn As String
    strConn = "Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
    " Dbq= " & path & ";Extensions=asc,csv,tab,txt;DefaultDir=C:\; Extended Properties=TEXT"
 
    Dim cn As ADODB.Connection
    Set cn = New ADODB.Connection
    cn.CursorLocation = adUseClient
 
    cn.Open strConn
 
    Set ReadRs = New ADODB.Recordset
    ReadRs.Open "Select * from test.CSV", cn
    If ReadRs.RecordCount > 0 Then
     ' You can use recordset here
    End If
    ReadRs.Close
    cn.Close
End Function