RE:Importar datos
Publicado por
Juan (1 intervención) el 24/07/2002 14:25:49
La única solución que yo conozco es la siguiente:
nf=freefile
Open FICHERO For Input As #nf
Do
Line Input #nf, Linea 'LEE LINEA DEL FICHERO
Pos = InStr(Linea, ",") 'BUSCA EN ESA LINEA EL CARACTER SEPARADOR DE CAMPOS EN TU CASO LA COMA
c = 0
REGISTRO.AddNew 'AÑADE UN REGISTRO NUEVO EN LA TABLA
Do While Pos <> 0 'MIENTRAS ENCUENTRE EL CARACTER
'TIENES QUE PONER TANTOS CASE COMO CAMPOS -1 TENGAS
'SI TIENES 6 CAMPOS PONES HASTA CASE 5:
c = c + 1
Select Case c
Case 1:
REGISTRO!CAMPO1 = LTrim(RTrim(Mid(Linea, 1, Pos - 1)))
Case 2:
REGISTRO!CAMPO2 = LTrim(RTrim(Mid(Linea, 1, Pos - 1)))
End Select
Linea = Mid(Linea, Pos + 1)
Pos = InStr(Linea, ",")
Loop 'SALE CUANDO YA NO ENCUENTRA MAS, ES DECIR, ESTA EN
'EL ULTIMO CAMPO
If c = 0 Then 'SI LA LINEA NO ES VALIDA
REGISTRO.CancelUpdate
Else
REGISTRO!ULTIMO_CAMPO = LTrim(RTrim(Linea))
RegArtG.Update
End If
Loop Until EOF(nf)
Close #nf
Espero que te sirva, yo siempre uso este metodo y me va bastante bien, si el caracter separador es otro basta con cambiar en la sentencia:
Pos = InStr(Linea, ",")
la coma por el caracter separador correspondiente.
Saludos.