Solved

Access 2010 code to execute compact & repair

Posted on 2010-08-12
5
4,184 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

856 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