Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Jai Williams   on Jan 20 In MS Office Category.

  
Question Answered By: Jimmy Abp   on Jan 20

To compact an Access database  via VBA you need to make a copy of the
original, and compact from one to the other. When complete you can
delete the original. Here is code  from within Access, you will need to
reference MS-Access within Excel to accomplish this. Though I will admit
I never tried this via Excel.

Dim dbOriginal As String
Dim dbCompact As String
Dim dbPath As String
Dim dbTempPath As String

dbOriginal = "Inventory and Cost.mdb" 'Original Database
dbCompact = "Inventory and Cost1.mdb" 'Database to copy too
dbPath = "M:\Databases\" & dbOriginal 'Path of original database
dbTempPath = "M:\Databases\" & dbCompact 'Path of new database

Call DBEngine.CompactDatabase(dbPath, dbTempPath) 'Compact data
DoEvents
Kill dbPath 'Delete original
DoEvents
Name dbTempPath As dbPath 'Rename new database to original name

Share: 

 

This Question has 11 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Compact & Repair Access Database from Excel Or get search suggestion and latest updates.


Tagged: