run FileCopy code from a string


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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)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
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
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

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cwbarrettAuthor Commented:
Thank you for your help.  Used the long-hand version and it works great.
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
you're welcome, and awesome!
cwbarrettAuthor Commented:
Thank you.  Worked out great.
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
you're welcome, Charlie ~ happy to help
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.