Gustav Brock
Gustav at cactus.dk
Fri Nov 7 11:07:54 CST 2008
Hi Pedro
There is no way to this other than read the file line by line (the loop) and create your own logic how to interpret the lines.
Here are the old code examples from Seth (not with us anymore, I think):
=========Reading from a file==========
Dim dbs As Database
Dim rst As Recordset
Dim strRecordSource As String 'Source for recordset, can be SQL, table, or saved query
Dim intFileDesc As Integer 'File descriptor for output file
Dim strSourceFile As String 'Full path of source file
Dim strTextLine As String 'Input buffer
Dim strField1 As String 'Extracted Field1 from buffer
Dim strField2 As String 'Extracted Field2 from buffer
Dim strField3 As String 'Extracted Field3 from buffer
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strRecordSource, dbOpenDynaset)
intFileDesc = FreeFile
Open strSourceFile For Input As #intFileDesc
Do While Not EOF(intFileDesc) ' Loop until end of file.
Line Input #intFileDesc, strTextLine 'Read line into buffer
' < use string handling to extract the fields from strTextLine
' and place them in strField1, strField2, & strField3 >
rst.AddNew 'depending on your situation, you may want to find an
' existing record and Edit instead
rst!Field1 = strField1
rst!Field2 = strField2
rst!Field3 = strField3
rst.Update
Loop
Close #intFileDesc 'Close file.
rst.Close 'Close the recordset
Set rst = Nothing
Set dbs = Nothing 'Garbage handling before we exit the function
==================================================================================================
=========Writing to a file==========
Dim dbs As Database
Dim rst As Recordset
Dim intFileDesc As Integer 'File descriptor for output file (number used by OS)
Dim strOutput As String 'Output string for entry
Dim strRecordSource As String 'Source for recordset, can be SQL, table, or saved query
Dim strOutfile As String 'Full path to output file
Kill strOutfile 'Delete the output file before using it.
'Not necessary, but ensures you have a clean copy every time
intFileDesc = FreeFile 'Get a free file descriptor
Open strOutfile For Binary As #intFileDesc 'Open the output file for writing
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strRecordSource ) 'open the recordset based on our source string
With rst 'make things easier for ourselves
While Not .EOF
strOutput = !Field1 & ";" & !Field2 & ";" & !Field3
Print #intFileDesc, strOutput 'Print output string to file
.MoveNext 'Advance to next record in recordset
Wend
.Close 'Close this recordset
End With
Close #intFileDesc 'Close output file
Set rst = Nothing
Set dbs = Nothing 'Garbage handling before we exit the function
==================================================================================================
/gustav
>>> pedro at plex.nl 07-11-2008 17:18 >>>
Hello Gary, Susan and others,
The suggestions that you presented are all known by me, that was a to easy
question. I see that my explanation wasn't clear enough.
I need the line that is present before some lines of text with tabs, as the
first column.
31 maart 2008 13.00- 16.45 uur(zomertijd); 12 graden ....... tab 32
tab 13.47 tab etc
31 maart 2008 13.00- 16.45 uur(zomertijd); 12 graden ....... tab 33
tab 14.34 tab etc
.......
.......
......
........
........
.........
5 april 2008 12.30-17.15 uur; 10 graden; half ...................... tab
40 tab 12.45 tab etc
5 april 2008 12.30-17.15 uur; 10 graden; half ...................... tab
41 tab 12.50 tab etc
...................
...............etc
I'll hope i am clear enough now
Pedro