run FileCopy code from a string

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
cwbarrettAsked:
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
0
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

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

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.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
you're welcome, and awesome!
0
cwbarrettAuthor Commented:
Thank you.  Worked out great.
0
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
you're welcome, Charlie ~ happy to help
0
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.