Compact and Repair another DB from VBA (1 Viewer)

yippie_ky_yay

Registered User.
Local time
Today, 12:07
Joined
Jul 30, 2002
Messages
338
Hello all,

I saw the SendKeys function - but how could I compact and repair another database? (preferably without adding any code to the target db at all).

The reason is that I need a certain table deleted from the database I use for the web - so it would be nice to compact it afterwards too!

Thanks in advance,

-Sean
 

fuzzygeek

Energy Ebbing
Local time
Today, 17:07
Joined
Mar 28, 2003
Messages
989
Go to the VBA help screen and look up the compactdatabase method. Both JRO and DAO examples for compacting DBs are given. Yes using code you can compact another database.
 

yippie_ky_yay

Registered User.
Local time
Today, 12:07
Joined
Jul 30, 2002
Messages
338
Thanks fuzzygeek! I'll look that up.

Never heard of JRO before - what is that? Is it another name for ADO?

Thanks again,
-Sean
 

Nero

Shop smart, shop S-Mart
Local time
Today, 17:07
Joined
Jan 8, 2002
Messages
217
Never heard of JRO before - what is that? Is it another name for ADO?

Jet Replication Objects. It's an extension to ADO used for compact/repair.
 

simongallop

Registered User.
Local time
Today, 17:07
Joined
Oct 17, 2000
Messages
611
Try this:

Function Compact_DB()
'SET PATH
Path = "C:\MyFiles\dev\"

'COMPACT CHOSEN DATABASE, TO TEMPORARY DATABASE NAME
DBEngine.CompactDatabase Path & "MyDatabase.mdb", Path & "Spare1.mdb"

'DELETE OLD DATABASE
Kill Path & "MyDatabase.mdb"

'RENAME TEMPORARY DATABASE TO ORIGINAL NAME
Name Path & "Spare1.mdb" As Path & "MyDatabase.mdb"

End Function

Haven't tried this in 2k though. Built it for 97
 

yippie_ky_yay

Registered User.
Local time
Today, 12:07
Joined
Jul 30, 2002
Messages
338
Thank you everyone who replied!

Harry, I used your code in Access 2000 and it worked like a charm! Even better than expected because I only need to compact the db before moving it to a seperate folder - so I didn't need to bother with the renaming, and deleting lines (I just specified a different path for the destination).

Thanks again!

-Sean
 

mdjks

Registered User.
Local time
Today, 11:07
Joined
Jan 13, 2005
Messages
96
worked like a charm in 2010 as well
 

Users who are viewing this thread

Top Bottom