A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

How to compact a database using macro or vba?



 
 
Thread Tools Display Modes
  #1  
Old June 9th, 2007, 01:30 PM posted to microsoft.public.access
Rodrigo Borges[_3_]
external usenet poster
 
Posts: 12
Default How to compact a database using macro or vba?

I have a DB tht loads a form when opened. I want to run a compact DB every
time I open and close the DB.

Is there a away to accomplis that using macro?

  #2  
Old June 9th, 2007, 01:45 PM posted to microsoft.public.access
Wayne-I-M
external usenet poster
 
Posts: 3,674
Default How to compact a database using macro or vba?

Hi Rodrigo

You don't need a macro.

Use
Tools
Options
General
Compact on Close.

It would be pointless compacting on open in this case - as the DB has
already been compacted last time it was closed.

--
Wayne
Manchester, England.



"Rodrigo Borges" wrote:

I have a DB tht loads a form when opened. I want to run a compact DB every
time I open and close the DB.

Is there a away to accomplis that using macro?

  #3  
Old October 22nd, 2008, 08:43 AM posted to microsoft.public.access
Mick
external usenet poster
 
Posts: 111
Default How to compact a database using macro or vba?

The question as I understood it asked HOW to compact and repair in Access
2007 not should you!

I am a Developer and would regularly compact the database in 2000-2003
format since I move alot of data around.

QUESTION: How does one compact and repair a database with a macro or vba
  #4  
Old October 22nd, 2008, 09:15 AM posted to microsoft.public.access
Stefan Hoffmann
external usenet poster
 
Posts: 991
Default How to compact a database using macro or vba?

hi Mick,

Mick wrote:
The question as I understood it asked HOW to compact and repair in Access
2007 not should you!

???

I am a Developer and would regularly compact the database in 2000-2003
format since I move alot of data around.

QUESTION: How does one compact and repair a database with a macro or vba

GIYF:

http://support.microsoft.com/kb/230501
http://msdn.microsoft.com/en-us/library/bb237197.aspx



mfG
-- stefan --
  #5  
Old March 23rd, 2010, 03:16 PM posted to microsoft.public.access
Maj_USA_Ret[_2_]
external usenet poster
 
Posts: 1
Default How to compact a database using macro or vba?

Request how to add Compact and Repair action to Macro.
Trying to create Macro that deletes many old and large tables, then runs
Compact and Repair, then imports new tables through ODBC.
Currently:
Step 1: Delete old tables.
Step 2: Run the compact and repair from the tools menu
Step 3: Import.
Intent is to combine all three steps above into single button, one click
macro.
Thankx

"Wayne-I-M" wrote:

Hi Rodrigo

You don't need a macro.

Use
Tools
Options
General
Compact on Close.

It would be pointless compacting on open in this case - as the DB has
already been compacted last time it was closed.

--
Wayne
Manchester, England.



"Rodrigo Borges" wrote:

I have a DB tht loads a form when opened. I want to run a compact DB every
time I open and close the DB.

Is there a away to accomplis that using macro?

  #6  
Old March 23rd, 2010, 10:29 PM posted to microsoft.public.access
Paul Shapiro
external usenet poster
 
Posts: 635
Default How to compact a database using macro or vba?

This VBA function compacts a db:
Public Function pjsCompactDatabase( _
dbDataBase As DAO.Database _
) As Boolean
'Comments : Closes the database and compacts it
Dim strDBFileName As String, strDBFileNameTemp As String

'Get current database name and create name to compact into
strDBFileName = dbDataBase.Name
strDBFileNameTemp = strDBFileName & ".tempCompactNewData.mdb"

'Close the existing database and flush all writes to disk
dbDataBase.Close
Set dbDataBase = Nothing
DBEngine.Idle dbRefreshCache
DoEvents

'Compact the database to a new, temporary file name.
DBEngine.CompactDatabase srcName:=strDBFileName,
dstName:=strDBFileNameTemp
DBEngine.Idle dbRefreshCache
DoEvents

'Delete the existing db and rename the temp file to the existing name.
Kill strDBFileName
Name strDBFileNameTemp As strDBFileName

'Indicate success
pjsCompactDatabase = True
End Function

"Maj_USA_Ret" wrote in message
...
Request how to add Compact and Repair action to Macro.
Trying to create Macro that deletes many old and large tables, then runs
Compact and Repair, then imports new tables through ODBC.
Currently:
Step 1: Delete old tables.
Step 2: Run the compact and repair from the tools menu
Step 3: Import.
Intent is to combine all three steps above into single button, one click
macro.
Thankx

"Wayne-I-M" wrote:

Hi Rodrigo

You don't need a macro.

Use
Tools
Options
General
Compact on Close.

It would be pointless compacting on open in this case - as the DB has
already been compacted last time it was closed.

--
Wayne
Manchester, England.



"Rodrigo Borges" wrote:

I have a DB tht loads a form when opened. I want to run a compact DB
every
time I open and close the DB.

Is there a away to accomplis that using macro?


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:48 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.