Private sub form_load ()
Text1.text = app. Path & "/db1.mdb"
End sub
Private sub commandementclick ()
On Error resume next
Dim snewname as string
Dim sbkfile as string
Snewname = text1.text
Sdatabase = snewname
Mousepointer = 11
Snewfile = left $ (sdatabase, Len (sdatabase)-3) & "new"
Sbakfile = left $ (sdatabase, Len (sdatabase)-3) & "Bak"
If check1.value = 1 then
Name sdatabase as sbakfile back up the database
End if
Dbengine. repairdatabase sdatabase' fix the database
If Dir (snewfile) <> "" then
Kill snewfile
End if
Dbengine. compactdatabase sdatabase, snewfile 'compressed Database
If Dir (sbakfile) <> "" then
Kill sbabkfile
End if
If Dir (sdatabase) <> "then
Kill sdatabase
End if
Name snewfile as sdatabase
Bcompactmdb = true
Mousepointer = 0
Mousepointer = 0
Msgbox "compressed database completed! "
End sub
Private sub command3_click ()
End
End sub
Bytes ---------------------------------------------------------------------------------------------------------
Compressing the ACCESS database in VB
Http://it.icxo.com/htmlnews/2004/07/29/278348.htm
Bytes ---------------------------------------------------------------------------------------------------------
'Use Microsoft Jet and replication provided by VB to compress the database
'Select Microsoft Jet and replication from the reference, and then apply the following code:
Dim J as new jro. jetengine
'Create and compress the temporary database to another directory.
J. compactdatabase "provider = Microsoft. Jet. oledb.4.0; Data "&_
"Source = D:/mydb. mdb ;"&_
"Jet oledb: Database Password = 123456789 ",_
"Provider = Microsoft. Jet. oledb.4.0; Data "&_
"Source = E:/mydb. mdb ;"&_
"Jet oledb: encrypt database = true ;"&_
"Jet oledb: Database Password = 123456789"
'Delete the original database
Kill "D:/mydb. mdb"
'Copy the compressed database back to its original location.
Filecopy "E:/mydb. mdb", "d:/mydb. mdb"
'Delete temporary database
Kill "E:/mydb. mdb"
Set J = nothing