Click to See Complete Forum and Search --> : Copying data from one txt file to another


mp_direct
11-05-2005, 01:08 PM
Hi All,

My program is a questionnair where the user simply enters data like Title, Firstname, Surname etc. Once the user clicks on SAVE it outputs the data to a txt file.

The way it should work is each time a user clicks on SAVE, if the file "C:\Test1.txt" already exists, the file name is changed by inserting the SYS data/time, and a new text file is created "Test1.txt", which has all the previous data plus the new data just inputted by the user i.e. the most up-to-date version file.

The problem i am having is if the file exists and after it has renamed the file with SYS DATE/TIME, when creating the new "Test1.txt" file will ALL THE PREVIOUS data is lost and it simply displays the new data the user had just inputted. :confused:

If retval = fileName Then
MsgBox "file already exists", vbCritical
Name "c:\Test1.txt" As "c:\Test1_OLD_" & Format(Now, "yyyy-mm-dd HhNn") & ".txt"

End If

Open "C:\Test1.txt" For Append As #1
Write #1, txtTitle, txtFirstname, txtSurname

Close #1


Any comments would be appreciated.

mstraf
11-05-2005, 03:28 PM
if you rename the file, the original file is lost and thus there is nothing to append to.
Use CopyFile instead of Name
But sincerely, I do not see any reason to keep an old version of the file if you are just appending data to it. The previous file is just the new one less the last line...
Marco