Error when compact/repair on start-up

T

teddysnips

My client has asked if it's possible to Compact and Repair his Front
End database programmatically. I remember doing this from a VB
application about 10 years ago, so I wondered if it was possible in
Access.

The application is Access 2003 in 2002-2003 File Format.

I've added the following function to the Front End in a global module:

Public Function CandRDB()

CommandBars("Menu Bar"). _
Controls("Tools"). _
Controls("Database utilities"). _
Controls("Compact and Repair Database..."). _
accDoDefaultAction

End Function

and created an AutoExec macro that only calls this function. It
appears to be working (something happens, there's an hourglass cursor
for example) but then barfs with the following:

"-2147467259 Method 'accDoDefaultAction' of object
'_CommandBarButton' failed"

From what I've read, this can happen if the Menu Bar is not visible,
but it is.

Any thoughts? I know that the database can be set to compact on exit,
but that's not what the client has asked for.

Thanks

Edward
 
S

Stuart McCall

My client has asked if it's possible to Compact and Repair his Front
End database programmatically. I remember doing this from a VB
application about 10 years ago, so I wondered if it was possible in
Access.

The application is Access 2003 in 2002-2003 File Format.

I've added the following function to the Front End in a global module:

Public Function CandRDB()

CommandBars("Menu Bar"). _
Controls("Tools"). _
Controls("Database utilities"). _
Controls("Compact and Repair Database..."). _
accDoDefaultAction

End Function

and created an AutoExec macro that only calls this function. It
appears to be working (something happens, there's an hourglass cursor
for example) but then barfs with the following:

"-2147467259 Method 'accDoDefaultAction' of object
'_CommandBarButton' failed"

From what I've read, this can happen if the Menu Bar is not visible,
but it is.

Any thoughts? I know that the database can be set to compact on exit,
but that's not what the client has asked for.

Thanks

Edward

You need to perform the compact from a separate database, otherwise you're
attempting to compact a file with running code, which obviously cannot be
allowed.

Create a new database file and create a public function that reads:

SourceFile = "c:\PathToExistingDatabase\MyFile.mdb"
OutputFile = "c:\PathToExistingDatabase\MyFile1.mdb"
Application.CompactRepair SourceFile, OutputFile

Kill SourceFile
Name OutputFile As SourceFile

With Application
.FollowHyperlink SourceFile
.Quit
End With

That will compact your app, then run the app and shut itself down.
 
A

a a r o n _ k e m p f

if your database is too stupid to be stable-- then move to something
that is.

SQL Server works perfect for me-- I never have to compact and repair.

I believe that 'Auto-Shrink' is enabled by default on smaller editions
of SQL Server

-Aaron
 
M

Michiel Rapati-Kekkonen

Ask him what is the difference between on Close and on Start-up?
Nothing can happen in between...
And no code required.


Michiel
 
K

Klatuu

To do it autmatically, Use the Compact On Close option from Tools, Options,
General tab. I don't recommend it, but it is the best automatic options.

BTW, ignore Aaron Kempf. He is a known Troll who will post false
information and denegrate Access at every opportunity for no apparent reason.
 
K

Keith Wilby

My client has asked if it's possible to Compact and Repair his Front
End database programmatically.

Why would you ever want to do this? If the client starts with a new,
pristine copy of the FE copied from a server location to the local drive
then it's not necessary, ever.

Keith.
www.keithwilby.com
 
A

a a r o n _ k e m p f

Access isn't reliable enough for anything.
Move to SQL Server.

With SQL 2005 Express, AutoShrink is set to on by default.
Case closed, you shouldn't ever have to deal with this shit

-Aaron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top