PDA

View Full Version : Unable to move folder after Dir?



MitchO
03-02-2011, 08:47 AM
Hi All .. I usually read up through this (and other) forums to find my solutions, but I just can't seem to find anything about this problem, so I'm hoping I can get a direct answer. I'm on Access 2003.

I recently added this piece of code on an "Open" button; it checks to see if there is any .txt file in the folder and puts it in a Text Box on my form:

Dim oObj As Object
Dim oTxt As Object
Dim fs As Object

'Check for a .txt file and show it
sTextFile = Dir(QAFileBucket.BasePath & "\ToBeQAd\" & file & "\*.txt")

If sTextFile <> "" Then
Set fs = CreateObject("Scripting.FileSystemObject")
Set oObj = CreateObject("Scripting.FileSystemObject")
Set oTxt = oObj.openTextFile _
(QAFileBucket.BasePath & "\ToBeQAd\" & file & "\" & sTextFile, 1)

With oTxt
txtScraperNotes = .ReadLine
.Close
End With

Set oObj = Nothing
Set oTxt = Nothing

fs.DeleteFile QAFileBucket.BasePath & "\ToBeQAd\" & file & "\" & sTextFile, True

Set fs = Nothing
End If


I am able to successfully delete the file and close all the objects. But later on, when my user hits an "Accept" type button, a MoveFolder call now says that Permission is Denied:

Dim fs As Object

Set fs = CreateObject("Scripting.FileSystemObject")

fs.MoveFolder QAFileBucket.BasePath & "\ToBeQAd\" & file, QAFileBucket.BasePath & "\ToBeCleansed\" & file


It just feels like the Dir command is keeping hold over the folder, or I'm not fully closing the text stream somehow. I've done as much research as I can, and I cannot find any indication of how to "close" the connection (if there even is one). The second piece of code works every time there is no text file; I only receive the permission denied error when the first piece successfully hits the If condition.

It's driving me nuts! Anyone have any solutions/suggestions or a nice rusty spoon to scoop my eyeballs out with?

SoftwareMatt
03-10-2011, 04:22 AM
You could try using 'Name' as below:

Name QAFileBucket.BasePath & "\ToBeQAd\" & file AS QAFileBucket.BasePath & "\ToBeCleansed\" & file