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]

# 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