Solved

In Code, close one database and open another

Posted on 2001-06-29
5
285 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

726 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