0

特定のフォルダー内のファイルに対して for each ループを持つモジュール内に MS Access VBA プロシージャがあります。

ループ内では、別のフォルダーに新しいファイルを作成し、ループ内のファイルからクリーンアップされたデータを格納します。新しいファイルのデータを SQL Server 2005 データベースにインポートします。インポートが成功すると、スクリプトはクリーンアップされたファイルを削除し、ループ内のファイルを同じディレクトリ内のアーカイブ サブフォルダーに移動 (またはコピー/削除)しようとします。

ファイルのループは、ループされたフォルダー内のすべてのファイルで正常に機能します...最後のファイルを除きます。そのとき、アクセス許可が拒否されましたというエラーが表示されます。

上記の状況下では、エラーメッセージは常に次のいずれかで発生します(同様のコマンドをいくつか試しました)。

fso.MoveFile
fso.DeleteFile (just after copy)
f.Move
f.Delete (just after copy)
Name origin As destination

これが私のコードです:

Dim fso As New Scripting.FileSystemObject
Dim f As file
Dim processingFiles As Files

If fso.FolderExists(incomingPath) Then
    Set processingFiles = fso.GetFolder(incomingPath).Files
End If

For Each f In processingFiles

    /*this is where the create a new file and clean it part runs - works fine*/

    If fso.FileExists(archivePathFile) Then
        Kill archivePathFile
    End If

    If fso.FileExists(tempPath & "\cleaned_processing_file.txt") Then
        Kill tempPath & "\clean_processing_file.txt"
    End If


    f.Move archivePathFile   '<------------- Permission Denied, last file in folder
    Debug.Print f.Name & " is now in " & incomingPath & "\Archive"

    'f.Copy archivePathFile, True 
    'f.Delete True '<----------------------- Permission Denied, last file

    'Name origPathFile As archivePathFile '< Path/File access error, last file

Next '<--- For Each Loop
4

2 に答える 2