469,646 Members | 1,496 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,646 developers. It's quick & easy.

Delete existing before running Open "c:\MyFile.txt" For Output As #1 ?

MLH
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?
Dec 13 '05 #1
4 8966
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")

--

Danny J. Lesandrini
dl*********@hotmail.com
http://amazecreations.com/datafast
"MLH" <CR**@NorthState.net> wrote in message news:as********************************@4ax.com...
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?

Dec 13 '05 #2
MLH
On Tue, 13 Dec 2005 11:01:36 -0700, "Danny J. Lesandrini"
<dl*********@hotmail.com> wrote:
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.
Dec 13 '05 #3
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

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"MLH" <CR**@NorthState.net> wrote in message
news:as********************************@4ax.com...
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?

Dec 13 '05 #4
MLH
Good point. I agree.
xxxxxxxxxxxxxxxxxxxxxxxxxx
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


Dec 14 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by John Appleby | last post: by
1 post views Thread by John Layton | last post: by
3 posts views Thread by John Torville | last post: by
5 posts views Thread by John Nagle | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.