473,625 Members | 3,353 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Interesting approach for compacting on close

To further follow up on my last post regarding the docmd.quit vs.
Application.qui t using access 2007, I noticed that docmd.quit will correctly
compact the database (program file) if you have the "Compact on Close"
option set for the current database.

However, even with Compact on Close set, if you use the Application.Qui t
acQuitSaveNone, the compacting will not fire.

This behavior actually seems desirable, as you can now make a program
smarter upon exiting your program. If you have an exit button that performs
some housekeeping type procs, backup, etc., then exits the access program,
you can take advantage of the behavior above (docmd.quit vs.
application.qui t) to determine if you should compact.

To do this, make sure "Compact on Close" is set for the current database
(your access program file), then run the following function on your exit
button.

Hope this helps people who might have been looking for a similar solution.
This behavior works in Access 2007, but I'm not sure about 2003.
Public Function ExitButton() As Boolean
Dim progsize As Long, compactyn As Integer
progsize = FileLen(Current Db.Name)
If progsize 40000000 Then '=40 MB. Set a reasonable number where you
think the program should be compacted
compactyn = -1
Else
compactyn = 0
End If
'MsgBox "Program size is now: " & progsize & " bytes. Setting compact on
close to: " & compactyn
'Call AutomatedBU(0) 'run any of your procs, etc.
'Call CloseOpenTabs 'a routine to close out all open forms
'
Exit_btnExit_Cl ick:
'
If compactyn = -1 Then
DoCmd.Quit 'the docmd.quit will correctly run the compact on close
Else
Application.Qui t acQuitSaveNone 'For whatever reason, this command
Ignores the "Compact on Close" setting
End If
'
' Exit Function

Err_btnExit_Cli ck:
If Err = 2450 Then 'user mistankingly closed while previewing a report
Exit Function
ElseIf Err = 2501 Then
Resume Next
Else
MsgBox Err.Description & " - " & Err.Number & ", Function:
ExitButton", vbCritical
Resume Exit_btnExit_Cl ick
End If
End Function

Oct 30 '08 #1
32 2331
Andy wrote:
To further follow up on my last post regarding the docmd.quit vs.
Application.qui t using access 2007, I noticed that docmd.quit will
correctly compact the database (program file) if you have the
"Compact on Close" option set for the current database.
Most experienced developers consider Compact-On-Close to be at best, useless
and more often, a pretty bad idea.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Oct 30 '08 #2
I appreciate the comment and have read similar comments before, however, if
anything happens to the front-end on the compact, worst case is you grab a
new copy of the FE.

Compact on close has no affect on the BE, it only operates on the file you
have opened, not linked tables, etc.

Can you give examples of why it's a bad idea?

"Rick Brandt" <ri*********@ho tmail.comwrote in message
news:WY******** ********@flpi14 7.ffdc.sbc.com. ..
Andy wrote:
>To further follow up on my last post regarding the docmd.quit vs.
Application.qu it using access 2007, I noticed that docmd.quit will
correctly compact the database (program file) if you have the
"Compact on Close" option set for the current database.

Most experienced developers consider Compact-On-Close to be at best,
useless and more often, a pretty bad idea.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Oct 30 '08 #3
"Andy" <PC*****@PCESof t.invalidwrote in message
news:IN******** ********@flpi15 0.ffdc.sbc.com. ..
To further follow up on my last post regarding the docmd.quit vs.
Application.qui t using access 2007, I noticed that docmd.quit will
correctly compact the database (program file) if you have the "Compact on
Close" option set for the current database.

However, even with Compact on Close set, if you use the Application.Qui t
acQuitSaveNone, the compacting will not fire.
Hmm ... I've just tried it in A2003 and it *does* work. Are you up to date
with SPs and the like?

Keith.
www.keithwilby.com

Oct 30 '08 #4
I'm using access 2007, with service pack 1.

Maybe Microsoft planned it so that the application.qui t with the nosave
option ignores the compact?

"Keith Wilby" <he**@there.com wrote in message
news:49******** @glkas0286.gree nlnk.net...
"Andy" <PC*****@PCESof t.invalidwrote in message
news:IN******** ********@flpi15 0.ffdc.sbc.com. ..
>To further follow up on my last post regarding the docmd.quit vs.
Application.qu it using access 2007, I noticed that docmd.quit will
correctly compact the database (program file) if you have the "Compact on
Close" option set for the current database.

However, even with Compact on Close set, if you use the Application.Qui t
acQuitSaveNone , the compacting will not fire.

Hmm ... I've just tried it in A2003 and it *does* work. Are you up to
date with SPs and the like?

Keith.
www.keithwilby.com
Oct 30 '08 #5
"Andy" <PC*****@PCESof t.invalidwrote in message
news:Ba******** *********@flpi1 50.ffdc.sbc.com ...
>I appreciate the comment and have read similar comments before, however, if
anything happens to the front-end on the compact, worst case is you grab a
new copy of the FE.
Why not then just grab a new copy of the FE with each new session? It's not
rocket science and has many benefits, most notably here the mitigation of
the compact on close issue.

Keith.

Oct 30 '08 #6
Mainly because this is a shareware runtime app that a user can download. I
think setting up a batch file, and automating that into the program
launching shortcut might be a more difficult thing in my case.

"Keith Wilby" <he**@there.com wrote in message
news:49******** **@glkas0286.gr eenlnk.net...
"Andy" <PC*****@PCESof t.invalidwrote in message
news:Ba******** *********@flpi1 50.ffdc.sbc.com ...
>>I appreciate the comment and have read similar comments before, however,
if anything happens to the front-end on the compact, worst case is you
grab a new copy of the FE.

Why not then just grab a new copy of the FE with each new session? It's
not rocket science and has many benefits, most notably here the mitigation
of the compact on close issue.

Keith.
Oct 30 '08 #7
Andy wrote:
I appreciate the comment and have read similar comments before,
however, if anything happens to the front-end on the compact, worst
case is you grab a new copy of the FE.

Compact on close has no affect on the BE, it only operates on the
file you have opened, not linked tables, etc.

Can you give examples of why it's a bad idea?
First off I see almost no reason a front end should ever need a compact.
Second there are cases where compacting messes up the file. For the (more
reasonable) occassional compact I would initiate it manually rather than
blindly doing it every time my app runs.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Oct 30 '08 #8
I wish it never needed a compact. This programs is quite large fully
compacted, and makes extensive use of temp tables, which tends to bloat the
FE significantly. I even tried off-loading the temp tables to a
"workspace.accd b" local file, and it didn't solve the FE bloat. Years ago I
went over everything, and all recordsets are properly closed after they are
used, and the database variable set to nothing, so my theory has always been
the temp tables angle as the reason for the bloat.

I used to put up a message if the FE had bloated 3-4X the normal size, and
normal users would never see the message. Power users, on the other hand,
could get the message after a day or 2 of usage.
"Rick Brandt" <ri*********@ho tmail.comwrote in message
news:sz******** *********@nlpi0 65.nbdc.sbc.com ...
Andy wrote:
>I appreciate the comment and have read similar comments before,
however, if anything happens to the front-end on the compact, worst
case is you grab a new copy of the FE.

Compact on close has no affect on the BE, it only operates on the
file you have opened, not linked tables, etc.

Can you give examples of why it's a bad idea?

First off I see almost no reason a front end should ever need a compact.
Second there are cases where compacting messes up the file. For the (more
reasonable) occassional compact I would initiate it manually rather than
blindly doing it every time my app runs.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Oct 30 '08 #9
"Andy" <PC*****@PCESof t.invalidwrote in
news:Ba******** *********@flpi1 50.ffdc.sbc.com :
I appreciate the comment and have read similar comments before,
however, if anything happens to the front-end on the compact,
worst case is you grab a new copy of the FE.
Which accounts for the "useless" part of what Rick said.

And given the possibility of corrupting a front end (which shouldn't
ever need to be compacted in the first place), why would you want to
have to deal with helping the end user recover a working copy of the
front end if something goes wrong?

Compact On Close is a stupid feature, as badly implemented as it
could possibly be.

No one, NOT ONE USER, should ever have it turned on in any
circumstances.

But I have no strong opinions on the subject, myself.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Oct 30 '08 #10

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

Similar topics

2
3279
by: ColinWard | last post by:
Hi I have a database that I would like to be able to compact when the exit button on the main form is clicked. Can anyone help with this? TIA Colin *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
1
2126
by: Rene Crespo | last post by:
Hello, Following my earlier posting regarding my Error On Exit: --------------------------------------------------------- I get the following error when compacting my MSAccess 2000 database: 'TempMsysAccessObjects' Already Exists" I have read the help file with this topic but can't seem to eliminate the
5
2645
by: Peter Verhelst | last post by:
Hello, Currently I am running an Access database on a windows WTS server, running Microsoft Windows 2000 server 5.00.2195 Service Pack 3. This database should be accessible for everybody in our network, so for the time being, I have changed the permission for the .mdb file to Everone -> Full control (I know this is not professional, but I'll sort out the security issues later). When this database is opened, and closed again, it is...
5
2965
by: lappy | last post by:
Hello, I have written a small programme to compact an access 97 database. Dim je As New JRO.JetEngine ' Compacts database Data.Mdb to Data2.mdb. je.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\Dump\DataOld.Mdb", _ "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\Dump\Data.Mdb"
11
2276
by: darcykahle | last post by:
I have stumbled upon an interesting issue with regard to compaction of an access frontend database which resides on a DFS target that utilizes FRS to mirror the sharepoint, and I was wondering if anyone knows a way to overcome it. For those who are unaware of DFS or FRS, DFS stands for Distributed File System, and basically involves "mounting" various sharepoints that reside on various computers underneath one special sharepoint. When...
3
1355
by: Pachydermitis | last post by:
Hi everyone, This is not the forum for Windows permissions, but I figure this has to be an issue one of you access experts has had to deal with. I have an XP system with an access db on it. The directory has permissions so that the warehouse user can read/write. Everything works great until I log in as admin and open the access database. When the database closes it compacts and rewrites itself to the directory. Now the permissions on...
7
2060
by: DavidB | last post by:
I have a standard FE/BE database. I'd like to be able to have a button on each db that allows the admin to compact the database. I am using the following code to perform the compact. Private Sub bCompact_Click() On Error GoTo Err_bCompact_Click CommandBars("Menu Bar").Controls("Tools").Controls("Database utilities").Controls("Compact and repair database...").accDoDefaultAction
1
2272
by: Slez via AccessMonster.com | last post by:
I do a routine compact and repair on a back end MS Access 2002 database. This time I had something peculiar occur. The compact started as normal, than the following error message popped up (I shortened the path for this post): Microsoft Access can't delete G:\......\MW-Estimate_be.mdb after compacting it. The compacted database has been named G:\......\db1.mdb. It then goes on to explain that the original database wasn't deleted...
3
3841
by: DSSMaster | last post by:
I am trying to use windows scheduler to compact a database. In the task run line I have the following: "C:\Program Files\Microsoft Office\OFFICE11 MSACCESS.EXE" _ "C:\Files\Access\Sacroc.mdb" /compact In the task start in box I have the following "C:\Program Files\Microsoft Office\OFFICE11" The database starts to compact and then returns the message
0
8256
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
8189
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
8694
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
8635
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...
1
8356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8497
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4089
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1500
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.