How to compress an Access database in VB

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.