I have the below code that runs to export a text file. I have both the Pgarn01 query and the table set to Ascending order by ID. However, when the export occurs a strange thing happens. The data will display as
header record
record 5
record 6
record 7
record 8
footer record
record 1
record 2
record 3
record 4
The expected result (and how it is displayed in both the query and table) is:
header record
record 1
record 2
record 3
record 4
record 5
record 6
record 7
record 8
footer record
The header record has "000000000" as the value in the ID field and the footer record has "999999999" as the ID field value.
What is going on?
Code:
Private Sub cmdExportPgarn_Click()
Dim varHeaderNme As String
Dim varHeaderSSN As String
Dim varQueryName As String
Dim varSpecName As String
Dim varTableName As String
Dim varFileName As String
Dim varTextFile As String
Dim varHeaderDate
Dim varBankName As String
Dim varBankCode As String
Dim varNewFolder As String
Dim varFileRename As String
varBankCode = cboBankName.Column(2)
varBankName = cboBankName.Column(1)
'**********pgarn.txt
varHeaderNme = "***From: NCDOR; To: " & varBankName & "; pgarn" & varBankCode & ".txt***"
varHeaderSSN = "000000000"
varHeaderDate = Format(Date, "MM/DD/YYYY")
DoCmd.SetWarnings False
varQueryName = "Pgarn00"
DoCmd.OpenQuery varQueryName, acViewNormal
mySQL = "INSERT INTO AAtblBankExport (EntityID, FullName, GarnDate) VALUES ('" & varHeaderSSN & "', '" & varHeaderNme & "', #" & varHeaderDate & "#)"
CurrentDb.Execute mySQL, dbFailOnError
varQueryName = "Pgarn01"
DoCmd.OpenQuery varQueryName, acViewNormal
varQueryName = "PGarnFooter"
DoCmd.OpenQuery varQueryName, acViewNormal
DoCmd.SetWarnings True
varSpecName = "AAtblBankExport Export Specification"
varTextFile = "pgarn" & varBankCode & ".txt"
varFileRename = "pgarn" & varBankCode
varTableName = "AAtblBankExport"
varNewFolder = "C:\File\Archive\" & varFileRename & Format(Date, "MMDDYYYY") & ".txt"
varFileName = "C:\File\" & varTextFile
Name varFileName As varNewFolder
DoCmd.TransferText acExportFixed, varSpecName, varTableName, varFileName
End Sub