472,983 Members | 2,472 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,983 software developers and data experts.

Response to overwrite prompt?

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
Jul 17 '05 #1
5 7444
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
:
:

Jul 17 '05 #2
.... 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
: :
: :
:

Jul 17 '05 #3
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
: :
: :
:

Jul 17 '05 #4
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
: > : :
: > : :
: > :
: >
:
:

Jul 17 '05 #5
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
| : > : :
| : > : :
| : > :
| : >
| :
| :
|
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Zero | last post by:
how to Overwrite Existing Excel File without prompt and quit?
1
by: Joseff | last post by:
I have this Bitmap object declared and outputted to the browswer this way: invoiceBMP.Save(Response.OutputStream, ImageFormat.Gif); However, the result is that the existing static controls of...
0
by: S.Kartikeyan | last post by:
I have a GetDotUlsStudentFile.aspx page which is accessed by another aspx page like this. Response.Redirect("GetDotUlsStudentFile.aspx?v=mms://myserver.mydomain/courses/xyz.wmv"); In...
2
by: B-Dog | last post by:
Is there a way to make vb.net to overwrite the file when moving? Here is what I'm trying to do: If System.IO.File.Exists(dest) Then 'handle overwrite here If MessageBox.Show("Do you want...
5
by: GRB | last post by:
I'm using VB.Net 2003 to build a web page. I need to prompt the client for a name in order to save a list. I used the following code to btnSaveList.Attributes.Add("onclick", "var listname =...
2
by: b00x | last post by:
Hi, I'm trying to develop a script that I can reuse to run remote commands on multiple UNIX servers via telnet. I've tried various php scripts after googling for a good 5 or so hours, but found...
0
by: Judy | last post by:
I'm searching for some data. After getting the data from sql, i'm using stringbuilder and then i'm passing this as a binary stream. I am trying to display an Excel file of this data in a browser,...
1
by: Aere | last post by:
Hello, I'm coding a program that saves information about my patients, so i created a rich textbox for every field. (Name, Tel, etc). The program saves a .txt for each field, no matter if there is...
8
by: Joe Duchtel | last post by:
Hello - I have the following code to detemine a file name when my application is saving a file. The problem is that if the file already exists and I select the Yes button in the "Do you want to...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.