Solved

Macro for export to txt file

Posted on 2003-12-06
3
2,845 Views
Last Modified: 2012-06-21
I need to automate the process of writing the contents of a Table to a comma delimited text file.  I can use the menu system of Access to do this, but I cannot determine how to do this via a macro or module?  I have to do this several times a week, so automating the
steps would be a time saver.  I am importing and exporting data between two programs.

0
Comment
Question by:dastaub
3 Comments
 
LVL 5

Accepted Solution

by:
peterpuscas earned 500 total points
ID: 9891201
To export a table into a text file:
from macros:

New

in the first line put
Macro Name         Condition            Action
--------------------  ------------------  ----------------------
macro_export                                TransferText  


At the bottom:
Transfer Type              Export Delimited
Specification Name                                    
Table Name                 YourTableName
File Name                    C:\Folder\file.txt     -> full path to your text file
Has Fields Names         Yes
HTML Table Name                                    

Save the macro with the name macro_export

You may run this mcro directly or from a form:

Private Sub Command0_Click()
  DoCmd.RunMacro "macro_export"
End Sub

The same for import except
Transfer Type              Import Delimited

You could also use linked tables if you have access from one mdb to another.


0
 
LVL 18

Expert Comment

by:bonjour-aut
ID: 9891741
Please be aware, that commas in your field may cause trouble
peterpuscas method will work

alternatively you can do in VBA
a completely VBA based method could include checking the content of your fields, or you dissalow putting in commas by tablefield definitions.

the altenata VBA syntax is

DoCmd.OutputTo acTable[, "nameoftable",axText,"path&NameofTargetfile"

so place this to some command button:

Sub nameofcommandbutton_Click
DoCmd.OutputTo acTable[, "nameoftable",axText,"path&NameofTargetfile"
End Sub

Regards, Franz
0
 
LVL 4

Expert Comment

by:MobileOakAI
ID: 9892521
"I have to do this several times a week"

Part of answer is platform and tools/versions, and who runs what. I had simliar situation long ago.

I began with running access from command line. This enables two features. With the right OS (I even used NT server) the command can be placed in a separate command file. That command file then can be run easily at will or on a schedule. Such as daily.

The other thing it gives is the option to have an access process run by name. Inside access associate that name with a few commands. A small set such as open, run, close, exit. see above. Much is easily accessible under access help and pick lists etc.

Once successful with that, a further option comes to mind. Inside the dos command file can be placed a few others, for making a backup copy of the test files and a log to track other things such as for run time and outcome (success indicator).
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question