Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating "File already exists, overwrite?" with CommonDialog1 1

Status
Not open for further replies.

Svanholm

Programmer
Jul 11, 2007
31
0
0
DK
Hi clever people

I am a beginnner working in VB5, struggling with open, save, and save as procedures. I have progressed well. They seem to work as I wish, mostly. I use CommonDialog1 and it is nice but a few things puzzles me.

First of all:
I want my procedure to alert with MsgBox that user is saving a filename that already exists, you know the classic windows: "File Already exists, overwrite?"-message.

How do I do that with CommonDialog1. A simplified version of my code is this:
-------

Public Sub SaveAS()

Dim FileNum As Integer
Dim FileName As String
Dim Address As String

txtAddress.Text = Address

FileNum = FreeFile

'open CommonDialog1 in "save as-mode"
CommonDialog1.Action = 2

FileName = CommonDialog1.FileName

Open FileName For Output As FileNum

Write #FileNum, Address

Close FileNum

End Sub

-------

What do I code? and where do I insert the code? Is there a better approach to my needs?

Secondly:
I wonder how do you control/code the Save button and the cancel button of the CommonDialog1?
 
CommonDialog1.CancelError = True 'handles Cancel

On Error GoTo ErrHandler
CommonDialog1.Flags = cdlOFNHideReadOnly Or cdlOFNOverwritePrompt 'Prompts if file exists

CommonDialog1.ShowSave 'Opens in Save mode

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Hi Error7

Thx a bunch. Am gonna try it out.

Knew about the .ShowSave cause it is the same as .Action = 2
but I did not know about the .Flags. Seems like that is what i look for.

About the CancelError property: This does not mean that .False controls the "Save Button", does it?

Totally agree with your motto :)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top