• Copying files from an Access comand button

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Copying files from an Access comand button

    Author
    Topic
    #462511

    I would like to copy a series of files that begin with a specific date that has been selected from my form screen. I would like to add this to the end of a procedure that already runs from an Access command button. However immediately when I finish typing the command and move off the line of text I typed, the destination for the files is highlighted and I get an compile error “Expected: End of Statement”

    copy “N:Files” & Format(Forms!frmMenu!AbsDt, “mm-dd-yy”) & “*.*” “H:BackupAbsenceFiles”

    Viewing 1 reply thread
    Author
    Replies
    • #1177543

      Judy,

      Not my area of expertise, but it looks as if you are trying to use a DOS command within VBA. When I’ve had to copy files in the past, I’ve set a variable to a FileSystemObject, e.g. Dim objFSO as FileSystemObject. Then, the methods such as objFSO.CopyFile become available.

      Hope this helps,

    • #1177544

      I would like to copy a series of files that begin with a specific date that has been selected from my form screen. I would like to add this to the end of a procedure that already runs from an Access command button. However immediately when I finish typing the command and move off the line of text I typed, the destination for the files is highlighted and I get an compile error “Expected: End of Statement”

      copy “N:Files” & Format(Forms!frmMenu!AbsDt, “mm-dd-yy”) & “*.*” “H:BackupAbsenceFiles”

      I believe in this case you want to use FileCopy rather than copy – see these posts by Hans – [post=”303048″]Copy File to Another Location[/post] and [post=”736866″]Wanting a List of Directories…[/post]

      • #1177562

        Thanks for your help. You got me on the right path. I had to keep playing with FileCopy to get it to work. There were 9 files and I tried to copy them using the asterisk as a wildcard to copy them using just one command line. That did not work for me so I inserted 9 commands one for each file I wanted to copy and then it worked just fine. One other thing that did not work was assuming that the command worked like the DOS command where you provide the path, foldername and filename in the source and then just the path and foldername in the destination. It did not work until I included the filename in the destination as well as the source.

    Viewing 1 reply thread
    Reply To: Copying files from an Access comand button

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: