Access 2010:  VBA code to copy a file from one location to another.

Posted on 2012-09-20
Last Modified: 2012-09-20
A have a report that is exported from access and I need the code that will copy and rename the file to another location. Something like this maybe?

Copy FilePath1 to FilePath2
Name FilePath2 As FilePathNew
Question by:JAMES125
    LVL 33

    Expert Comment

    The 2nd one is correct, but you need to include the full path(s) and filename(s).

    Author Comment

    Well I need to copy it first, and then rename it because the original file needs to stay in the original location.  So what is the proper syntax to copy a file from one directory to another?
    LVL 119

    Accepted Solution

    if you want to copy and retain the original, use

    FileCopy FilePath1, FilePath2

    if you want to move and rename the file, use

    Name FilePath2 As FilePathNew
    LVL 33

    Expert Comment

    Oops, my mistake

    Name is used to rename/move a file, not copy it.

    The VBA for copying  a file is FileCopy.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Suggested Solutions

    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…
    I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
    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…
    In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

    755 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

    20 Experts available now in Live!

    Get 1:1 Help Now