Solved

In Code, close one database and open another

Posted on 2001-06-29
5
291 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…

687 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