run FileCopy code from a string

cwbarrett
cwbarrett used Ask the Experts™
on
Hi.

I am trying to build code for filecopy  and cannot seem to build the command string properly. I have 3 strings with the following info:
destinationlocation  (text field in a form containing "C:\%userprofile%\Dropbox\<subfoldername>")
destinationfolder  (text field in a form containing "<destination folder>" -- this is a sub-folder of "destinationlocation")
destinationfilename (text field in a form containing "<destinationfilename>"

What is the correct way to build a command string to execute this using VBA filecopy?

(note:  Source file location and name is always the same... not in text field)

Thank for any help. Charlie
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
filecopy  <Source file location and name> , destinationlocation & "\" & destinationfolder & "\" & destinationfilename

Open in new window

change <Source file location and name> with the actual path and filename
Remote Training and Programming
Top Expert 2015
Commented:
Hi Charlie,

I prefer to calculate the strings in variables then use those variables in the FileCopy command.
dim sSourceFile as string, sDestinationFile as string
sSourceFile = "c:\path\filename.ext"  ' customize this
sDestinationFile = Environ$("USERPROFILE") & "\Dropbox\" & me.txtSubfoldername & "\" & me.txtDestinationFilename
FileCopy sSourceFile, sDestinationFile
MsgBox "Done" 'you may want to take this out

Open in new window

WHERE
txtSubfoldername is the controlname with the subfolder name
txtDestinationFilename is the controlname with the file name

Author

Commented:
Thank you for your help.  Used the long-hand version and it works great.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

crystal (strive4peace) - Microsoft MVP, AccessRemote Training and Programming
Top Expert 2015

Commented:
you're welcome, and awesome!

Author

Commented:
Thank you.  Worked out great.
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and Programming
Top Expert 2015

Commented:
you're welcome, Charlie ~ happy to help

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial