By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,461 Members | 1,108 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,461 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.