create text file with header record 
Author Message
 create text file with header record

I have created a query to append to a table, written vb to export the
table to a fixed width text file.  Now I need to figure out how to
1) create the header record which includes a count of the detail records
(I'm thinking a counter in a loop)
2) -insert- (not append) this header in the first line of the text file
3) use access vb to ftp the header/detail file to the recipient (anyone
doing anything like this?)

I am at a loss as to how to do these steps.  Thank you for any and all
hints/suggestions/links provided.

CAS



Sun, 30 Jan 2005 12:35:43 GMT  
 create text file with header record
Simple way to program it:
1. Write the query out to a temp file.
2. Create the header string.
3. Open the real file, and write the header plus each line from the temp
file.

DoCmd.TransferText acExportDelim, , "MyQuery", _
    strPath & strFileTemp, False

'Add the Header, and write to the real file.
Open strPath & strFileTemp For Input As #1
Open strPath & strFile For Output As #2
Print #2, strHeader
Do While Not EOF(1) ' Loop until end of file.
    Line Input #1, strTmp
    Print #2, strTmp
Loop
Close #2
Close #1

'Delete the temp file.
Kill strPath & strFileTemp

--
Allen Browne - Microsoft MVP (Most Valuable Professional)
Allen Browne's Database And Training - Perth, Western Australia.
Tips for MS Access users - http://allenbrowne.com
Reply to the newsgroup. (Email address has spurious "_SpamTrap")


Quote:
> I have created a query to append to a table, written vb to export the
> table to a fixed width text file.  Now I need to figure out how to
> 1) create the header record which includes a count of the detail records
> (I'm thinking a counter in a loop)
> 2) -insert- (not append) this header in the first line of the text file
> 3) use access vb to ftp the header/detail file to the recipient (anyone
> doing anything like this?)

> I am at a loss as to how to do these steps.  Thank you for any and all
> hints/suggestions/links provided.

> CAS



Sun, 30 Jan 2005 14:27:34 GMT  
 create text file with header record
Alternatively, you could write a dummy header record before
writing the data, open that file later in binary mode for
modification, and modify the count in that dummy record.
Allen's method is simpler, perhaps, but this approach would
be faster if you have very many records.

I don't think there's a binary mode if you use the
FileSystemObject. I don't use it, anyway, except for demos,
because it requires the scripting runtime which many system
adminstrators disable, or search out and destroy, as a
security measure.


message

Quote:
> Simple way to program it:
> 1. Write the query out to a temp file.
> 2. Create the header string.
> 3. Open the real file, and write the header plus each line
from the temp
> file.

> DoCmd.TransferText acExportDelim, , "MyQuery", _
>     strPath & strFileTemp, False

> 'Add the Header, and write to the real file.
> Open strPath & strFileTemp For Input As #1
> Open strPath & strFile For Output As #2
> Print #2, strHeader
> Do While Not EOF(1) ' Loop until end of file.
>     Line Input #1, strTmp
>     Print #2, strTmp
> Loop
> Close #2
> Close #1

> 'Delete the temp file.
> Kill strPath & strFileTemp

> --
> Allen Browne - Microsoft MVP (Most Valuable Professional)
> Allen Browne's Database And Training - Perth, Western
Australia.
> Tips for MS Access users - http://allenbrowne.com
> Reply to the newsgroup. (Email address has spurious
"_SpamTrap")



> > I have created a query to append to a table, written vb
to export the
> > table to a fixed width text file.  Now I need to figure
out how to
> > 1) create the header record which includes a count of
the detail records
> > (I'm thinking a counter in a loop)
> > 2) -insert- (not append) this header in the first line
of the text file
> > 3) use access vb to ftp the header/detail file to the
recipient (anyone
> > doing anything like this?)

> > I am at a loss as to how to do these steps.  Thank you
for any and all
> > hints/suggestions/links provided.

> > CAS



Mon, 31 Jan 2005 06:05:48 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Q: SQL to import from text file - ignores first (non-header) record

2. Help creating DB records from text files.

3. Text file records comparaison against a Master text file

4. Text file records comparaison against a Master text file

5. import text with VBA -Header Record?

6. lost text record (header)

7. Creating UTF8 file without the Byte Order Mark header

8. need a vbscript to create a file type under MIME Map button of HTTP headers tab

9. Creating and exporting unique files based on group headers

10. How to gain access to the JPEG file header, changing text captions

11. Creating word Macro to copy text and create new files from existing one

12. Editing text file to create data file.

 

 
Powered by phpBB® Forum Software