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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

export a calculated value to a textfile or a table? 1

Status
Not open for further replies.

frontside

Technical User
Sep 26, 2002
85
SE
I have a report that does a lot of code during the format(detail)of the report. I would like to move this value(that the code gets) to either a textfile or a table?
the data is just numbers like:
3
-6
8
11
0

The result I´m looking for is a table containing these numbers or a textfile(like 3;-6;8;11;0)filled by all those calculations that the code does(every line).
 
Hi,
Here is a bit of code that you can modify to write things to an external text file. This code will only write one line to the text file, but if you want multiple lines, simply put the "write" statement inside a loop.

dim strList as String
'loop through calculations here
' assign the values, e.g., "3", "-6", etc. to strList
' example: strList = strList & strNewValue
Open "c:\List.txt" For Output As #1
Write #1, strList
Close #1


HTH, [pc2]
Randy Smith
California Teachers Association
 
Thanks for your help,
Exchanging the output for append did the trick on listing all numbers in the file.
like this:
Open "c:\List.txt" For Output As #1
Open "c:\List.txt" For Append As #1


One small little question left! how do I delete the file or the content of the file everytime I run the report? My thought was to find a code that deletes the file "on open report"?
Any ideas?

 
Hi,
There are a few possibilities for you in Access 2000. In case you want to save all the original files, you can simply create a custom filename to open each day. Here is the code to append the current date to a filename:

Dim strFileName As String
'it is necessary to use "DatePart" because "Date"
' would return a value that includes slash marks,
' which is interpreted by VB/VBA to be a folder name
strFileName = "c:\TEST" & DatePart("m", Date) & DatePart("dd", Date) & DatePart("yyyy", Date) & ".txt"
Open strFileName For Output As #1


It isn't so straightforward to delete files in Access. It will be necessary to declare a FileSystemObject. Here is the code:
[/b]Dim fso As Object, fsoFile As Object
Set fso = CreateObject("Scripting.FileSystemObject")

Set fsoFile = fso.GetFile("c:\TEST" & DatePart("m", Date) & DatePart ("dd", Date) & DatePart("yyyy", Date) & ".txt")
fsoFile.Delete [/b]



HTH, [pc2]
Randy Smith
California Teachers Association
 
Hi,
I have used this info to create an FAQ on the topic. You can find it at: faq703-3767


HTH, [pc2]
Randy Smith
California Teachers Association
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top