473,666 Members | 2,571 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_d b.mdb"

Application.DBE ngine.CompactDa tabase "C:\db_to_compa ct.mdb", "C:\compacted_d b.mdb"

' *** END

if you coud also give any help on automatically zipping the compacted file "C:\compacted_d b.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 1876
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
2597
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
10414
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...
7
2357
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 installed on the server so we can compact it on the server. Can I compact the mdb without needing Office installed maybe using VB or something else? Thanks, Chris
3
2371
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...
6
5569
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 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.
3
5566
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 cannot find it anywhere... Any clues... Already went into the help file and nothing... Also try to copy my database and the same message comes up
2
2459
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....
8
2700
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 process). Lots of decompiling and lots of compacting of the original application in A2000. Then the app was opened in A2003 and compacted, decompiled and compacted. Next I imported everything into a blank A2003 database. Then this db was...
2
5137
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, however once the database has finished compacting and the database is closed, the database1.mdb still remains in the folder. As a result, the next time the database closes, it creates a database2, which it does not delete, and this continues each time...
0
8454
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
8363
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,...
1
8561
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
7389
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5672
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
4200
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
2776
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
2013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1778
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.