Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 29th, 2003, 05:05 PM
Registered User
 
Join Date: Aug 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Dwight
Default Compact mdbs while open, using code

I want to try to compact a database after I have deleted several tables and while the mdb is still open.

Some background to why I think I need to do this - I will be working with very large datasets and after the user selects the process to perform I am going to be exporting the result to excel and deleting the table(s) of calculations and attempt to compact the database so that the user can select another process without worrying about running out of space in the database.

Any assistance would help.

Dwight
Resource Analyst

 
Old August 31st, 2003, 08:09 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dwight,
you may want to check this out:
http://www.mvps.org/access/general/gen0013.htm

Steven

I am a loud man with a very large hat. This means I am in charge
 
Old September 8th, 2003, 02:53 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 451
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Ben Horne
Default

Dwight,

The only option you have (from what it looks like to me) is to compact the database WITHOUT using code. I believe that in order to compact a database while it is still open, you need to go to Tools, Compact & Repair database




Ben
 
Old September 8th, 2003, 03:01 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There was a discussion about this very topic last week on yahoo's AccessDevelopers group.

Duane Hookom pointed out "To compact the current database, I believe you must close it, open another, and compact the first. Michael Kaplan has a solution that Shut One Open New at
http://www.trigeminal.com/utility.asp?1033"

I myself use a shortcut icon with the /compact switch, but the database would have to be closed.

Another individual (Mike) posted the following:

I have seen many threads on this for answers. I haven't seen one
with CompactRepair so that's what I'm posting. It needs a reference
to Microsoft Scripting Runtime to use the FileSystemObject (my
preferred way of determining file existence). It takes a file and
functionally compacts it using the same name through a temp db.

Basically I compact "C:\db1.mdb" into "C:\db1_temp.mdb", check to
ensure the compact worked and created a file, delete "C:\db1.mdb",
then move "C:\db1_temp.mdb into "C:\db1.mdb".

Because of the DeleteFile method, if you choose to use this code, I
do not guarantee against loss, flooding, or spindling of your
database. But I do use it quite successfully on a daily basis. It
takes one parameter, the path to the database, i.e., "C:\db1.mdb"

Function CompactDB(strDB As String) As Boolean
' -- TAKES A DATABASE AND COMPACTS IT INTO ITS ORIGINAL NAME BY USING
A TEMP DB
On Error GoTo CompactDB_Err

Dim fso As New FileSystemObject
' -- COMPACT THE SOURCE INTO A TEMP DB
CompactDB = Application.CompactRepair(strDB, Left(strDB,
InStrRev(strDB, ".") - 1) & "_temp.mdb", True)
' -- IF SUCCESSFUL, DELETE THE SOURCE DB
If fso.FileExists(Left(strDB, InStrRev(strDB, ".") - 1)
& "_temp.mdb") Then
fso.DeleteFile (strDB)
End If
' -- RENAME THE TEMP TO THE ORIG
fso.MoveFile (Left(strDB, InStrRev(strDB, ".") - 1))
& "_temp.mdb", strDB

' RESET THE ERROR HANDLER
On Error GoTo 0
Exit Function

CompactDB_Err:
CompactDB = False
Exit Function
End Function

HTH,

Beth M
PS I also claim Mike's disclaimers :)
 
Old September 8th, 2003, 04:03 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When performing a compact and repair on a database, you have to make certain that you have exclusive access to the database - no one else can be using it.

Rand





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to open different access database from code TomW Access VBA 2 May 6th, 2008 11:49 AM
Need code to open the printer dialog screen donrafeal Access VBA 1 June 13th, 2006 01:35 PM
Open a Parameterised Query to screen using code vbark Access VBA 2 June 5th, 2006 05:46 PM
comparing the designs of two mdbs rahzan Access VBA 2 April 1st, 2005 06:01 PM
Why doesn't this code open window to fullscreen? savoym Javascript 4 July 23rd, 2003 09:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.