I am upgrading my Access 2003 database to Access 2010. This code worked perfectly in 2003, but I keep getting an error in 2010. It might be that the reference isn't correct. Searching the net, I thought I might need to use "Microsoft Scripting Runtime", but it still doesn't work. It breaks at "Set fso = FileSystemObject". Here is my code. Any help would be appreciated!
Code:
Dim sDate As Date
Dim sPath As String
Dim fso As FileSystemObject
Dim oFldr As Folder
Dim oFile As File
sDate = Now() - 60
sPath = "\\Data\Custom\Archive\"
Set fso = FileSystemObject
Set oFldr = fso.GetFolder(sPath)
If oFldr <> "" Then
For Each oFile In oFldr.Files
If DateSerial(Mid(oFile, 45, 2), Mid(oFile, 47, 2), Mid(oFile, 49, 2)) < sDate Then
oFile.Delete
End If
Next oFile
End If
DeleteOld_exit:
Set oFile = Nothing
Set oFldr = Nothing
Set fso = Nothing
Exit Sub