Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 23rd, 2006, 04:34 PM
Authorized User
 
Join Date: Feb 2006
Location: Sacramento, CA, USA.
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default Compacting database

Is there a way to compact a database from another database but keep the original name?
I have found code to compact but you have to create a new database.

Thanks,
Scott
__________________
ScottP
Reply With Quote
  #2 (permalink)  
Old March 23rd, 2006, 07:10 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hi Scott,

You can do it with a little file juggling:

Sub Test()

   ' Running this line of code leaves you with your
   ' original database and a compacted temporary version
   ' of your original database on drive C:
   DBEngine.CompactDatabase "C:\Test.mdb", _
      "C:\TestTemp.mdb"

   ' Delete old backup file if there is one.
   If Dir("C:\Test.bak") <> vbNullString Then
      Kill "C:\Test.bak"
   End If

   ' Now change the extension of your original database to
   ' save as a backup file, and rename the compacted temporary
   ' version of your original database to the name of your original
   ' database.
   Name "C:\Test.mdb" As "C:\Test.bak"
   Name "C:\TestTemp.mdb" As "C:\Test.mdb"

End Sub

HTH,

Bob

Reply With Quote
  #3 (permalink)  
Old March 24th, 2006, 07:08 PM
Authorized User
 
Join Date: Feb 2006
Location: Sacramento, CA, USA.
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Bob, it was the renaming thing I could not find anywhere. Works fine.

Thanks again,
Scott
Reply With Quote
  #4 (permalink)  
Old August 8th, 2006, 09:16 AM
Authorized User
 
Join Date: Aug 2005
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I was under the impression that only closed databases could be compacted. If I put that code word-for-word into a module and run it, it will not work. Obviously I'm missing something. Do I need to close the current database file (Test.mdb here) and open another one with the startup module containing this code and then close it automatically, only to open test.mdb back up again? I hope there is an easier way.

Reply With Quote
  #5 (permalink)  
Old August 8th, 2006, 10:40 AM
Authorized User
 
Join Date: Feb 2006
Location: Sacramento, CA, USA.
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Jeff, my question was specifically for compacting from another database so I believe this only works with the database to be compacted closed. I may be missing something but if you have the database open why don't you just compact it manually?

ScottP
Reply With Quote
  #6 (permalink)  
Old August 9th, 2006, 09:33 AM
Authorized User
 
Join Date: Aug 2005
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I got it to work. Thanks.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
compacting database pblm MathLearner VB Databases Basics 8 September 27th, 2007 07:34 AM
Compacting Access Database problem imaley SQL Language 1 April 23rd, 2004 11:28 AM
Compacting Access Database from code imaley Access 6 March 31st, 2004 05:33 PM
Automatically Compacting a Database nanohurtz Access 2 March 22nd, 2004 10:25 AM
Compacting a large database takabyte Classic ASP Databases 1 February 5th, 2004 12:58 PM



All times are GMT -4. The time now is 01:04 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.