Solved

Compacting work tables in vb

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

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 49

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now