How to move a File using VBA

I have code (using VBA Access 2010) that checks to see if a File exists (it works). If the File exists I need to rename it and MOVE it to a local location.  

In the code below the NEW file name is newpriceMonthYear where vMonthYear (for October) would be 102017.txt and the new file name will be "newprice102017.txt".  Creating vMonthYear  works. vMonthYear is Dim'd as a STRING  The code executes with no errors but the File is NOT moved

Dim FSO As FileSystemObject
FileToMove = "C:\RDC-POS\OLCC Downloads\newprice.txt"
DestPath = "C:\RDC-POS\OLCC Past Downloads\newprice" & vMonthYear
FSO.MoveFile FileToMove, DestPath
Who is Participating?
Bill PrewCommented:
You seem to be missing:

Set FSO = CreateObject("Scripting.FileSystemObject")

Open in new window

Martin LissOlder than dirtCommented:
Try  (Note: Not FSO)

Name FileToMove As DestPath
Jessica KCommented:
Hello Juricta,

Try the following code:

Using a VBA Code Move a single file from one location to another in MS Access
If it didn't resolve your issue, please let us know. We will surely help you with another solution.

jurictaAuthor Commented:
Bill was the "spot on" answer.  adding his line to my code makes it work perfectly.  Thanks to all who added to my question
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.