Export to text help.

LennyNero

Registered User.
Local time
Today, 06:40
Joined
Jul 31, 2008
Messages
18
Hi all,

I need to export data from a query to a text file.
Hope you can help me with a simple way of doing it.
Im going to import data from a access database to a new table, from that table i need to export data to a fixed width, and name the file with some of the data.
Some of the fields must be filled with "0" or spaces with the export data aligned to right. All record in database will have 125 chars in each exported text line.
The file must be named like some of the fields like date and some codes that are on the same table.
I want to have a button that exports to the txt file.
Can someone help me with the basics please.

Thanks in advance
Luis
 
Forgot one thing
The first and last line of the text file come from different tables like a header and footer.
 
Hi again,

I know have for the header:

Public Function CreateTextFile()

Dim strTIPOLINHAH As String * 2
Dim strFILERH1 As String * 1
Dim strCODENTIDA As String * 9
Dim strCODTIPENT As String * 8
Dim strNUMFACT As String * 8
Dim strANOMESFACT As String * 6
Dim strDATAENVIO As String * 8
Dim strCODREJEICAO As String * 2
Dim strFILERH2 As String * 81
Dim mydb As DAO.Database, myset As DAO.Recordset
Dim intFile As Integer
Set mydb = CurrentDb()
Set myset = mydb.OpenRecordset("header", dbOpenTable)

'myset.Index = "IDHEADER" 'Orders table must have primary key.
intFile = FreeFile
Open "C:\Users\luis.palha\TESTE7.txt" For Output As intFile

myset.MoveFirst
Do Until myset.EOF
LSet strTIPOLINHAH = myset![TIPOLINHAH] 'Field name in brackets
RSet strFILERH1 = Format(myset![FILERH1], "0")
RSet strCODENTIDA = Format(myset![CODENTIDA], "000000000")
RSet strCODTIPENT = Format(myset![CODTIPENT], "00000000")
RSet strNUMFACT = Format(myset![NUMFACT], "00000000")
RSet strANOMESFACT = Format(myset![ANOMESFACT], "yyyymm")
RSet strDATAENVIO = Format(myset![DATAENVIO], "yyyymmdd")
RSet strCODREJEICAO = Format(myset![CODREJEICAO], "00")
RSet strFILERH2 = myset![FILERH2]

Print #intFile, strTIPOLINHAH & strFILERH1 & strCODENTIDA & strCODTIPENT & strNUMFACT & strANOMESFACT & strDATAENVIO & strCODREJEICAO & strFILERH2
myset.MoveNext
Loop
Close intFile
myset.Close
mydb.Close
MsgBox "O ficheiro foi criado!"
End Function

This works and i have now the header text, i need help now to name the file like : YYYYMM_CODENTIDA_NUMBER.TXT

I also need help on some ideas how to join now header, footer and detail in one file.

Thanks,
Luis
 

Users who are viewing this thread

Back
Top Bottom