Results 1 to 11 of 11
  1. #1
    kdbailey is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2012
    Posts
    228

    Faster way to copy a file than FileCopy()


    Is there a faster, more efficient way to copy a file to a new location? I have some rather small .jpg's that are moved upon request, but it seems to be taking 20-30 seconds each while using the FileCopy() method.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Can use API code but doubt it will be much faster than the intrinsic VBA FileCopy().

    Bing: API file copy

    http://www.freevbcode.com/ShowCode.asp?ID=498
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    kdbailey is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2012
    Posts
    228
    Thanks, I will give it a try and see if there's a noticeable difference.

  4. #4
    kdbailey is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2012
    Posts
    228
    Just thought I'd let you know I was able to get around to trying this method. Copy time reduced from ~25 seconds down to less than 1 second.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Really, that is interesting. Perhaps I should revisit my code. Glad it worked for you.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    kdbailey is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2012
    Posts
    228
    I performed one immediately after the other, same file. The difference was staggering. Not sure if this is applicable to all file types, but it sure is faster regarding jpegs

  7. #7
    kdbailey is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    228
    Does this method work in Excel? I'm trying to run the exact same code within excel to move a couple files, but it won't copy the file over.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Yes, it works.

    The code must be in a general code module.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    kdbailey is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    228
    It is in a regular module in my personal workbook.

    Code:
    Public Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
    And in a function later...

    Code:
    If dir("S:\Shared\Quality\PQG\Kris\Locations Reports\Final Summaries\Test", vbDirectory) = "" Then MkDir "S:\Shared\Quality\PQG\Kris\Locations Reports\Final Summaries\Test"
    CopyFile "S:\Shared\Quality\PQG\Kris\Locations Reports\Background\Affected.xlsx", "S:\Shared\Quality\PQG\Kris\Locations Reports\Final Summaries\Test\Affected - " & Format(Now(), "m/d/yyyy") & ".xlsx", False
    CopyFile "S:\Shared\Quality\PQG\Kris\Locations Reports\Background\Affected Locations.xlsx", "S:\Shared\Quality\PQG\Kris\Locations Reports\Final Summaries\Test\Locations Report - Test - " & Format(Now(), "m/d/yyyy") & ".xlsx", False
    Is there a reference library I need for this to run?

  10. #10
    kdbailey is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    228
    Figured it out, had to do with the title of the new file location. Cannot include the character "/".

  11. #11
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    As an alternative to using an API, I have had pretty good results referencing the Microsoft Scripting Runtime
    https://www.accessforums.net/access/...tml#post287123

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 03-18-2014, 05:16 PM
  2. FileCopy
    By thescottsman92 in forum Access
    Replies: 1
    Last Post: 09-02-2013, 04:35 PM
  3. FileCopy Funtion
    By dccjr in forum Programming
    Replies: 2
    Last Post: 04-18-2013, 09:04 PM
  4. How to copy a file from one folder to another in vba
    By pkstormy in forum Code Repository
    Replies: 2
    Last Post: 09-20-2012, 05:32 PM
  5. Replies: 0
    Last Post: 12-03-2010, 02:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums