New directory being used after database closed

K

KidSensation

Hello all,

I have a strange problem. I wrote a process that loops through a
folder, grabs text files one-by-one and imports them into tables in my
database. Before I start looping, I make a subdirectory so that after
I use each file (before moving on to the next one) I can move the file
into it to avoid using it again at a later date. I move the file
using an object and the movefile method. Anyway, my problem starts
after I close the database. I exit the database normally and when I
go out to the subdirectory and try to do anything with it, it tells me
that the folder is currently in use and I cannot modify it in any
way. Is there something that I should be releasing here? The only
way I can do anything with the folder is if I open up the db in design
mode, open vb editor and click stop. Even this doesn't work every
time. I am stumped. Any insight would be greatly appreciated.
Thanks.

Here is some of my code:

Set FSys = CreateObject("Scripting.FileSystemObject") 'Set the file
object

If Len(Dir(strPath & strDate, vbDirectory)) = 0 Then 'see if
the directory exists
MkDir strPath & strDate 'create the directory
End If
If strFile <> "" Then
Do While (Len(strFile) > 0)
DoCmd.CopyObject , Left(strFile, 4), acTable, strTable
'make a new table with a new name
intFileLength = Len(strFile)
InitializeDatabaseTest (Left(strFile, intFileLength -
4)) 'send filename onto the rest of process
FSys.MoveFile strPath & strFile, strPath & strDate &
"\" & strFile 'move file after done
strFile = Dir(strPath) 'get next file
Loop
Else
MsgBox ("There are no files in your directory!")
End If
 
6

'69 Camaro

Hi.
Is there something that I should be releasing here?

Did you release the memory for the FSys variable before it went out of
scope?

.. . .

CleanUp:
Set FSys = Nothing
Exit Sub
ErrorHandler:
' Error handler code goes here.
GoTo CleanUp
End Sub


HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
Blogs: www.DataDevilDog.BlogSpot.com, www.DatabaseTips.BlogSpot.com
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 
K

KidSensation

Hi.


Did you release the memory for the FSys variable before it went out of
scope?

. . .

CleanUp:
Set FSys = Nothing
Exit Sub
ErrorHandler:
' Error handler code goes here.
GoTo CleanUp
End Sub

HTH.
Gunny

Seehttp://www.QBuilt.comfor all your database needs.
Seehttp://www.Access.QBuilt.comfor Microsoft Access tips and tutorials.
Blogs:www.DataDevilDog.BlogSpot.com,www.D....QBuilt.com/html/expert_contributors2.htmlfor contact
info.

I had not. I was looking for something like that, but I tried
FSys.close which obviously does not work. Anyway, initial testing
seems to work. Thanks for your help.
 
K

KidSensation

I had not. I was looking for something like that, but I tried
FSys.close which obviously does not work. Anyway, initial testing
seems to work. Thanks for your help.- Hide quoted text -

- Show quoted text -

I lied. It worked the first time, but has failed the next 3 times
following the same exact procedure. Anything else to try?
 
6

'69 Camaro

Hi.
I lied. It worked the first time, but has failed the next 3 times
following the same exact procedure. Anything else to try?

I hate when that happens. Save all of your work and reboot to get a clean
slate. Open the database and run the procedure again a few times. Does it
still lock the directory? Could the procedure InitializeDatabaseTest be
hanging onto the directory?

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
Blogs: www.DataDevilDog.BlogSpot.com, www.DatabaseTips.BlogSpot.com
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top