Solved

Access 2010 code to execute compact & repair

Posted on 2010-08-12
5
4,102 Views
1 Endorsement
Last Modified: 2013-11-27
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

1
Comment
Question by:OGSan
  • 3
5 Comments
 
LVL 9

Expert Comment

by:Tom
ID: 33425528
Try this:
DoCmd.RunCommand acCmdCompileAndSaveAllModules
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
ID: 33426250
1.Do you have the menu bar displayed in the Ribbon?
(In Access 2007, custom Menus and toolbars are now under the AddIns Tab on the Ribbon)

2. Acc 2003 and older used Menus and Toolbars, Access 2010 uses the Ribbon.
So try this instead, it does not seem to work in 2007, but perhaps it will in 2010?:
DoCmd.RunCommand acCmdCompactDatabase
Or this:
DoCmd.RunCommand acCmdRepairDatabase

;-)

JeffCoachman
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 33426266
Oh,

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

Author Comment

by:OGSan
ID: 33426453
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.  
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 33426662
;-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now