Solved

Compacting work tables in vb

Posted on 2001-06-07
3
210 Views
Last Modified: 2010-05-03
I am using access tables as work tables in VB6.
I am deleting records. Each time I run the program the DB gets larger by about 2MB. I do not want to have to have Access on the users machine so how do I compact the database so as to keep it from getting too big. I have used Access tables with VB6 apps before without having Access on the user machine but I did not notice this increase in the DB size.

I have tried dropping tables and then creating them when needed but this makes no difference.

Have the experts any ideas

Thanks
0
Comment
Question by:arquette2
  • 2
3 Comments
 
LVL 50

Accepted Solution

by:
Ryan Chong earned 100 total points
ID: 6163026
Hi,

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
 

OR

http://www.freevbcode.com/ShowCode.Asp?ID=1024
0
 

Author Comment

by:arquette2
ID: 6163301
Thanks ryancys
Your answer works a treat.

I tried the free code but it did not work for some reason.

arquette2
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 6163325
Hi arguette2, firstly glad can help you. and please pay tribute to TimCottee, one of the Expert in the Top 15 list. I get this code from what he posted earlier.

Then as compacting database, you can use DAO to do it so, find more about compact database in those VB website that may help. : )
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
A macro to Count the number of rows across all worksheets 3 125
MsgBox 2 59
SQL VB connection works in one PC and doesn't in another 15 67
using web browser with BING 40 131
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

839 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