jsanderson
MIS
I am writing a module to export the results of a query to a fixed width text file. I am using the MSKB article: as an example. The only difference that I can see is that the example is based on a table with a primary key and mine is based on a query with no primary key. I tried adding the main table's primary key as a column in the query (PaymentID) but that didn't help. Can this example be modified to work with a query or am I barking up the wrong tree? I am using this method because I have found no other way to justify the columns in the exported text file.
<code>
Option Compare Database
Public Function CreateTextFile()
Dim strPropertyNumber As String * 13
Dim strUnitNumber As String * 14
Dim strPaymentDate As String * 6
Dim strCheckNumber As String * 10
Dim strPaymentAmount As String * 8
Dim mydb As DAO.Database, myset As DAO.Recordset
Dim intFile As Integer
Set mydb = CurrentDb()
Set myset = mydb.OpenRecordset("qryTodayReport"
'should I add (, dbOpenDynaset) to the query parameters?
myset.Index = "PaymentID"
'(compile error - operation is not supported for this type of object)
intFile = FreeFile
Open "C:\windows\desktop\Today.txt" For Output As intFile
'This section puts the records from the Orders table in the text
'file.
myset.MoveFirst
Do Until myset.EOF
LSet strPropertyNumber = myset![PropertyNumber] 'Field name in brackets
LSet strUnitNumber = myset![UnitNumber] 'Field name in brackets
RSet strPaymentDate = Format(YYMMDD, myset![PaymentDate], "Short Date"
LSet strCheckNumber = myset![CheckNumber]
RSet strPaymentAmount = myset![PaymentAmount]
'Concatenate all of the variables together as in the following:
Print #intFile, strPropertyNumber & strUnitNumber & strPaymentDate & strCheckNumber & strPaymentAmount
myset.MoveNext
Loop
Close intFile
myset.Close
mydb.Close
MsgBox "Today.txt is on the desktop!"
End Function
</code>
<code>
Option Compare Database
Public Function CreateTextFile()
Dim strPropertyNumber As String * 13
Dim strUnitNumber As String * 14
Dim strPaymentDate As String * 6
Dim strCheckNumber As String * 10
Dim strPaymentAmount As String * 8
Dim mydb As DAO.Database, myset As DAO.Recordset
Dim intFile As Integer
Set mydb = CurrentDb()
Set myset = mydb.OpenRecordset("qryTodayReport"
'should I add (, dbOpenDynaset) to the query parameters?
myset.Index = "PaymentID"
'(compile error - operation is not supported for this type of object)
intFile = FreeFile
Open "C:\windows\desktop\Today.txt" For Output As intFile
'This section puts the records from the Orders table in the text
'file.
myset.MoveFirst
Do Until myset.EOF
LSet strPropertyNumber = myset![PropertyNumber] 'Field name in brackets
LSet strUnitNumber = myset![UnitNumber] 'Field name in brackets
RSet strPaymentDate = Format(YYMMDD, myset![PaymentDate], "Short Date"
LSet strCheckNumber = myset![CheckNumber]
RSet strPaymentAmount = myset![PaymentAmount]
'Concatenate all of the variables together as in the following:
Print #intFile, strPropertyNumber & strUnitNumber & strPaymentDate & strCheckNumber & strPaymentAmount
myset.MoveNext
Loop
Close intFile
myset.Close
mydb.Close
MsgBox "Today.txt is on the desktop!"
End Function
</code>