appending to a text file 
Author Message
 appending to a text file

I want to read a recordset and write it to a text file.
But, I want this routine to run several times during the
day, so I want the text file to be appended to....not
overwritten. I have to use Access '97. I don;t think
TransferDatabase has an append...can I write a VBA
routine similar to this...

OPEN "C:\test.txt" FOR APPEND AS #1
PRINT #1, text1.text
close #1

Thanks Ed



Sun, 10 Apr 2005 19:00:05 GMT  
 appending to a text file
Ed,

Take a looking at the FileSystemObject which gives you a
lot more flexibility with the option to Append to a text
file.  You will need to set a reference to the Microsoft
Scripting Library.

Hope this helps
Mark

Quote:
>-----Original Message-----
>I want to read a recordset and write it to a text file.
>But, I want this routine to run several times during the
>day, so I want the text file to be appended to....not
>overwritten. I have to use Access '97. I don;t think
>TransferDatabase has an append...can I write a VBA
>routine similar to this...

>OPEN "C:\test.txt" FOR APPEND AS #1
>PRINT #1, text1.text
>close #1

>Thanks Ed
>.



Sun, 10 Apr 2005 19:45:01 GMT  
 appending to a text file
You are correct about the TransferText not having an append feature.
I also think you are correct about your sample code.

================================================
Here is a sample of some general export code:

Public Sub ExportDelim(strTable As String, strExportFile As String,
strDelimiter As String, Optional blnHeader As Boolean)

   'strTable is the table or query name
   'strExportFile is the full path and name of file to export to
   'strDelimiter is the field deliminator to use like Chr(9) for tab or
Chr(44) for comma or ??

   Dim fld As Field
   Dim varData As Variant
   Dim rs As Recordset
   Dim intFileNum As Integer

   'set recordset on table or query
   Set rs = CurrentDb.OpenRecordset(strTable, dbOpenSnapshot)

   'get file handle and open for output
   intFileNum = FreeFile()
   Open strExportFile For Output As #intFileNum

   If blnHeader Then
      'output the header row if requested
      varData = ""
      For Each fld In rs.Fields   'traverse the fields collection
         varData = varData & fld.Name & strDelimiter
      Next

      'remove extra last strDelimiter
      varData = Left(varData, Len(varData) - 1)

      'write out the header row
      Print #intFileNum, varData
   End If

   'now your data
   Do While Not rs.EOF
      varData = ""
      'concatenate the data row
      For Each fld In rs.Fields
         varData = varData & fld.Value & strDelimiter
      Next

      'remove extra last strDelimiter
      varData = Left(varData, Len(varData) - 1)

      'write out data row
      Print #intFileNum, varData

      rs.MoveNext
   Loop

   Close #intFileNum
   rs.Close
   Set rs = Nothing
End Sub
--
Joe Fallon
Access MVP


Quote:
> I want to read a recordset and write it to a text file.
> But, I want this routine to run several times during the
> day, so I want the text file to be appended to....not
> overwritten. I have to use Access '97. I don;t think
> TransferDatabase has an append...can I write a VBA
> routine similar to this...

> OPEN "C:\test.txt" FOR APPEND AS #1
> PRINT #1, text1.text
> close #1

> Thanks Ed



Mon, 11 Apr 2005 00:45:31 GMT  
 appending to a text file
Thanks guys...got it
Quote:
>-----Original Message-----
>You are correct about the TransferText not having an
append feature.
>I also think you are correct about your sample code.

>================================================
>Here is a sample of some general export code:

>Public Sub ExportDelim(strTable As String, strExportFile
As String,
>strDelimiter As String, Optional blnHeader As Boolean)

>   'strTable is the table or query name
>   'strExportFile is the full path and name of file to
export to
>   'strDelimiter is the field deliminator to use like Chr
(9) for tab or
>Chr(44) for comma or ??

>   Dim fld As Field
>   Dim varData As Variant
>   Dim rs As Recordset
>   Dim intFileNum As Integer

>   'set recordset on table or query
>   Set rs = CurrentDb.OpenRecordset(strTable,
dbOpenSnapshot)

>   'get file handle and open for output
>   intFileNum = FreeFile()
>   Open strExportFile For Output As #intFileNum

>   If blnHeader Then
>      'output the header row if requested
>      varData = ""
>      For Each fld In rs.Fields   'traverse the fields
collection
>         varData = varData & fld.Name & strDelimiter
>      Next

>      'remove extra last strDelimiter
>      varData = Left(varData, Len(varData) - 1)

>      'write out the header row
>      Print #intFileNum, varData
>   End If

>   'now your data
>   Do While Not rs.EOF
>      varData = ""
>      'concatenate the data row
>      For Each fld In rs.Fields
>         varData = varData & fld.Value & strDelimiter
>      Next

>      'remove extra last strDelimiter
>      varData = Left(varData, Len(varData) - 1)

>      'write out data row
>      Print #intFileNum, varData

>      rs.MoveNext
>   Loop

>   Close #intFileNum
>   rs.Close
>   Set rs = Nothing
>End Sub
>--
>Joe Fallon
>Access MVP



>> I want to read a recordset and write it to a text file.
>> But, I want this routine to run several times during the
>> day, so I want the text file to be appended to....not
>> overwritten. I have to use Access '97. I don;t think
>> TransferDatabase has an append...can I write a VBA
>> routine similar to this...

>> OPEN "C:\test.txt" FOR APPEND AS #1
>> PRINT #1, text1.text
>> close #1

>> Thanks Ed

>.



Mon, 11 Apr 2005 06:18:11 GMT  
 appending to a text file


Quote:
> I want to read a recordset and write it to a text file.
> But, I want this routine to run several times during the
> day, so I want the text file to be appended to....not
> overwritten. I have to use Access '97. I don;t think
> TransferDatabase has an append...can I write a VBA
> routine similar to this...

> OPEN "C:\test.txt" FOR APPEND AS #1
> PRINT #1, text1.text
> close #1

TextExport class from http://www.users.cloud9.net/~dfurman/code.htm will
let you create a delimited text file directly from a recordset and append
to the file as necessary. The code would look similar to this:

Dim TE As TextExport

Set TE = New TextExport

With TE
  .ExportSource = rsRecordset
  .AppendToFile = True
  .ExportFilename = "c:\temp\file.txt"
  .Export
End With

--
(remove a 9 to reply by email)



Mon, 11 Apr 2005 10:18:47 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. append line to text file

2. Appending to a text file

3. Appending to Large Text Files 3.0 Users

4. (Help Request) Appending to Large Text Files

5. Help appending to a text file using vbscript

6. Appending to a text file

7. Append one huge text file to another-- most efficient way?

8. How can I append a line of text to the start of a 100MB text file

9. appending text to a non-text file

10. appending text to output text file

11. Import/Append Text Files

12. Appending two (or more) text files

 

 
Powered by phpBB® Forum Software