Solved

Compacting work tables in vb

Posted on 2001-06-07
3
209 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

832 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