Link to home
Start Free TrialLog in
Avatar of OGSan
OGSanFlag for United States of America

asked on

Access 2010 code to execute compact & repair

Hi, Experts -
I'm using MS Access 2010 and have a routine that runs fine under Access 2003 but which issues an error message, "Invalid procedure call or argument" under 2010.  I've attached the snippet of code below.
Question - Is there a way to modify this code so it will run under 2010, as well as be backward compatible with 2003?  The databases were created under 2003, but the company will be migrating over to Office 2010 product line later this summer.
MsgBox ("Compact & repair will commence once this msgbox is closed.  This will take several seconds.  Please do not close ACCESS window.")
    CommandBars("Menu Bar"). _
    Controls("Tools"). _
    Controls("Database utilities"). _
    Controls("Compact and repair database..."). _
    accDoDefaultAction

Open in new window

Avatar of Tom
Tom
Flag of Norway image

Try this:
DoCmd.RunCommand acCmdCompileAndSaveAllModules
ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh,

Or try the code here to try (Application.CompactRepair()):
http://msdn.microsoft.com/en-us/library/bb237807%28office.12%29.aspx
Avatar of OGSan

ASKER

Thanks for the replies.  I've tried the first two suggestions made above:
1.  Result of DoCmd.RunCommand acCmdCompileAndSaveAllModules
     Nothing happened, nada, zip.
2.  Result of DoCmd.RunCommand acCmdCompactDatabase
     Error message, "You cannot compact the open database by running a macro or Visual Basic code.
     Instead of using a macro or code, click the File tab and then click Compact and Repair Database."
I'm going to go with this since - even though it doesn't do anything - it at least informs the MS Access 2010 user of what to do and where to do it.