Overwrite or Create copy of file when saving?

Posted on 2009-04-30
Last Modified: 2012-05-06
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.


dim outputfile as string

dim destinationpath as string

destnationpath = "c:\files"

outputfile = destpath & Forms!frmtabs!txtFilename & ".PDF"

Open in new window

Question by:GWitek
    LVL 3

    Accepted Solution

    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
    LVL 3

    Author Comment

    Will one of these be better or worse then the other?
    What does the ">2" do in the first example?
    LVL 3

    Author Comment

    I'm revisiting this project.
    Any suggestions on the above questions?
    LVL 3

    Author Closing Comment

    Works awesome!


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
    Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
    In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
    Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now