MS Access VBA to delete files in Windows Explorer

I am using Access 2010 and Windows 7

I want to programmatically delete files that are more than 10 days old from a folder using MS Access VBA. I am using the filesystemobject but I am either not coding it correctly or am missing a reference library. I have not even put in the date compare code because I can't seem to get the date created. I get a file not found error on the dteCreate = fileOb.GetFile(fileNme).DateCreated line.

Dim fileOb As Object
Dim fileNme As String
Dim path As String
Dim dteCreate As String
Dim FileGet As String

Set fileOb = CreateObject("Scripting.FileSystemObject")
path = "\\Cust\DeptFiles$\pol\Shop\TopCust\"
fileNme = Dir(path)
Do While (fileNme <> "")
      If InStr(fileNme, "RptRecentContact") > 0 Then
          FileGet = fileOb.GetFileName(fileNme)
          dteCreate = fileOb.GetFile(fileNme).DateCreated      
'           Kill fileName
'         End If
      End If

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:
FileGet = fileOb.GetFileName(fileNme)
          dteCreate = FileGet.DateCreated  

to delete the file you need to use

       fileOb.deletefile fileGet
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPDesigner and DeveloperCommented:

Kill fileNme


Kill fileName

Note that you have dropped the a from Name in your other code.

I would highly recommend using

Option Explicit

at the top of your code modules to avid any spelling mistakes like this.
Rey Obrero (Capricorn1)Commented:
try this simple function

Function getFileInfo(path)
   Dim fso, f, msg
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.GetFile(path)
   msg = f.Path & "<br>"
   msg = msg & "Created: " & f.DateCreated & "<br>"
   msg = msg & "Last Accessed: " & f.DateLastAccessed & "<br>"
   msg = msg & "Last Modified: " & f.DateLastModified  
   getFileInfo = msg
End Function

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
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 Development

From novice to tech pro — start learning today.