473,509 Members | 2,880 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Compact/Delete an access 97 db using VBA

2 New Member
Hello all,

Im having an issue with compacting an access 97 database. I am currently runing the following code which works fine ONCE! However, when I run the code a second time I get an error because the file i wish to create and compact already exists. Is there a way to delete the file before creating & compacting? a bit like......

' *** START

' *** desired code here
' delete Acces db "C:\compacted_db.mdb"

Application.DBEngine.CompactDatabase "C:\db_to_compact.mdb", "C:\compacted_db.mdb"

' *** END

if you coud also give any help on automatically zipping the compacted file "C:\compacted_db.mdb" (the desired result is to let a user email a set of files), then you truely would be a saint

Cheers, John
Feb 15 '08 #1
2 1869
sierra7
446 Recognized Expert Contributor
Hi
You might want to read the 'Microsoft Scripting Runtime' thread which is running at present as this shows more sophisticated ways of handling files.

However, the quick and dirty way is to check whether the file exists and then delete it using the DIR() and Kill() functions. So it might look something like this (NOT TESTED!!)

Expand|Select|Wrap|Line Numbers
  1. If Dir("C:\compacted_db.mdb") = "compacted_db.mdb" Then Kill("C:\compacted_db.mdb")
I can't help you too much on zipping files but WinZip supports command line instructions but you need to download an Add-On from their site
After which you may be able to run something like
Expand|Select|Wrap|Line Numbers
  1.  Dim stAppName As String 
  2.     stAppName = "WinZip C:\compacted_db.mdb, C:\compacted_db.zip"
  3.     Call Shell(stAppName, 1)
  4.  
but you will need to check the WinZip syntax

S7
Feb 18 '08 #2
BinDogg
2 New Member
Thanks S7

that works a treat and its the simplist bit of code to write (even if it is dirty).

i'll leave the zip feature for now as if a user can't zip a file then they should'nt be using a computer!

Once again many thanks
Feb 19 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2588
by: lestersal | last post by:
How would I compact a database on Open using code? I presume I'd have to use the Autoexec macro but what code do I put in the procedure called by Autoexec? Thanks, Alistair
13
10392
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...
7
2347
by: me | last post by:
i run a script which compacts a backend mdb at midnight when no one is connected to the backend. I compact it on the server. But this means that we need an extra license for Office to have it...
3
2360
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...
6
5562
by: KEVIN97810 | last post by:
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...
3
5557
by: Paolo | last post by:
Hi, I am trying to compact and repair my database, however every time I try it comes up a message saying: Table: "TempMSysAccessObject already exists", whenever I try to look for this table I...
2
2447
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...
8
2688
by: rdemyan via AccessMonster.com | last post by:
I've converted my application from A2K format to A2003 format. I tried to follow Allen Browne's protocol in getting my app into A2003 (although I was unable to find informtion on the conversion...
2
5129
by: Icarus | last post by:
I've got several Access 2000 databases that are currently being run with Access 2007. When the databases close, I've got them set to compact on close. This creates the database1.mdb file,...
0
7237
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,...
0
7416
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...
1
7073
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...
1
5062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4732
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...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1571
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 ...
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
443
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...

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.