Create a button that runs "Compact and Repair Database" in Access Database General Questions  
 |  Edit my Profile  |  Help
 
     
  
 
 
 
ali 12/20/2007 1:13 AM PST
  Question
  I need to create a button which will run :

Tools--> Database Utilities --> Compact and Repair Databases...


----------------------------------------------------------------------


Thank you so much !


--
Allen Phailat Wongakanit
 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
Allen Browne 12/20/2007 1:33 AM PST
  Answer
  You cannot programmatically compact the current database, because the shut
down for compact cannot occur while the code is running.

Microsoft even provides a way to do it:
RunCommand acCmdCompactDatabase
but it can't work for the reason explained above.

You can try stuffing keystrokes into the keyboard buffer with SendKeys. I've
no idea if that's possible, but I could not recommend it. That key sequence
could do something undesirable in a future version of Access.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"ali" <ali@discussions.microsoft.com> wrote in message
news:C6CBDD7C-D9CE-4D4B-9100-CC387F51A7C5@microsoft.com...
>I need to create a button which will run :
>
> Tools--> Database Utilities --> Compact and Repair Databases...
>
> ----------------------------------------------------------------------
>
> Thank you so much !
>
> --
> Allen Phailat Wongakanit

 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
ali 12/20/2007 1:44 AM PST
   
  thanks a lot, since my guess wasn't wrong !


--
Allen Phailat Wongakanit


"Allen Browne" wrote:

> You cannot programmatically compact the current database, because the shut
> down for compact cannot occur while the code is running.
>
> Microsoft even provides a way to do it:
> RunCommand acCmdCompactDatabase
> but it can't work for the reason explained above.
>
> You can try stuffing keystrokes into the keyboard buffer with SendKeys. I've
> no idea if that's possible, but I could not recommend it. That key sequence
> could do something undesirable in a future version of Access.
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "ali" <ali@discussions.microsoft.com> wrote in message
> news:C6CBDD7C-D9CE-4D4B-9100-CC387F51A7C5@microsoft.com...
> >I need to create a button which will run :
> >
> > Tools--> Database Utilities --> Compact and Repair Databases...
> >
> > ----------------------------------------------------------------------
> >
> > Thank you so much !
> >
> > --
> > Allen Phailat Wongakanit
>
>
 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
Krzysztof Pozorek [MVP] 12/20/2007 2:03 AM PST
   
  (...)
> You cannot programmatically compact the current database, because the shut
> down for compact cannot occur while the code is running.
(...)

This is truth, but this is not whole truth ;-) Following VBA code compacts
current database:

CommandBars.FindControl(id:=2071).accDoDefaultAction

K.P.
www.access.vis.pl


 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
Allen Browne 12/20/2007 4:17 AM PST
   
  Thanks for the suggestion.

I just tried this in Access 2007 SP1.
Access replied with this dialog:

You cannot compact the open database
by running a macro or Visual Basic code.

Instead of using a macro or code,
click the Microsoft Office Button,
point to Manage, and then click
Compact and Repair Database.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Krzysztof Pozorek [MVP]" <access@vis.pl> wrote in message
news:eIdz18uQIHA.280@TK2MSFTNGP03.phx.gbl...
> (...)
>> You cannot programmatically compact the current database, because the
>> shut down for compact cannot occur while the code is running.
> (...)
>
> This is truth, but this is not whole truth ;-) Following VBA code compacts
> current database:
>
> CommandBars.FindControl(id:=2071).accDoDefaultAction
>
> K.P.
> www.access.vis.pl

 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
Allen Browne 12/20/2007 4:39 AM PST
   
  Okay, it looks like this works in previous versions, but not A2007.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Allen Browne" <AllenBrowne@SeeSig.Invalid> wrote in message
news:%23f6j2HwQIHA.4740@TK2MSFTNGP02.phx.gbl...
> Thanks for the suggestion.
>
> I just tried this in Access 2007 SP1.
> Access replied with this dialog:
>
> You cannot compact the open database
> by running a macro or Visual Basic code.
>
> Instead of using a macro or code,
> click the Microsoft Office Button,
> point to Manage, and then click
> Compact and Repair Database.
>
> "Krzysztof Pozorek [MVP]" <access@vis.pl> wrote in message
> news:eIdz18uQIHA.280@TK2MSFTNGP03.phx.gbl...
>> (...)
>>> You cannot programmatically compact the current database, because the
>>> shut down for compact cannot occur while the code is running.
>> (...)
>>
>> This is truth, but this is not whole truth ;-) Following VBA code
>> compacts current database:
>>
>> CommandBars.FindControl(id:=2071).accDoDefaultAction
>>
>> K.P.
>> www.access.vis.pl

 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
Dale Fye 12/20/2007 7:29 AM PST
   
  K.P.

In all the threads I've read on Compact and Repair, this is the first time
I've ever seen that solution.


--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.



"Krzysztof Pozorek [MVP]" wrote:

> (...)
> > You cannot programmatically compact the current database, because the shut
> > down for compact cannot occur while the code is running.
> (...)
>
> This is truth, but this is not whole truth ;-) Following VBA code compacts
> current database:
>
> CommandBars.FindControl(id:=2071).accDoDefaultAction
>
> K.P.
> www.access.vis.pl
>
>
>
 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
Jeff C 6/10/2008 6:12 AM PST
   
 
--
Jeff C
Live Well .. Be Happy In All You Do


"Krzysztof Pozorek [MVP]" wrote:

> (...)
> > You cannot programmatically compact the current database, because the shut
> > down for compact cannot occur while the code is running.
> (...)
>
> This is truth, but this is not whole truth ;-) Following VBA code compacts
> current database:
>
> CommandBars.FindControl(id:=2071).accDoDefaultAction

I just wanted to say "THANKS" for this little piece if gold. I have a
process running every morning (Access/Office 2003) that bloats a 20 MB file
up to 130 MB+. Placing that line at the end of the process before
SetWarnings = True - compacts the database without a hitch.


>
> K.P.
> www.access.vis.pl
>
>
>
 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
Douglas J. Steele 6/10/2008 7:05 AM PST
   
  You might consider changing how your application works.

From the sounds of it, you're importing data into temporary tables in your
front-end, thus causing the bloating. Instead, import into temporary tables
in a temporary database. Tony Toews has sample code at
http://www.granite.ab.ca/access/temptables.htm

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Jeff C" <JeffC@discussions.microsoft.com> wrote in message
news:3AE12910-FC6B-4A10-9F4D-CBDD9E257296@microsoft.com...
>
> I just wanted to say "THANKS" for this little piece if gold. I have a
> process running every morning (Access/Office 2003) that bloats a 20 MB
> file
> up to 130 MB+. Placing that line at the end of the process before
> SetWarnings = True - compacts the database without a hitch.


 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
Jeff C 6/10/2008 4:05 PM PST
   
 
--
Jeff C
Live Well .. Be Happy In All You Do


"Douglas J. Steele" wrote:

> You might consider changing how your application works.
>
> From the sounds of it, you're importing data into temporary tables in your
> front-end, thus causing the bloating. Instead, import into temporary tables
> in a temporary database. Tony Toews has sample code at
> http://www.granite.ab.ca/access/temptables.htm
>

The database and process is one built for another and myself to generate
monthly reports. I didn't see the need to split it, but am re-thinking now
that you have pointed out Tony's idea - I like that and working through the
process will help me with other things.

Thanks much for your thoughts - "Salute" Doug

> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Jeff C" <JeffC@discussions.microsoft.com> wrote in message
> news:3AE12910-FC6B-4A10-9F4D-CBDD9E257296@microsoft.com...
> >
> > I just wanted to say "THANKS" for this little piece if gold. I have a
> > process running every morning (Access/Office 2003) that bloats a 20 MB
> > file
> > up to 130 MB+. Placing that line at the end of the process before
> > SetWarnings = True - compacts the database without a hitch.
>
>
>
 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
LIANA 6/11/2008 1:09 PM PST
   
 
Jeff C <JeffC@discussions.microsoft.com> escribió en el mensaje de noticias
0A7593B6-1401-43DB-BA70-6DDC2179B4B2@microsoft.com...
>
> --
> Jeff C
> Live Well .. Be Happy In All You Do
>
>
> "Douglas J. Steele" wrote:
>
> > You might consider changing how your application works.
> >
> > From the sounds of it, you're importing data into temporary tables in
your
> > front-end, thus causing the bloating. Instead, import into temporary
tables
> > in a temporary database. Tony Toews has sample code at
> > http://www.granite.ab.ca/access/temptables.htm
> >
>
> The database and process is one built for another and myself to generate
> monthly reports. I didn't see the need to split it, but am re-thinking
now
> that you have pointed out Tony's idea - I like that and working through
the
> process will help me with other things.
>
> Thanks much for your thoughts - "Salute" Doug
>
> > --
> > Doug Steele, Microsoft Access MVP
> > http://I.Am/DougSteele
> > (no e-mails, please!)
> >
> >
> > "Jeff C" <JeffC@discussions.microsoft.com> wrote in message
> > news:3AE12910-FC6B-4A10-9F4D-CBDD9E257296@microsoft.com...
> > >
> > > I just wanted to say "THANKS" for this little piece if gold. I have a
> > > process running every morning (Access/Office 2003) that bloats a 20 MB
> > > file
> > > up to 130 MB+. Placing that line at the end of the process before
> > > SetWarnings = True - compacts the database without a hitch.
> >
> >
> >


 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
David W. Fenton 12/20/2007 12:59 PM PST
   
  "Allen Browne" <AllenBrowne@SeeSig.Invalid> wrote in
news:ey#AJruQIHA.5980@TK2MSFTNGP04.phx.gbl:

> You cannot programmatically compact the current database, because
> the shut down for compact cannot occur while the code is running.
>
> Microsoft even provides a way to do it:
> RunCommand acCmdCompactDatabase
> but it can't work for the reason explained above.
>
> You can try stuffing keystrokes into the keyboard buffer with
> SendKeys. I've no idea if that's possible, but I could not
> recommend it. That key sequence could do something undesirable in
> a future version of Access.

Or you can use the TSI SOON (Shut One, Open New) add-in:

http://trigeminal.com/lang/1033/utility.asp?ItemID=8#8

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
Tony Toews [MVP] 12/20/2007 8:46 PM PST
   
  ali <ali@discussions.microsoft.com> wrote:

>I need to create a button which will run :
>
>Tools--> Database Utilities --> Compact and Repair Databases...

Do you mean the current MDB or the linked BE MDB?

If the linked BE MDB see my Backup, do you trust the users or
sysadmins? tips page for more info.
http://www.granite.ab.ca/access/backup.htm

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
  Return to Microsoft Communities  Notify me of replies