Is it good programming practice to delete existing file before running
Open "c:\MyFile.txt" For Output As #1 ???
IE, I already have a file c:\MyFile.txt on disk and I launch
Open "c:\MyFile.txt" For Output As #1 ==> VBA is supposed to
overwrite whatever WAS there with the new contents - right? And
if that is true, does it matter whether I delete the existing file
prior to running the Open statement?
Danny J. Lesandrini - 13 Dec 2005 18:01 GMT
I generally like to clean up, either before a process or after it ends,
for files that are disposable. Try something like this ...
If Dir("c:\MyFile.txt") <> "" Then Kill("c:\MyFile.txt")

Signature
Danny J. Lesandrini
dlesandrini@hotmail.com
http://amazecreations.com/datafast
> Is it good programming practice to delete existing file before running
> Open "c:\MyFile.txt" For Output As #1 ???
[quoted text clipped - 4 lines]
> if that is true, does it matter whether I delete the existing file
> prior to running the Open statement?
MLH - 13 Dec 2005 18:28 GMT
>I generally like to clean up, either before a process or after it ends,
>for files that are disposable. Try something like this ...
>
> If Dir("c:\MyFile.txt") <> "" Then Kill("c:\MyFile.txt")
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Yep. That's good practice.
Douglas J. Steele - 13 Dec 2005 19:01 GMT
Opening a file As #1 isn't good programming practice!
Dim intFile As Integer
If Len(Dir("c:\MyFile.txt")) > 0 Then
Kill "c:\MyFile.txt"
End If
intFile = FreeFile()
Open "c:\MyFile.txt" For Output As #intFile

Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
> Is it good programming practice to delete existing file before running
> Open "c:\MyFile.txt" For Output As #1 ???
[quoted text clipped - 4 lines]
> if that is true, does it matter whether I delete the existing file
> prior to running the Open statement?
MLH - 14 Dec 2005 03:36 GMT
Good point. I agree.
xxxxxxxxxxxxxxxxxxxxxxxxxx
>Opening a file As #1 isn't good programming practice!
>
[quoted text clipped - 6 lines]
> intFile = FreeFile()
> Open "c:\MyFile.txt" For Output As #intFile