Solved

Macro for export to txt file

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

825 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