Open/Close DB 1 using DB 2 Code

G

Guest

Good afternoon

What is the best way to open and close an external database (DB 2) using code in DB 1? I have a form that opens for batching in DB 2 based on a refresh command and I would like to be able to compact and backup DB 2, but cannot since the database stays open. I would like be able to close DB 2, compact & backup, then re-open DB 2 so the batching is not interrupted

Any help will be greatly appreciated

Thank yo
Ke
 
D

Dev Ashish

What is the best way to open and close an external database (DB 2)
using code in DB 1? I have a form that opens for batching in DB 2
based on a refresh command and I would like to be able to compact and
backup DB 2, but cannot since the database stays open. I would like
be able to close DB 2, compact & backup, then re-open DB 2 so the
batching is not interrupted.

Depends how the db is open. If you are using OpenDatabase, then call
CloseDatabase; then DBEngine.CompactDatabase; then OpenDatabase again. If
you are using AUtomation, then call instance.CloseCurrentDatabase; do a
DBEngine.CompactDatabase, and then instance.OpenCurrentDatabase.

-- Dev
 
G

Guest

Dev

Thank you for your response...I have tried using opendatabase and close database before and cannot seem to get them to work...I have used Access Help extensively and I just do not seem to be getting anywhere. What kind of help are you willing to give in writing that code? I will be opening and closing several databases from within one database on a timer so that I can compact and backup them up. Any help you can provide will be greatly appreciated

Thank you once again for your response

Sincerel
Ke
 
G

Guest

De

Thank you for the response. I tried to send this once and it does not seem to have taken, so if this posts twice, sorry

I have tried using Opendatabase and close database before and can never seem to get it working right. Is it possible for you help me get started with that code? I have tried to use Access Help, but have gotten no where

Thanks so much for your help
Ke


----- Dev Ashish wrote: ----

What is the best way to open and close an external database (DB 2
using code in DB 1? I have a form that opens for batching in DB
based on a refresh command and I would like to be able to compact an
backup DB 2, but cannot since the database stays open. I would lik
be able to close DB 2, compact & backup, then re-open DB 2 so th
batching is not interrupted.

Depends how the db is open. If you are using OpenDatabase, then call
CloseDatabase; then DBEngine.CompactDatabase; then OpenDatabase again. If
you are using AUtomation, then call instance.CloseCurrentDatabase; do a
DBEngine.CompactDatabase, and then instance.OpenCurrentDatabase

-- De
 
D

Dev Ashish

.I have tried using opendatabase and close database before and cannot
seem to get them to work...I have used Access Help extensively and I
just do not seem to be getting anywhere.

Can you post the code you are using? Sometimes you need to refresh the
databases and other collections to reflect the latest changes.

-- Dev
 
G

Guest

Okay, but promise you want laugh! Haha Here it is

Sub closeX(

Dim clslocal5 As Databas
Set clslocal5 = opendatabase("C:\Documents and Settings\#ps8kem\Desktop\CLS Local 5.mdb"
clslocal5.Clos
Kill "N:\fas\Shared\Speciality Functions\Database Backups\CLS Local 5 Backup (Station).mdb
DBEngine.CompactDatabase "C:\Documents and Settings\#ps8kem\Desktop\CLS Local 5.mdb", "N:\fas\Shared\Speciality Functions\Database Backups\CLS Local 5 Backup (Station).mdb
FileCopy "N:\fas\Shared\Speciality Functions\Database Backups\CLS Local 5 Backup (Station).mdb", "C:\Documents and Settings\#ps8kem\Desktop\CLS Local 5.mdb
DBEngine.opendatabase clslocal

End Su

Thank
Ke


----- Dev Ashish wrote: ----

.I have tried using opendatabase and close database before and canno
seem to get them to work...I have used Access Help extensively and
just do not seem to be getting anywhere.

Can you post the code you are using? Sometimes you need to refresh the
databases and other collections to reflect the latest changes

-- De
 
T

TC

Jumping in with a side-comment:

You should always include the dbengine keyword when you use methods of the
dbengine object; eg. DBENGINE.opendatabase. Otherwise, strange DAO licencing
errors can occur, including but not limited to, inability to create an MDE.

HTH,
TC


Ken said:
Okay, but promise you want laugh! Haha Here it is:

Sub closeX()

Dim clslocal5 As Database
Set clslocal5 = opendatabase("C:\Documents and
Settings\#ps8kem\Desktop\CLS Local 5.mdb")
clslocal5.Close
Kill "N:\fas\Shared\Speciality Functions\Database Backups\CLS Local 5 Backup (Station).mdb"
DBEngine.CompactDatabase "C:\Documents and
Settings\#ps8kem\Desktop\CLS Local 5.mdb", "N:\fas\Shared\Speciality
Functions\Database Backups\CLS Local 5 Backup (Station).mdb"
FileCopy "N:\fas\Shared\Speciality Functions\Database Backups\CLS
Local 5 Backup (Station).mdb", "C:\Documents and
Settings\#ps8kem\Desktop\CLS Local 5.mdb"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top