Open file selected by your route - [VB6]

0

Hi I have a question I hope you can help me, I have a archivo .csv I want to open but you must select the file previously, once selected I get your route and your name, but here comes the problem, as I do to pass your route and name the connection string so you can be loaded.

Option Explicit

Public Function LeerTxt(Directorio As String) As ADODB.Recordset
  On Error GoTo ErrorFunction
  Dim rs As ADODB.Recordset
  Set rs = New ADODB.Recordset
  Dim cn As ADODB.Connection
  Set cn = New ADODB.Connection
  Dim ruta
  Dim directorios

  ruta = Form1.File1.FileName
  directorios = Form1.File1.Path & "\"
  MsgBox ruta 'PARA COMPROBAR QUE SE ENCUENTREN LLENAS
  MsgBox directorios 'PARA COMPROBAR QUE SE ENCUENTREN LLENAS

  cn.Open "DRIVER={Microsoft Text Driver (*.txt; *.csv)};" & "DBQ=" & directorios & ";", "", ""

  rs.Open "select * from [ruta]", cn, adOpenStatic, adLockReadOnly, adCmdText
  Set LeerTxt = rs

  Set rs = Nothing
  Set cn = Nothing

  Exit Function
ErrorFunction:
  MsgBox Err.Description, vbCritical
  Err.Clear

End Function

    
asked by Francisco Rey 21.09.2016 в 20:42
source

1 answer

0

I already found the solution, it was necessary to concatenate. Greetings.

    
answered by 21.09.2016 / 21:28
source