Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Macro for export to txt file

Posted on 2003-12-06
3
Medium Priority
?
3,164 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

782 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