Solved

Compact Access Database Via Batch File (Database uses MDW File)

Posted on 2004-09-02
5
1,602 Views
Last Modified: 2012-06-27
OK, here goes.

I have created the On Timer Event that will close any open databases at 8:30 PM. This works great.

I have batch files that will compact these databases at 8:35 PM.

Contents of batch file:

"C:\Program Files\Microsoft Office\Office\MSAccess.exe" "\\targetserver\databases\database.mdb" /compact "\targetserver\databases\newdatabase.mdb"

Then I just delete the old database and rename the new database to the old.

My problem is that I have one database that uses an *.mdw file.

Normally, the end user clicks on a shortcut on their desktop to access the database and is prompted for credentials.

Contents of shortcut:

"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" "\\targetserver\databases\database.mdb" /wrkgrp "\\targetserver\databases\mdwfile.mdw"

When I try to run the batch file to compact the database, I get "Database In Use" error.

Do I need to login to compact? I tried changing script to included login credentials, but this will only open the database.

Any help would be appreciative.
0
Comment
Question by:efrimpol
5 Comments
 
LVL 84
ID: 11965163
You won't be able to compact a db which is in use. There's really no way around this, other than using code within the database to "kick out" users after xx minutes of inactivity ... although there are some 3rd party utilities which may be able to do this.

You can try altering the command line to use a default user/pass:

"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" "\\targetserver\databases\database.mdb" /wrkgrp "\\targetserver\databases\mdwfile.mdw" /user="Bob" /pwd="bobspassword"
0
 
LVL 6

Author Comment

by:efrimpol
ID: 11965340
Was able to solve before I read your reply.

Here is the solution:

"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" "\\targetserver\databases\database.mdb" /wrkgrp "\\targetserver\databases\mdwfile.mdw" /user="user" /pwd="password" /compact "\\targetserver\databases\compacteddatabase.mdb"

As far as open database issue, I have inserted this event on the form that first opens when the database is opened. This is located in the OnTimer Event. I sent the timer to 55000, or 55 seconds:

    Dim locTime As String
    Dim locTime2 As String
    Dim locA As Long
       
    locTime = Time
    locTime2 = locTime
   
    locA = InStr(locTime, " ")
    Mid(locTime2, locA - 2, 2) = "00"
    locTime2 = Trim(locTime2)
     
    If locTime2 = "8:00:00 PM" Then
    Application.Quit
    End If

The compact will run at 8:15 PM (just to be on the safe side).

The combination will close any open databases, then compact those databases. I just have to write the batch file to copy the old databases to a different location, then rename the compacted databases to the old name.

Can't wait to see how it runs.

By the way, because I am compacting multiple databases, I created a batch files that calls all the other compact batch files. This is the file that I schedule.

Batch file scheduled contents.

VER | TIME > c:\start.txt
call c:\runcompact1.bat
call c:\runcompact2.bat
.
.
VER | TIME > c:\end.txt

This will create the start and end text files that give me that start and ending times.

Cool, huh?

You're welcomed to the 40 points just for replying. How do I award them?
0
 

Expert Comment

by:mperez1216
ID: 14130141
ok to close
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 14147986
PAQed with points refunded (20)

modulo
Community Support Moderator
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now