compactDatabase command

Hi guys,
I have used compactDatabase command in my code which ends in error because the database (Ms access) i use is still locked. I closed all connections to the database and set db objects to nothing but still its locked. How do i compact database even if it is locked. The lock file is gone once the application ends. Please help me.
[341 byte] By [sureshcse] at [2007-11-20 11:46:56]
# 1 Re: compactDatabase command
Maybe executing DoEvents before compactDatabase command
jggtz at 2007-11-9 19:32:26 >
# 2 Re: compactDatabase command
This is the proper way. Compact it before you open it! Here's a rewritten routine that doesn't use DAO.

Private Sub Form_Load()
Call CompactAndRepair("tracking07.mdb")
end sub

Sub CompactAndRepair(db$)
Dim jro As jro.JetEngine, xn$
Set jro = New jro.JetEngine
Screen.MousePointer = vbHourglass
xn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\"
jro.CompactDatabase xn & db, xn & db & "-2"
If Len(Dir(App.Path & "\" & db & "-2")) > 0 Then
Kill App.Path & "\" & db
Do While Len(Dir(App.Path & "\" & db)) > 0
DoEvents ' wait for delete
Loop
Name App.Path & "\" & db & "-2" As App.Path & "\" & db
Do While Len(Dir(App.Path & "\" & db)) = 0
DoEvents ' wait for copy to complete
Loop
End If
Screen.MousePointer = vbDefault
End Sub
dglienna at 2007-11-9 19:33:21 >
# 3 Re: compactDatabase command
Thanks a lot :). One more question. Is it possible to compact a database even if it is locked?
sureshcse at 2007-11-9 19:34:31 >
# 4 Re: compactDatabase command
Nope. Locked means it's opened.
dglienna at 2007-11-9 19:35:31 >
# 5 Re: compactDatabase command
thanks a lot dglienna
sureshcse at 2007-11-9 19:36:25 >