MartyConnelly
martyconnelly at shaw.ca
Tue Oct 14 12:32:56 CDT 2003
Code is okay, it will fail with a subscript error if there are less than 9 fields or perhaps if this is a Unix file with a terminating LF instead of CR LF Put in a UBound(aRecord) + 1 to count number of fields. oleg_123 at xuppa.com wrote: >Hey Group >I have to convert a CSV file to Access table, with one of the records >changing from yearmonthdate(19980123) to monthdateyear(01231998) format. >So I gues I can't use macro for that since it doesn't recognise >yearmonthdate format. I wrote the code below yesterday and tested it at >home on diff table and it worked up till including Debug.Print >aRecord(8)line then I had trouble sending received data to table. Now it >doesn't work at all.. any suggestions ? > > >Dim fs As New Scripting.FileSystemObject >Dim ts As Scripting.TextStream >Dim strLine As String >Dim aRecord >Dim strSQL As String >Dim con As New ADODB.Connection > >If fs.FileExists("U:\Users\HRIS\oleg\cars testing\trainFROM.csv") Then > > Set ts = fs.OpenTextFile("U:\Users\HRIS\oleg\cars >testing\trainFROM.csv", ForReading) > > Do Until ts.AtEndOfStream > > strLine = ts.ReadLine > aRecord = split(strLine, ",") > > aRecord(8) = Mid(aRecord(8), 5) & Left(aRecord(8), 4) > > Debug.Print aRecord(8) > > strSQL = "INSERT table value(" & aRecord(0) & "," & aRecord(8) & ")" > 'con.Execute (strSQL) > > Loop >Else > MsgBox ("file doesn't exist") >End If > > > > >----------------------------------------- >Get Breaking News from CNN, ABC, NBC, CBS Now. >http://www.xuppa.com/news/?link=webmail > > >_______________________________________________ >AccessD mailing list >AccessD at databaseadvisors.com >http://databaseadvisors.com/mailman/listinfo/accessd >Website: http://www.databaseadvisors.com > > > -- Marty Connelly Victoria, B.C. Canada