Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can Access Data be exported to Notepad?

Status
Not open for further replies.

Doraemon

IS-IT--Management
Sep 12, 2003
31
0
0
HK
I would like to export data to notepad, and wonder if it is possible. If possible, then how can I do it?

Thanks a lot in advance.
 
Hallo,

Notepad reads text files so you could write (or export) your data to a text file, then open notepad with the file you've just written.
Another option would be to open Notepad and use SendKeys to send the data character-by-character to the notepad application. This way goes horribly wrong if anything (or anyone) moves the focus away from notepad, as all your 'keys' will be sent somewhere else with potentially disasterous consequences.

- Frink
 
Yes, I want to ask if I can export data to a text file, what specifically is the coding for opening a file and then write things to it?

I want to write a module to output data together with some defined set of characters to a text file. How can I do that?

Is that the TransferTextfile can export data only? Can extra defined set characters be added in between?

Sorry for long wordings. Thanks a lot in advance.
 
TransferText can export data using a query based on a table. With all of the functions available in defining fields in a query, you can probably create the data you want in a query. Save the query and export it with the TransferText command.

If you want to do it in VB, look up the FreeFile, Open, and Print statements. They are explained pretty well in help.
 
Try something like this:

Set rstNames = CurrentDb.openrecordset("tblNames")

Open "C:\OutputFile.txt" For Output As 1

Write #1, "ID", "Surname", "Forename"
With rstNames
.MoveFirst
While not .EOF
Write #1, !ID, !Surname, !Forename
.MoveNext
Wend
.Close
End With
Close #1

You will get a file that looks something like:
"ID","Surname","Forename"
1,"Smith","John"
2,"Smith","Joan"
etc

If you don't want a comma delimited file (CSV) then try Print #1 instead of Write #1

Enjoy

Peter

 
That's exactly what I want. Thanks a lot!
 
Hallo,

May I make one suggestion?

In Peters example he uses a file number of 1. This may well work now, but file number 1 may not always be available. (may be used in another part of your code, by the operating system, by another application, who knows how Microsoft have set it up)
It is good programming practice to get a file number using FreeFile.

In the above example,
Dim intFileNo as Integer
intFileNo = FreeFile
Then replace all 1's in the Open, Write and Close statements with intFileNo


Sorry to be picky,

- Pete


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top