By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,661 Members | 791 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,661 IT Pros & Developers. It's quick & easy.

export text to only one file.txt

P: n/a
I need create a macro for export to only one text file, of 3 TABLES

What is the necessary instructions (for create ONLY ONE FINAL text
file) ??

Thanks

Ramon
Oct 27 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a

Ramon Pam wrote:
I need create a macro for export to only one text file, of 3 TABLES

What is the necessary instructions (for create ONLY ONE FINAL text
file) ??

Thanks

Ramon
With a Macro? Not possible, AFAIK. With code, not too hard.
Look up Open, Write, Close, FreeFile in the help. There are examples.

Basic steps:
open the text file for input.
for each table/query
open a recordset based on the query/table
loop through the recordset, writing the fields to text. you could
create a tab-delimited file...
close recordset, go to the next
next table/query
close the textfile.

Oct 27 '06 #2

P: n/a
Sorry but i dont know programation languages

This instructions are for Access or for Visual Basic ???

In the MS Access Help file, not matches this instructions (Open,
Write, Close...)

Thanks for your cooperation

Ram
En/na pi********@hotmail.com say:
Ramon Pam wrote:
>I need create a macro for export to only one text file, of 3 TABLES

What is the necessary instructions (for create ONLY ONE FINAL text
file) ??

Thanks

Ramon

With a Macro? Not possible, AFAIK. With code, not too hard.
Look up Open, Write, Close, FreeFile in the help. There are examples.

Basic steps:
open the text file for input.
for each table/query
open a recordset based on the query/table
loop through the recordset, writing the fields to text. you could
create a tab-delimited file...
close recordset, go to the next
next table/query
close the textfile.
Oct 27 '06 #3

P: n/a
Yes. You can't do it with a macro. you could either output them all
to the same textfile using VB or you could output them all separately
with a macro and then use a DOS command to append them all to the same
file.

Here's my hacked together solution...

Option Compare Database
Option Explicit

Public Sub WriteToFile(ByVal strFile As String)
Dim intFileNo As Integer
Dim intCounter As Integer
Dim intFieldNo As Integer

Dim arrQueries(1 To 3) As String
Dim rs As DAO.Recordset
Dim strLine As String

'--SPECIFY THE QUERIES TO APPEND TO THE TEXT FILE
arrQueries(1) = "qryBrentwood"
arrQueries(2) = "qryDickson"
arrQueries(3) = "qryFranklin"

intFileNo = FreeFile
Open "C:\Cities.txt" For Output As #intFileNo
For intCounter = 1 To 3
Debug.Print
Print #intFileNo, vbCrLf
Debug.Print arrQueries(intCounter)
Print #intFileNo, arrQueries(intCounter)
Debug.Print "----------------------"
Print #intFileNo, "----------------------"

Set rs =
DBEngine(0)(0).QueryDefs(arrQueries(intCounter)).O penRecordset

Do Until rs.EOF
'--collect data from fields into a tab delimited string...
(GetString looks good here!!)
For intFieldNo = 0 To rs.Fields.Count - 1
If intFieldNo = 0 Then
strLine = rs.Fields(intFieldNo)
Else
strLine = strLine & vbTab & rs.Fields(intFieldNo)
End If
Next intFieldNo
'--Write result to file
Debug.Print strLine
Print #intFileNo, strLine
rs.MoveNext
Loop
rs.Close
Next intCounter

Set rs = Nothing
Close #intFileNo
End Sub

Oct 29 '06 #4

P: n/a
Ramon Pam <rp*****@gmail.comwrote in news:eh**********@news.ya.com:
I need create a macro for export to only one text file, of 3 TABLES

What is the necessary instructions (for create ONLY ONE FINAL text
file) ??

Thanks

Ramon
Perhaps you could use a Union Query on the three tables, then look at
TransferText in Help.

Cheers,
Alan Carpenter
Oct 29 '06 #5

P: n/a

Alan Carpenter wrote:
Ramon Pam <rp*****@gmail.comwrote in news:eh**********@news.ya.com:
I need create a macro for export to only one text file, of 3 TABLES

What is the necessary instructions (for create ONLY ONE FINAL text
file) ??

Thanks

Ramon

Perhaps you could use a Union Query on the three tables, then look at
TransferText in Help.

Cheers,
Alan Carpenter

Just as long as they're union-compatible sets...

Oct 30 '06 #6

P: n/a
Why not just export them to three text files and then issue a DOS command of
Copy txtFile1 + txtFile2 + txtFile3 txtFileFour.
TxtFileFour will then the have the contents of the first three files.
No programming or SQL involved.
"Ramon Pam" <rp*****@gmail.comwrote in message
news:eh**********@news.ya.com...
>I need create a macro for export to only one text file, of 3 TABLES

What is the necessary instructions (for create ONLY ONE FINAL text
file) ??

Thanks

Ramon


Oct 30 '06 #7

P: n/a


Thanks

Is easy and running

Many thanks
En/na Kc-Mass ha escrit:
Why not just export them to three text files and then issue a DOS command of
Copy txtFile1 + txtFile2 + txtFile3 txtFileFour.
TxtFileFour will then the have the contents of the first three files.
No programming or SQL involved.
"Ramon Pam" <rp*****@gmail.comwrote in message
news:eh**********@news.ya.com...
>I need create a macro for export to only one text file, of 3 TABLES

What is the necessary instructions (for create ONLY ONE FINAL text
file) ??

Thanks

Ramon


Oct 30 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.