Solved

Macro for export to txt file

Posted on 2003-12-06
3
2,636 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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

706 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now