dbTalk Databases Forums  

Compact MDB

comp.databases.ms-access comp.databases.ms-access


Discuss Compact MDB in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
KEVIN97810
 
Posts: n/a

Default Compact MDB - 01-02-2005 , 06:49 PM






Hello to all,
Assume my mdb name is Cust.MDB. I want to compact & repair
the same Cust.MDB when the user exit the program. Is there a way you can do it
in code behind the EXIT button. I am dumping data from SQL to temp table and
also delete from these tables in Cust.MDB. This would cause the MDB to get
big. So I just want some code to compact and repair as user Exit from the
access database.

thanks a bunch.


Reply With Quote
  #2  
Old   
PC Datasheet
 
Posts: n/a

Default Re: Compact MDB - 01-02-2005 , 07:27 PM






The better thing to do is to just use the Kill command to delete Cust.mdb
and then recreate Cust.mdb and its tables.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
resource (AT) pcdatasheet (DOT) com
www.pcdatasheet.com


"KEVIN97810" <kevin97810 (AT) aol (DOT) com> wrote

Quote:
Hello to all,
Assume my mdb name is Cust.MDB. I want to compact &
repair
the same Cust.MDB when the user exit the program. Is there a way you can
do it
in code behind the EXIT button. I am dumping data from SQL to temp table
and
also delete from these tables in Cust.MDB. This would cause the MDB to
get
big. So I just want some code to compact and repair as user Exit from the
access database.

thanks a bunch.




Reply With Quote
  #3  
Old   
Paradigm
 
Posts: n/a

Default Re: Compact MDB - 01-03-2005 , 06:28 AM



I use the following function just before quiting the application to test for
a file saize and set the autocompact on close to true if the file is greater
than a certain size. This means I do not have to compact it everytime it
closes but only when a certain size has been exceeded. Call it just before
your application.quit statement.

Public Function AutoCompactCurrentProject()
Dim fs, f, s, filespec
Dim strProjectPath As String, strProjectName As String
strProjectPath = Application.CurrentProject.Path
strProjectName = Application.CurrentProject.Name
filespec = strProjectPath & "\" & strProjectName
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(filespec)
s = CLng(f.Size / 1000000) 'convert size of app from bytes to Mb's
If s > 3 Then 'edit the 3 (Mb's) to the max size you want
to allow your app to grow.
Application.SetOption ("Auto Compact"), 1 'compact app
Else
Application.SetOption ("Auto Compact"), 0 'no don't compact app
End If
End Function

"PC Datasheet" <nospam (AT) nospam (DOT) spam> wrote

Quote:
The better thing to do is to just use the Kill command to delete Cust.mdb
and then recreate Cust.mdb and its tables.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
resource (AT) pcdatasheet (DOT) com
www.pcdatasheet.com


"KEVIN97810" <kevin97810 (AT) aol (DOT) com> wrote in message
news:20050102194927.08116.00002894 (AT) mb-m05 (DOT) aol.com...
Hello to all,
Assume my mdb name is Cust.MDB. I want to compact &
repair
the same Cust.MDB when the user exit the program. Is there a way you
can
do it
in code behind the EXIT button. I am dumping data from SQL to temp
table
and
also delete from these tables in Cust.MDB. This would cause the MDB to
get
big. So I just want some code to compact and repair as user Exit from
the
access database.

thanks a bunch.






Reply With Quote
  #4  
Old   
thomas.tracy@gmail.com
 
Posts: n/a

Default Re: Compact MDB - 01-03-2005 , 06:45 AM



I have downloaded and use the compact addin from the Access MVP site.
Key challenge with this is the need to load the add in on any computer
that will use it, but it works very nicely from a single line calling
it from an exit button.


Reply With Quote
  #5  
Old   
Trevor Best
 
Posts: n/a

Default Re: Compact MDB - 01-03-2005 , 07:18 AM



KEVIN97810 wrote:
Quote:
Hello to all,
Assume my mdb name is Cust.MDB. I want to compact & repair
the same Cust.MDB when the user exit the program. Is there a way you can do it
in code behind the EXIT button. I am dumping data from SQL to temp table and
also delete from these tables in Cust.MDB. This would cause the MDB to get
big. So I just want some code to compact and repair as user Exit from the
access database.

thanks a bunch.

watch line wrapping. This was to compact at any time and would restart
the db but can be modified.

Sub compactme()
Dim hFile As Integer
hFile = FreeFile()
Open Environ("TEMP") & "\repair.bat" For Output As #hFile
Print #hFile, "echo off"
Print #hFile, "cls"
Print #hFile, "echo compacting the Database.."
Print #hFile, "start /wait """ & SysCmd(acSysCmdAccessDir) &
"msaccess.exe"" " & gdbCurrent.name & " /compact"
Print #hFile, ""
Print #hFile, "echo Re-Launching the Database.."
Print #hFile, "start """ & SysCmd(acSysCmdAccessDir) &
"msaccess.exe"" " & gdbCurrent.name
Print #hFile, "del c:\temp\repair.bat"
Print #hFile, "this will never execute and DOS will complain about
""Batch File Missing"" but user shouldn't see it"
Close #hFile
Debug.Print Shell(Environ("TEMP") & "\repair.bat", vbMaximizedFocus)
Application.Quit acQuitSaveNone

End Sub

--
This sig left intentionally blank


Reply With Quote
  #6  
Old   
John Mishefske
 
Posts: n/a

Default Re: Compact MDB - 01-03-2005 , 06:16 PM



Paradigm wrote:
Quote:
I use the following function just before quiting the application to test for
a file saize and set the autocompact on close to true if the file is greater
than a certain size. This means I do not have to compact it everytime it
closes but only when a certain size has been exceeded. Call it just before
your application.quit statement.

Public Function AutoCompactCurrentProject()
Dim fs, f, s, filespec
Dim strProjectPath As String, strProjectName As String
strProjectPath = Application.CurrentProject.Path
strProjectName = Application.CurrentProject.Name
filespec = strProjectPath & "\" & strProjectName
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(filespec)
s = CLng(f.Size / 1000000) 'convert size of app from bytes to Mb's
If s > 3 Then 'edit the 3 (Mb's) to the max size you want
to allow your app to grow.
Application.SetOption ("Auto Compact"), 1 'compact app
Else
Application.SetOption ("Auto Compact"), 0 'no don't compact app
End If
End Function
Interesting idea. I'd suggest removing the use of the FileSystemObject
and using native VBA to get the file size:

s = CLng(FileLen(filespec) / 1000000) 'convert size

Thanks for the idea...
--
'---------------
'John Mishefske
'---------------


Reply With Quote
  #7  
Old   
Peter Russell
 
Posts: n/a

Default Re: Compact MDB - 01-04-2005 , 06:52 AM



If you are using A2000 or later you can set the Compact On Close option in
Tools>Options.

Peter Russell

KEVIN97810 previously wrote:
Quote:
Assume my mdb name is Cust.MDB. I want to compact &
repair
the same Cust.MDB when the user exit the program. Is there a way you
can do it
in code behind the EXIT button. I am dumping data from SQL to temp
table and
also delete from these tables in Cust.MDB. This would cause the MDB to
get
big. So I just want some code to compact and repair as user Exit from
the
access database.

thanks a bunch.




Reply With Quote
Reply




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 On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.