PDA

Click to See Complete Forum and Search --> : Compacting a database


Clunietp
Jan 6th, 2000, 12:03 AM
Possibly on the first line, DB.CLOSE, but that assumes that you have the database open before calling this sub.

Also, if there are multiple users of this database, you cannot get exclusive access to the file and will not be able to compact it unless everyone else who is using the database has also closed their reference to it

Dean Murray
Jan 6th, 2000, 11:57 AM
Question. When we use a procedure for compacting a database, is there any untrappable error that could occur during this call:
DBEngine.CompactDatabase sDBName, sBackup

which would then allow
Kill sDBName
to occur thus removing the database from the system?

The entire procedure is below:

Sub CompactDatabase(sDBName As String, sBackup As String)
on error goto errtrap
db.Close

'Check to see if the tempory backup exists
If Len(Dir$(sBackup)) > 0 Then 'Backup exists

Kill sBackup 'Delete it

End If

'Compact the database to the tempory one
DBEngine.CompactDatabase sDBName, sBackup

'Delete the current one
Kill sDBName

'Compact the backup to the actual database
DBEngine.CompactDatabase sBackup, sDBName

'And remove the backup database
Kill sBackup

OpenDB (App.Path & "\demo.mdb")
exit sub
errtrap:
msgbox "there is an error"
End Sub