How to use FileSystemObject work in Access 2007

Okay why won't the FileSystemObject work in my Access 2007?
I get a runtime error 58 "File already exists" on this line:
 fso.MoveFile (sfol & File), dfol

What am I missing???
Here's my code any advice would be appreciated.
Thanks,

Public Sub MoveFiles()

Dim MyDB As Database
Dim MyRS As Recordset

Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset("tblMoveFiles")

MyRS.MoveFirst

If MyRS.RecordCount > 0 Then
 MyRS.MoveFirst
 Do While Not MyRS.EOF
 '....move file process

Dim fso As Object
Dim File As String, sfol As String, dfol As String

File = MyRS!ATTACHMENT_FILE_NAME ' change to match the file name
sfol = "C:\IMAGES" & "\" ' change to match the source folder path
dfol = "C:\BATCH" & "\" & MyRS!BATCH_FOLDER_NAME ' change to match the destination folder path

Set fso = CreateObject("Scripting.FileSystemObject")

If Not fso.FileExists(sfol & File) Then
    MsgBox sfol & File & " does not exist!", vbExclamation, "Source File Missing"
ElseIf Not fso.FileExists(dfol & File) Then
    fso.MoveFile (sfol & File), dfol
Else
    MsgBox dfol & File & " already exists!", vbExclamation, "Destination File Exists"
End If
 MyRS.MoveNext
 Loop
 End If

MyRS.Close

End Sub
lblancatoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
The obvious answer would be that the file specificed by your path does not exist. Can you Debug.Print the fully formed variable you're using? To do that, just insert this line after setting the sfol and dfol values:

Debug.Print sfol & File

This will print to the Immediate window - examine that to determine if you are correctly building that file path.
0
lblancatoAuthor Commented:
The file reference appears to be correct.
from the Immediate Window:
C:\WWS_IMAGES\STM010837BACKFILE.TIF

Could it be a reference library issue????

Thanks.
0
lblancatoAuthor Commented:
I have even tried
fso.MoveFile "C:\IMAGES\837E.PDF", "C:\BATCH\BackUp10"
 the source and destination into the code and still receive the same error  runtime error 58 "File already exists". This is just crazy.
0
Determine the Perfect Price for Your IT Services

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

Rey Obrero (Capricorn1)Commented:
File = MyRS!ATTACHMENT_FILE_NAME ' change to match the file name
sfol = "C:\IMAGES" & "\" ' change to match the source folder path

'Change this
'dfol = "C:\BATCH" & "\" & MyRS!BATCH_FOLDER_NAME  ' change to match the destination folder path

'to
dfol = "C:\BATCH" & "\" & MyRS!BATCH_FOLDER_NAME  & "\"

Set fso = CreateObject("Scripting.FileSystemObject")


If Not fso.FileExists(sfol & File) Then
    MsgBox sfol & File & " does not exist!", vbExclamation, "Source File Missing"
ElseIf Not fso.FileExists(dfol & File) Then

    'change this
    'fso.MoveFile (sfol & File), dfol
     'to
    fso.MoveFile (sfol & File), dfol & File
Else
    MsgBox dfol & File & " already exists!", vbExclamation, "Destination File Exists"
End If




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
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Or just do this:

If Dir("Your Full Path Here") = "" Then
  FileCopy "source", "Destination"
End If
0
lblancatoAuthor Commented:
You are a genius. Thank you, thank you, thank you.
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.