Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Creating a text file

Posted on 2003-02-19
6
Medium Priority
?
250 Views
Last Modified: 2012-08-14
I would like to be able to create a .txt file using data from my database but am unsure how to go about it.

I would like to get a phone number from one table field and a message from another field and display them on a text file like so:

"number1", "message"
"number2", "message"...

& therefore repeating through all the number records until the last. Any help will be greatful.
0
Comment
Question by:hbkmunroe
6 Comments
 
LVL 3

Expert Comment

by:LordThlan
ID: 7982419
Create a query that gathers the info you want, then right click on the query and choose the Export option.  Follow the prompts and choose the file format you want (text, Excel, Access, etc.)
0
 
LVL 1

Accepted Solution

by:
FredPerry69 earned 150 total points
ID: 7982446
Are you intending to do this in code?

If so, simply create a query (make sure you save and close it), then do an export on the query. To extend LordThlan response, the export code for the above would be:

DoCmd.TransferText acExportFixed, [LAYOUT], [Query name], [export name and full path, with .txt extension]

The layout is only required if you have a set layout, otherwise leave blank for general. If you want it exported in csv format, change the first option to acExportDelim
0
 

Expert Comment

by:Lynchurian_Velvet
ID: 7982560
This method is more manual and a little more clunky, but I've done it like this:

Open "c:\SomeFile.txt" For Output As #1    ' Open file for output.

'Use a loop to loop through your table or data
        Print #1, number1; Spc(5); message1
        Print #1,
        Print #1, number2; Spc(5); message2
        Print #1,
Close #1

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:hbkmunroe
ID: 7987974
Ok, have been trying
DoCmd.TransferText acExportFixed, [LAYOUT], [Query name], [export name and full path, with .txt extension]
To launch the txt file but it keeps saying about a specification name argument??

"An action or question requires a specification name argument"

Afraid I don't know what to do here. I have a query and all made and have exported it manually but I need it to work for an 'on click' event.
0
 

Author Comment

by:hbkmunroe
ID: 7988010
Ok, have been trying
DoCmd.TransferText acExportFixed, [LAYOUT], [Query name], [export name and full path, with .txt extension]
To launch the txt file but it keeps saying about a specification name argument??

"An action or question requires a specification name argument"

Afraid I don't know what to do here. I have a query and all made and have exported it manually but I need it to work for an 'on click' event.
0
 
LVL 1

Expert Comment

by:FredPerry69
ID: 7992661
ok, if you've typed it in like that directly, it won't work. Firstly,if you have an export layout (i.e. if you run a manual export, is there a spec that you select that has all the column layouts pre-saved - if so copy the name of that spec) store this name in a string ans type it like so:

DoCmd.TransferText acExportFixed, "Standard Export Layout"

if you don't have one, just leave it blank:

DoCmd.TransferText acExportFixed, ,

Then the query. The DoCmd function will only export pre-made query's or tables. so say your query is called "Select All Active Users" it should look like:

DoCmd.TransferText acExportFixed, "Standard Export Layout", "Select All Active Users",

Alternatively, I'm looking in to exporting with a query, but the best you could do is use querydef to create a query using your sql, and then enter that query into the above as stated. write back if you want this and need it clarified.

finally you post the output name. store that in a string, like 'path', and have the fullname. say that your output name is stored in a string called 'OPName', then your path would look like this:

path = "c:\My Documents\FolderX\" & OPName &".txt"

then put this in the final section, like so:

DoCmd.TransferText acExportFixed, "Standard Export Layout", "Select All Active Users", path

Hope this helps. If you need further information, just post it and i'll answer. Sorry if this isn't what you wanted.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Implementing simple internal controls in the Microsoft Access application.
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

580 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