Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

repair & compact database?

Posted on 2001-09-03
4
Medium Priority
?
337 Views
Last Modified: 2012-05-04
Hi!

How can i do repair & compact in VB (with an Access-Database)?

Falke
0
Comment
Question by:Falk2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 1

Expert Comment

by:dekeldate
ID: 6451623
0
 
LVL 4

Accepted Solution

by:
VincentLawlor earned 200 total points
ID: 6451658
Add as reference to DAO 3.51 or later to your project and
use DBEngine.Compact database here's an example.


Sub CompactDatabaseX()

   Dim dbsNorthwind As Database

   Set dbsNorthwind = OpenDatabase("Northwind.mdb")

   ' Show the properties of the original database.
   With dbsNorthwind
      Debug.Print .Name & ", version " & .Version
      Debug.Print "  CollatingOrder = " & .CollatingOrder
      .Close
   End With

   ' Make sure there isn't already a file with the
   ' name of the compacted database.
   If Dir("NwindKorean.mdb") <> "" Then _
      Kill "NwindKorean.mdb"

   ' This statement creates a compact version of the
   ' Northwind database that uses a Korean language
   ' collating order.
   DBEngine.CompactDatabase "Northwind.mdb", _
      "NwindKorean.mdb", dbLangKorean

   Set dbsNorthwind = OpenDatabase("NwindKorean.mdb")

   ' Show the properties of the compacted database.
   With dbsNorthwind
      Debug.Print .Name & ", version " & .Version
      Debug.Print "  CollatingOrder = " & .CollatingOrder
      .Close
   End With

End Sub

Vin.
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6451979
Hi Falk2,

Source from another expert:

You can also use the CompactDatabase method of the Microsoft Jet and Replication Objects (JRO) 2.1 JetEngine object to encrypt or decrypt a database. To use the JRO JetEngine object, you must set a reference to the Microsoft Jet and Replication Objects 2.1 object library. When you use the CompactDatabase method, you can't save the compacted (and optionally encrypted) database to the same name as the original database.

The CompactDatabase method takes two arguments to specify the source database and the destination database: SourceConnection and DestConnection. Both the SourceConnection and DestConnection arguments take the form of connection strings. Within the connection strings, you specify various connection properties to determine how the source database is opened and how the destination database is compacted. At a minimum, you must use the Data Source property in each connection string to specify the path and name of the database. Additionally, to encrypt the database, you must include the Jet OLEDB:Encrypt Database property in the connection string for the DestConnection argument. The following procedure uses these connection properties to encrypt the database specified by the strSourceDB argument to the path and name specified by the strDestDB argument:

Function EncryptDb(strSourceDB As String, _
                  strDestDB As String) As String
Dim jetEngine          As JRO.JetEngine
Dim strSourceConnect   As String
Dim strDestConnect     As String

' Build connection strings for SourceConnection and
' DestConnection arguments.
strSourceConnect = "Data Source=" & strSourceDB
strDestConnect = "Data Source=" & strDestDB & ";" & _
                  "Jet OLEDB:Encrypt Database=True"

Set jetEngine = New JRO.JetEngine

' Compact and encrypt the database specified by strSourceDB
' to the name and path specified by strDestDB.
jetEngine.CompactDatabase strSourceConnect, strDestConnect

Set jetEngine = Nothing
End Function

'Hope will help.

0
 

Author Comment

by:Falk2
ID: 6452790
thanks :)

Falke
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question