?
Solved

Creating a text file

Posted on 2003-02-19
6
Medium Priority
?
246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

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

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

762 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