Results 1 to 9 of 9
  1. #1
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253

    Need help with fso.copyfile

    I am trying to learn how to use the FileSystemObject methods. I have the following code on a button on a form and I am trying to make it copy a file on click event. I have tried different databases and locations for the sources and destinations but cannot get it to copy. Could someone please steer me in the right direction. I have been reading a book to try and figure this out. I have read through many threads on here as well and have not found anything like what I am having difficulty with. Thank you in advance for your time and knowledge.



    Code:
    Option Compare Database
    Option Explicit
    
    Dim fso As Scripting.FileSystemObject
    Set fso = New Scripting.FileSystemObject
        
    Private Sub btnDBCopy_Click()
        
        'Copy current database to local computer
        fso.CopyFile "C:\Access 2010 working files\C_GXPS Hydrostatic Library.accdb", "C:\Test\", True
        
    End Sub

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Try moving the DIM and SET lines below the
    Private Sub btnDBCopy_Click() line.


    Did you get an error message??

  3. #3
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    I had the DIM and SET within the Sub and it was the same. I don't receive any error messages which is why I came here for help. I would feel better if there was an error that I could try to fix but nothing happens that I can tell.

  4. #4
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    I thought it might have something to do with the references. Here is a screen shot of the ones I have active for this DB.

    Click image for larger version. 

Name:	Ref.JPG 
Views:	7 
Size:	49.5 KB 
ID:	26144

  5. #5
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    I changed a couple of things and it worked:
    - instead of typing out the path etc I used "Currentdb.Name" - not sure if this makes any difference, probably not
    - I changed the "To" folder to my docs - are you sure you can save files to "C:\Test"?

  6. #6
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    Could you share the code you used please so I can compare it to what I have tried

  7. #7
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Code:
        Dim fso As Scripting.FileSystemObject
        Set fso = New Scripting.FileSystemObject
        fso.CopyFile CurrentDb.Name, "H:\", True

  8. #8
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    I figured out what happened. I feel really dumb now for wasting everyones time. I realized that I changed the name of the button on the form due to using a keyword. so it wasn't trying to run the code at all. I fixed the different names and got it to work. Again I am sorry for wasting everyones time.

  9. #9
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    No problem, glad it is working.

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

Similar Threads

  1. why use timer for copyfile?
    By vicsaccess in forum Programming
    Replies: 7
    Last Post: 04-05-2016, 12:39 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