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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Common Dialog Control SaveAs Question

Status
Not open for further replies.

atunplatino

Technical User
Mar 23, 2005
7
US
Hello I am using VB6 and am trying to use the Common Dialog control to allow my user to name a file that the program is creating. The trouble is I cannot figure out how to generate an alert to the user if they have selected a filename that is already taken and are thus about to overwrite an existing file. Can anybody help me??

Here is some of my code:
___________________________________________
cdlCommon.CancelError = False
cdlCommon.InitDir = App.Path & "\pictures\"
cdlCommon.FileName = Format(Now, "mm-dd-yyyy")
cdlCommon.Flags = cdlOFNHideReadOnly
cdlCommon.Filter = "Picture Files (*.jpg)|*.jpg|"

cdlCommon.FilterIndex = 1
cdlCommon.ShowSave

Dim newpic As String
newpic = cdlCommon.FileName

'USE FSO TO CREATE THE FILE REQUESTED ABOVE
Dim fs, A As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Set A = fs.createtextfile(newpic, True)
A.Close
_________________________________________

Again, the code is fully functional I just need to know how to generate an alert for the user if an existing file name is about to be overwritten.

Thank you very much.
-Atunplatino
 
cdlOFNOverwritePrompt


Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Specify the cdlOFNOverwritePrompt flag.

[tt]cdlCommon.Flags = cdlOFNHideReadOnly Or cdlOFNOverwritePrompt[/tt]
 
Beautiful.

Thank you much; I suspected a flag was available but could not turn up any flag listings/definitions on msdn or google.

-Atunplatino
 
Hi,

just for next time.
Once you have referenced the Common Dialog Control (in this case).
Press F2 to bring up the Object Browser.
Top Left of the screen allows you to browse for properties,methods,constants for all objects referenced in your project.

Hoping this may help.


Droopy
 
Thanks, Droops.

That is helpful information that I am a bit surprised I didn't know. I have never read a VB book, I am taught via the great Google, so I guess I miss these things.

I do appreciate the info, it will help.
-atunplatino
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top