473,803 Members | 3,752 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Compact MDB

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.

Nov 13 '05 #1
6 5579
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
re******@pcdata sheet.com
www.pcdatasheet.com
"KEVIN97810 " <ke********@aol .com> wrote in message
news:20******** *************** ****@mb-m05.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.

Nov 13 '05 #2
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.qui t statement.

Public Function AutoCompactCurr entProject()
Dim fs, f, s, filespec
Dim strProjectPath As String, strProjectName As String
strProjectPath = Application.Cur rentProject.Pat h
strProjectName = Application.Cur rentProject.Nam e
filespec = strProjectPath & "\" & strProjectName
Set fs = CreateObject("S cripting.FileSy stemObject")
Set f = fs.GetFile(file spec)
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.Set Option ("Auto Compact"), 1 'compact app
Else
Application.Set Option ("Auto Compact"), 0 'no don't compact app
End If
End Function

"PC Datasheet" <no****@nospam. spam> wrote in message
news:bc******** ***********@new sread1.news.pas .earthlink.net. ..
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
re******@pcdata sheet.com
www.pcdatasheet.com
"KEVIN97810 " <ke********@aol .com> wrote in message
news:20******** *************** ****@mb-m05.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.


Nov 13 '05 #3
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.

Nov 13 '05 #4
KEVIN97810 wrote:
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.ba t" For Output As #hFile
Print #hFile, "echo off"
Print #hFile, "cls"
Print #hFile, "echo compacting the Database.."
Print #hFile, "start /wait """ & SysCmd(acSysCmd AccessDir) &
"msaccess.e xe"" " & gdbCurrent.name & " /compact"
Print #hFile, ""
Print #hFile, "echo Re-Launching the Database.."
Print #hFile, "start """ & SysCmd(acSysCmd AccessDir) &
"msaccess.e xe"" " & 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.ba t", vbMaximizedFocu s)
Application.Qui t acQuitSaveNone

End Sub

--
This sig left intentionally blank
Nov 13 '05 #5
Paradigm wrote:
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.qui t statement.

Public Function AutoCompactCurr entProject()
Dim fs, f, s, filespec
Dim strProjectPath As String, strProjectName As String
strProjectPath = Application.Cur rentProject.Pat h
strProjectName = Application.Cur rentProject.Nam e
filespec = strProjectPath & "\" & strProjectName
Set fs = CreateObject("S cripting.FileSy stemObject")
Set f = fs.GetFile(file spec)
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.Set Option ("Auto Compact"), 1 'compact app
Else
Application.Set Option ("Auto Compact"), 0 'no don't compact app
End If
End Function


Interesting idea. I'd suggest removing the use of the FileSystemObjec t
and using native VBA to get the file size:

s = CLng(FileLen(fi lespec) / 1000000) 'convert size

Thanks for the idea...
--
'---------------
'John Mishefske
'---------------
Nov 13 '05 #6
If you are using A2000 or later you can set the Compact On Close option in
Tools>Options.

Peter Russell

KEVIN97810 previously wrote:
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.


Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
5081
by: James Franklin | last post by:
Hi, I have a number of databases in A2K, written on different machines with different installations of Office. I have found that compacting a database while it is open regularly fails, seemingly at random. This is especially annoying as I usually set the Compact on Close setting in Tools/Options to true. Has anyone else experienced this and is there a fix? Thanks for any help,
13
10422
by: Larry L | last post by:
Access is noted for bloating a database when you add and delete records frequently. I have always had mine set to compact on close, and that works great. Now after everyone's advice I split my database, so the data is in a second (back-end) database with all the tables linked. However, now when I close the database, it compacts the front end, since that's what's open, and the back-end grows. I now have to manually open and close the...
3
2379
by: Trevor Hughes | last post by:
Hello All I have a database (Access 2000, running on Win 2000), which suffers from bloat over a period of time. In order to solve the problem I set the option to compact on exit. This however has caused a problem. The permissions of the mdb file which are set to Everyone-Full control, are reset when the database is compacted. The end result is the the users get a message saying Access cannot locate the database. I can run it with...
2
2471
by: Greg Strong | last post by:
Hello All, I've written code in a test database with test data. Everything seems to be working except compact database in VB code per http://www.mvps.org/access/general/gen0041.htm. The reason I say this is the auto number fields are NOT being reset to zero. I delete the data from tables with action delete queries, then call the compact DB code which is followed by importing data to tables and subsequent append queries to other tables....
1
4830
by: robert demo via AccessMonster.com | last post by:
In my startup routine, I have the following code: s = CLng(FileLen(filespec) / 1000000) If s > 5 Then 'FIRST, BACKUP THE FRONT END If BackupFrontEnd = False Then Exit Function End If
6
2284
by: MLH | last post by:
I just used Tools / Database Utilities / Compact Database in Access 97 for the first time. Unlike Access 2.0, it does not ask me to furnish a filename for it to compact into. It just launched headlong into a process that, after the fact, had the result of overwriting the 44-meg previous size file into an 8-meg file of the same name. Has anyone ever experienced a data-loss during such a compact operation under A97? Surely, the access...
6
2312
by: owengoodhew | last post by:
Hi, I am responsible for maintaining an MS Access 97 Database that reliably becomes corrupt following a compact......... About the Database: The database is made up of three linked databases, data, input and output. The files all share the same table structures. Recently the input database started growing in size and it became necessary to compact the databases more frequently. Following the compact of the
5
3358
by: bob | last post by:
Hi Using 2003 - targeting the compact framework (c#), but would like to do most development using the full.net (manually leaving out stuff not in the compact framework). Q. Trying to find a way of converting a project to have builds for both compact and full. Project properties doesn't seem to help Thanks
2
2783
by: Ron | last post by:
Hi All, Using WinXP pro/Access 2000. I have a database that's been used for about 5 months. Transferred lots of data from a dos based program, then the users have been using it for that 5 months. About 180000 records in one of the main files (maybe 25000 new since the dos conversion). Been having some speed issues crop up along the way (much faster to do same reports when I first transferred the data than now, with the new 25000...
9
3993
by: Ron | last post by:
New discovery. If I take a perfectly good database, and "compact/repair" on it with Access 2000 (seems to be at multiple sites--I've tried it with my system here, at another office on an entirely different network), it damages the file somehow. The user's machine that did the compact/repair can see the file fine. But any networked user can't get in. I can double click on a good database file from any user (over the network) and it...
0
9703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9566
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10555
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10317
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2974
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.