Article View: comp.databases.ms-access
Article #466Re: COMPACT COMMAND BUTTON
From: GWsales
Date: Thu, 10 Jul 1997 00:00
Date: Thu, 10 Jul 1997 00:00
52 lines
2340 bytes
2340 bytes
On Wed, 09 Jul 1997 15:08:27 -0700, Ron Myer <myeron@ix.netcom.com>
wrote:
>TIMOTHY W. NEWTON wrote:
>>
>> Does anyone know how to create a command button on a form to compact the
>> database without have to leave it and use Accesses toolbar function.
>
>
>You can not compact on open database!
>You could create a Windows Macro to Compact the database either on
>opening or closing!
>
Right. From Access you can create a second application with a nice
front end that can do it to your main app. Include a command button
with this code: (assume your main app is DATA.MDB)
' First, run Repair on your app
DBEngine.RepairDatabase "c:\data.mdb"
' get rid of a temp file left behind from last time you ran _
this process
MyFile = Dir("c:\temp.mdb")
If MyFile = "temp.mdb" Then
Kill "c:\temp.mdb"
End If
DBEngine.CompactDatabase "c:\data.mdb", "c:\temp.mdb", ""
' it's always nice to backup your app before it's replaced
MyFile = Dir("c:\data.bak")
If MyFile = "data.bak" Then
Kill "c:\data.BAK"
End If
Name "c:\data.mdb" As "c:\data.BAK"
' this renames the temp, compacted file as your main app
Name "c:\temp.mdb" As "c:\data.mdb"
You might even reorder this somewhat and do the backup first
George Woody
*****************************************
Check out George Woody and the nutty antics
of his All Star Team of the Future at
http://www.execulink.com/~catcon/GeorgeWoody.htm
(c) 1997 George Woody Hobbies 'n Stuff
GWsales@execulink.com
Technical Details
Message-ID:
<33c43d15.10832104@news>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<01bc8c97$4b5d7e60$3475aace@adp547> <33C40BDB.1B21@ix.netcom.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 101bdd,59d8f0d5f78be206 X-Google-Attributes: gid101bdd,public X-Google-Thread: 111a5a,59d8f0d5f78be206 X-Google-Attributes: gid111a5a,public X-Google-Thread: 1034e6,59d8f0d5f78be206 X-Google-Attributes: gid1034e6,public X-Google-Thread: ff0ac,59d8f0d5f78be206 X-Google-Attributes: gidff0ac,public From: GWsales@execulink.com Subject: Re: COMPACT COMMAND BUTTON Date: 1997/07/10 Message-ID: <33c43d15.10832104@news> X-Deja-AN: 255854784 References: <01bc8c97$4b5d7e60$3475aace@adp547> <33C40BDB.1B21@ix.netcom.com> Organization: iSTAR internet Incorporated Newsgroups: comp.databases.ms-access,es.comp.bd.ms-access,microsoft.public.access.forms,microsoft.public.access.macros