I think Gord wants to delete the file if it exists, not open it and
write over part of it.
So yes, you have to detect it and delete it. There are various ways to
do this, including
Open FilePath For Output As nFile
Close nFile
which just opens the file and immediately closes it, so it is zero
length and gone. This works whether the file is there or not.
You could also do
If Dir(FilePath) <> "" Then
Kill FilePath
End If
"Randy Birch" <rg************@mvps.org> wrote in message
news:_L********************@rogers.com...
| If the .Filename property is not blank, and cancelerror did not fire
(cancel
| was not pressed), then either an existing file was selected or a
filename
| was entered and the user pressed OK. All 'overwrite' does, in this
context,
| is indicate to the user that they have selected an existing file, and
it is
| eliciting confirmation that it will be OK for the code to subsequently
write
| to that file (thereby overwriting the existing data).
|
| What you do with the file after the dialog returns is completely your
| business, and yes, you have to write code to check for the existence
of the
| file if you need to be sure it exists before you access it. But with
VB's
| file methods this is not required, as they will create the file when
you
| issue an "Open filename for Random Access" ... call.
|
| If you need a FileExists method, try this:
|
http://vbnet.mvps.org/code/fileapi/fileexists.htm
|
| --
|
|
| Randy Birch
| MS MVP Visual Basic
|
http://vbnet.mvps.org/
|
|
| "Gord" <x1******@telus.net> wrote in message
| news:p6Wad.36079$663.26766@edtnps84...
| : Randy,
| :
| : Much thanks for your reply.
| :
| : I guess I'm making a different assumption about what 'Overwrite'
means in
| : this context. What I'm trying to do when saving a file with a name
of a
| : file that already exists on disk, is to completly wipe out the file
| : presently on disk. Then have the file that I'm saving, go to disk
with
| the
| : name of the file that was just erased. Right now when using the
'Open'
| : statement, if the file already exists, it is opened and the data I'm
| saving
| : only 'overwrites' the records I'm saving and leaves the rest of the
file
| : intact. (By the way, I'm saving my files as 'Random Access')
| :
| : If I need to delete the file on disk with code first, that's fine.
| However,
| : I can't believe that I have to write my own code to detect if a file
| already
| : exists so that I can go ahead and delete it, when the 'Save' common
dialog
| : obviously has this ability built in. There doesn't seem to be any
| : property/method or whatever to detect an existing file from the
common
| : dialog control even though its capable of bringing up the
'Overwrite'
| : message box?
| :
| : Thanks,
| :
| : Gord
| :
| :
| : "Randy Birch" <rg************@mvps.org> wrote in message
| : news:y9********************@rogers.com...
| : > ... and yes, the dialog does nothing to the file, it merely
provides a
| : > means
| : > of extracting a file name choice from the user. Even if it asks to
| : > overwrite
| : > or create the file if missing (with appropriate flags), the most
it will
| : > do
| : > is return to you either the filename selected, or if the user
pressed
| : > cancel. The dialog does not cause any file to be created, or
write any
| : > data
| : > to disk.
| : >
| : > --
| : >
| : >
| : > Randy Birch
| : > MS MVP Visual Basic
| : >
http://vbnet.mvps.org/
| : >
| : >
| : > "Randy Birch" <rg************@mvps.org> wrote in message
| : > news:-b********************@rogers.com...
| : > : You don't. If the user selects no, they are returned to the
dialog for
| : > : another selection or to cancel the action. You can determine if
| cancel
| : > was
| : > : selected by setting the CancelError property to true, and adding
error
| : > : trapping which will fire if cancel is selected. E.g. ..
| : > :
| : > : Private Sub Command1_Click()
| : > :
| : > : On Error Goto save_error
| : > :
| : > : With CommonDialog1
| : > : .CancelError = True
| : > : .Flags = cdlOFNExplorer Or cdlOFNFileMustExist Or
| cdlOFNLongNames
| : > : .Filter = "*.bmp|*.bmp"
| : > : .ShowSave
| : > :
| : > : If Len(.FileName) > 0 Then
| : > : 'do something with .FileName
| : > : End If
| : > :
| : > : End With
| : > :
| : > : save_exit:
| : > : Exit Sub
| : > :
| : > : save_error:
| : > : '
| : > : Resume save_exit
| : > :
| : > : End Sub
| : > :
| : > :
| : > : --
| : > :
| : > :
| : > : Randy Birch
| : > : MS MVP Visual Basic
| : > :
http://vbnet.mvps.org/
| : > :
| : > :
| : > : "Gord" <x1******@telus.net> wrote in message
| : > : news:VBHad.13032$Ia5.9690@edtnps89...
| : > : : Hello,
| : > : :
| : > : : If you set the flag for an overwrite prompt using the 'Save'
common
| : > : dialog,
| : > : : how do you read the response when the user clicks the Yes or
No in
| the
| : > : : 'overwrite' message box?
| : > : :
| : > : : Everything I've read explains about setting the flag to bring
up the
| : > : : overwrite prompt message box, but there's no explanation on
how to
| : > read
| : > : the
| : > : : response to it. It appears that clicking the Yes option
doesn't
| : > actually
| : > : : overwrite the old file, so I assume I'm meant to do that in
code,
| but
| : > of
| : > : : course I have to know what the damn response was!
| : > : :
| : > : : Thanks,
| : > : :
| : > : : Gord
| : > : :
| : > : :
| : > :
| : >
| :
| :
|