Solved

In Code, close one database and open another

Posted on 2001-06-29
5
252 Views
Last Modified: 2006-11-17
I have a very large database, which I want to compact on close SOMETIMES.

I know that there is the "Compact on Close" option in the tools of the database, but was hopping that I could do this through code so that I could prompt the user to be sure that they want to compact now.

In trying to solve this problem, I have found that I can compact a closed database through code. I therefore created a second very small database, which I was able to code to prompt the user and (if answered yes) compact the first database.

So my problem now is how do I close the first large database, and open the second smaller database in code?

In asking fellow developers, it was suggested that I create a batch file to open the first database and then the second.

I believe that there is a cleaner way to do this inside of Access.

Please help, knowing the total story above if anyone could suggest a totally different approach, I would be interested in that as well.

Thank you,

Michael
0
Comment
Question by:MADamiano
  • 2
  • 2
5 Comments
 
LVL 14

Expert Comment

by:mgrattan
ID: 6239502
You might want to try an add-in from Trigeminal Software.  It's free, and it has the ability to open other databases, compact them, and then re-open them or do some other process.

http://www.trigeminal.com/utilities/TsiSoon90.zip
0
 
LVL 11

Accepted Solution

by:
LambertHeenan earned 100 total points
ID: 6239702
To close the current db and open another in code you can do this...

Const strCompactorMDB = "X:\SomePath\SomeDatabase.mdb"
Dim strCommandLine
Dim dbl_D as Double

  strCommandLine = Quote(SysCmd(acSysCmdAccessDir) & _
     "MSACCESS.EXE") & " " & Quote(strCompactorMDB) & _
     " /cmd " & Quote(CurrentDb.Name)
   dbl_D = Shell(strCommandLine, vbNormalFocus)
   Application.Quit acQuitSaveNone ' close the current database

... Note the line contiumation characters in the above code

Helper function...

Function Quote(aString) As String
    Quote = """" & aString & """"
End Function

The /cmd switch for Access allows you to pass an arbirary parameter on the command line. In this case we are passing the name of the current database.

Then your compacting database (named in strCompactorMDB) can retrieve the name of the database to compact using the command() function. That way the user does not need to enter tne name of the database to compact.
0
 
LVL 1

Author Comment

by:MADamiano
ID: 6239888
What a simple great solution!
I just tried it out.
Fantastic, Thank you.
0
 
LVL 11

Expert Comment

by:LambertHeenan
ID: 6240847
Thanks for the compliment. Glad to have helped.
0
 
LVL 1

Author Comment

by:MADamiano
ID: 6984318
Thanks for the help.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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…

758 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