K
ksteger
I am trying to created a file to be submitted for Auto Drafts. With
this file there are 5 different fixed length record formats that will
be included in the file (File Header, Batch Header, Entry Detail, Batch
Control and File Control) I have created tables within my Access
Database to hold each type of format and already got the code to export
each table to a text file. Now I am trying to read in 4 of the 5 (which
I got the reading in part working) and then append it to the file with
the file header record in it in the appropriate order.
Everything I have tried reads in the data fine, but when I try to
append the data it overwrites the data already in the file and doesn't
append. Here is the code I have so far. Can anyone please tell me what
I need to do to get it to append and not overwrite.
Dim strFileName As String
Dim strOutputName As String
Dim strBuffer As String
Dim intFileNo As Integer
'check if autodraftfileheader.txt exists...if so delete
If Len(Dir("C:\GWB\AutoDraftFileHeader.txt")) > 0 Then
Kill "C:\GWB\AutoDraftFileHeader.txt"
End If
'export file header record to autodraftfileheader.txt
DoCmd.TransferText acExportFixed, "AutoDraftFileHeader Export
Specification", "AutoDraftFileHeader",
"C:\GWB\AutoDraftFileHeader.txt", False, ""
'check if AutoDraftBatchHeader.txt exists...if so delete
If Len(Dir("C:\GWB\AutoDraftBatchHeader.txt")) > 0 Then
Kill "C:\GWB\AutoDraftBatchHeader.txt"
End If
'export batch header record into AutoDraftBatchHeader.txt
DoCmd.TransferText acExportFixed, "AutoDraftBatchHeader Export
Specification", "AutoDraftBatchHeader",
"C:\GWB\AutoDraftBatchHeader.txt", False, ""
'check if autodraftfileheader.txt exists...if so delete
If Len(Dir("C:\GWB\GWBAutoDraftFile.txt")) > 0 Then
Kill "C:\GWB\GWBAutoDraftFile.txt"
End If
' Rename the file
Name "C:\GWB\AutoDraftFileHeader.txt" As
"C:\GWB\GWBAutoDraftFile.txt"
'set path of output file
strOutputName = "C:\GWB\GWBAutoDraftFile.txt"
'Set path of file to be read in
strFileName = "C:\GWB\AutoDraftBatchHeader.txt"
'Read in AutoDraftBatchHeader.txt
intFileNo = FreeFile()
Open strFileName For Input As #intFileNo
strBuffer = Input(LOF(intFileNo), intFileNo)
Close #intFileNo
intFileNo = FreeFile()
Open strOutputName For Random As #intFileNo
Put #intFileNo, , strBuffer
Close #intFileNo
Thanks,
-Kim
this file there are 5 different fixed length record formats that will
be included in the file (File Header, Batch Header, Entry Detail, Batch
Control and File Control) I have created tables within my Access
Database to hold each type of format and already got the code to export
each table to a text file. Now I am trying to read in 4 of the 5 (which
I got the reading in part working) and then append it to the file with
the file header record in it in the appropriate order.
Everything I have tried reads in the data fine, but when I try to
append the data it overwrites the data already in the file and doesn't
append. Here is the code I have so far. Can anyone please tell me what
I need to do to get it to append and not overwrite.
Dim strFileName As String
Dim strOutputName As String
Dim strBuffer As String
Dim intFileNo As Integer
'check if autodraftfileheader.txt exists...if so delete
If Len(Dir("C:\GWB\AutoDraftFileHeader.txt")) > 0 Then
Kill "C:\GWB\AutoDraftFileHeader.txt"
End If
'export file header record to autodraftfileheader.txt
DoCmd.TransferText acExportFixed, "AutoDraftFileHeader Export
Specification", "AutoDraftFileHeader",
"C:\GWB\AutoDraftFileHeader.txt", False, ""
'check if AutoDraftBatchHeader.txt exists...if so delete
If Len(Dir("C:\GWB\AutoDraftBatchHeader.txt")) > 0 Then
Kill "C:\GWB\AutoDraftBatchHeader.txt"
End If
'export batch header record into AutoDraftBatchHeader.txt
DoCmd.TransferText acExportFixed, "AutoDraftBatchHeader Export
Specification", "AutoDraftBatchHeader",
"C:\GWB\AutoDraftBatchHeader.txt", False, ""
'check if autodraftfileheader.txt exists...if so delete
If Len(Dir("C:\GWB\GWBAutoDraftFile.txt")) > 0 Then
Kill "C:\GWB\GWBAutoDraftFile.txt"
End If
' Rename the file
Name "C:\GWB\AutoDraftFileHeader.txt" As
"C:\GWB\GWBAutoDraftFile.txt"
'set path of output file
strOutputName = "C:\GWB\GWBAutoDraftFile.txt"
'Set path of file to be read in
strFileName = "C:\GWB\AutoDraftBatchHeader.txt"
'Read in AutoDraftBatchHeader.txt
intFileNo = FreeFile()
Open strFileName For Input As #intFileNo
strBuffer = Input(LOF(intFileNo), intFileNo)
Close #intFileNo
intFileNo = FreeFile()
Open strOutputName For Random As #intFileNo
Put #intFileNo, , strBuffer
Close #intFileNo
Thanks,
-Kim