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.
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.
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
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.