PDA

Click to See Complete Forum and Search --> : Get Datas from Text File separated with commas...


COSIDUS
Aug 21st, 2000, 02:32 AM
Hi everyone !!

I'd like to know how i could get datas from a Text file where datas are separated with commas. My aim is to get these datas and make them appear in different Textboxes as a Data Object can do... I need to do SQL request too with this text file... How could I do ??

If someone could help...

Thank you

COSIDUS

Gary.Lowe
Aug 21st, 2000, 04:43 AM
Cosidus

Try this


Dim cnn As New ADODB.Connection
Dim rstText As New ADODB.Recordset

'Open the connection to the directory where the file is stored
cnn.Open "Provider=MSDASQL;Driver={Microsoft text Driver (*.txt; *.csv)};DBQ=C:\Test"

'Open the text file for import
rstText.Open "test.txt", cnn, adOpenKeyset

txtText1 = Trim(rstText.Fields(0))
txtText2 = Trim(rstText.Fields(1))
txtText3 = Trim(rstText.Fields(2))
'ETC


Hope this is of use to you

Clunietp
Aug 21st, 2000, 11:55 AM
Or try this method, it doesn't use ODBC


'Uses ADO 2.1/5

Dim cn As ADODB.Connection
Dim rs As Recordset

Set cn = New Connection
Set rs = New Recordset

'open connection to folder that contains the CSV file
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\;Extended Properties=Text;"

'open the file
rs.Open "select * from test.csv", cn

'we have data
MsgBox rs.Fields(1).Value

softwareguy74
Sep 11th, 2000, 03:23 PM
In the example that Gary.Lowe gave, how would you specify a different delimiter, such as ::

It seems that your code only works if it's a comma..

Any help would be appreciated..

Dan