• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 341
  • Last Modified:

Overwrite or Create copy of file when saving?

I have code that is saving my Access report as a PDF on local disk space.
Currently, when a user presses the save proposal button it overwrites any PDF that already has it's same file name.  The user does not get the option to change the file name.

I would like to add some code that checks to see if the output file name already exists and if it does, ask the user if they'd like to overwrite the file or create a copy of it.  If they choose copy it would concatenate a "copy of" to the beginning of the file (just like windows).   I've provided my variables below.

Thanks!

dim outputfile as string
dim destinationpath as string
 
destnationpath = "c:\files"
outputfile = destpath & Forms!frmtabs!txtFilename & ".PDF"

Open in new window

0
GWitek
Asked:
GWitek
  • 3
1 Solution
 
DRY_GINCommented:
you can use if (len(dir(filename))>2) then 'ask for the question
or you can use scripting dll

If  CreateObject("Scripting.FileSystemObject").FileExists(your_file) Then 'ask question
0
 
GWitekAuthor Commented:
Will one of these be better or worse then the other?
What does the ">2" do in the first example?
0
 
GWitekAuthor Commented:
I'm revisiting this project.
Any suggestions on the above questions?
Thanks,
0
 
GWitekAuthor Commented:
Works awesome!

Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now