Solved

In Code, close one database and open another

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

929 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

11 Experts available now in Live!

Get 1:1 Help Now