Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: Compacting and Repairing Access 2000 database


Message #1 by "Hanson Lam" <hansonlam@h...> on Sun, 17 Jun 2001 00:45:32
You may this code. Add reference to Jet Replication Objects
This uses ADO 2.6

' Code Begin
'-----------------------------------

Private Sub jiCompactDB()
Dim JRO As JRO.JetEngine

cnLocalData.Close 'Close the database connection
Set cnLocalData = Nothing

Set JRO = New JRO.JetEngine

Screen.MousePointer = vbHourglass
MDILabel.sbrStatus.Panels(1).Text = "Compacting Database. Pls Wait!!"
If Dir(App.Path & "\backup.mdb") <> "" Then Kill App.Path & "\backup.mdb"
JRO.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" &
App.Path & "\Label.mdb", _
    "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & App.Path &
"\Backup.mdb"
  
Kill App.Path & "\Label.mdb"
Name App.Path & "\Backup.mdb" As App.Path & "\Label.mdb"
Screen.MousePointer = vbDefault
	
End Sub

'End Code
'-------------------


Raheem



> Hello:
> 
> I've built a VB6 application with an Access 2000 back-end.  Is there any 
> way to "Compact and Repair" the database through VB6?  This feature in 
> Access to makes the database smaller and more efficient - and should be 
> done once in a while.
> 
> Does the following code in VB6 do the same?
> 
> DBEngine.CompactDatabase OriginalDB, CompactedDB
> 
> (OriginalDB is the full path to the original db, and CompactedDB is the 
> path for the new DB.
> 
> Anyone done this before?
> 
> Hanson
> 

  Return to Index