A
Armando Vargas
Hello!
Anyone has the solution into how to import text files into a ADP using code?
I found something, but dont know how it works.
Thanks!
Private Sub Comando0_Click()
LeerDelimitado ("c:\casetas.txt")
End Sub
Public Sub LeerDelimitado(sArchivo As String)
'Requiere referencia a Microsoft Scripting Runtime
Dim MiFSO As FileSystemObject, MiSTR As TextStream
'Referencia a objetos ADO
Dim cnn As ADODB.Connection, rs As ADODB.Recordset, i As Integer
Set cnn = New ADODB.Connection
'Configura tu cadena de conexión. Mira en http://tinyurl.com/n42r9
cnn.Open "Provider=sqloledb;" & _
"Server=MOBILxe;" & _
"Database=AdveXE;" & _
"User Id=sa;" & _
"Password=miserver"
Set rs = New ADODB.Recordset
rs.Open "TblRegistroIAVE", cnn, adOpenStatic, adLockOptimistic
Dim sCampos() As String
Set MiFSO = New FileSystemObject
Set MiSTR = MiFSO.OpenTextFile(sArchivo, ForReading)
Do Until MiSTR.AtEndOfStream
sCampos = Split(MiSTR.ReadLine, "|")
'Código para tratar la matriz sCampos
rs.AddNew
For i = LBound(sCampos) To UBound(sCampos)
rs.Fields(0) = sCampos(i)
Next
rs.Update
Loop
rs.Close
Set rs = Nothing
cnn.Close
Set cnn = Nothing
MiSTR.Close
Set MiSTR = Nothing
Set MiFSO = Nothing
End Sub
Anyone has the solution into how to import text files into a ADP using code?
I found something, but dont know how it works.
Thanks!
Private Sub Comando0_Click()
LeerDelimitado ("c:\casetas.txt")
End Sub
Public Sub LeerDelimitado(sArchivo As String)
'Requiere referencia a Microsoft Scripting Runtime
Dim MiFSO As FileSystemObject, MiSTR As TextStream
'Referencia a objetos ADO
Dim cnn As ADODB.Connection, rs As ADODB.Recordset, i As Integer
Set cnn = New ADODB.Connection
'Configura tu cadena de conexión. Mira en http://tinyurl.com/n42r9
cnn.Open "Provider=sqloledb;" & _
"Server=MOBILxe;" & _
"Database=AdveXE;" & _
"User Id=sa;" & _
"Password=miserver"
Set rs = New ADODB.Recordset
rs.Open "TblRegistroIAVE", cnn, adOpenStatic, adLockOptimistic
Dim sCampos() As String
Set MiFSO = New FileSystemObject
Set MiSTR = MiFSO.OpenTextFile(sArchivo, ForReading)
Do Until MiSTR.AtEndOfStream
sCampos = Split(MiSTR.ReadLine, "|")
'Código para tratar la matriz sCampos
rs.AddNew
For i = LBound(sCampos) To UBound(sCampos)
rs.Fields(0) = sCampos(i)
Next
rs.Update
Loop
rs.Close
Set rs = Nothing
cnn.Close
Set cnn = Nothing
MiSTR.Close
Set MiSTR = Nothing
Set MiFSO = Nothing
End Sub