Connect an Access DB to another running Access DB

W

Warrio

Hello!

Would it be possible to connect a Access database to another Access
Database?
I've used :
Dim MyDB as Access.Application
Set MyDB = CreateObject("Access.Application")
MyDB.OpenCurrentDatabase "C:\db2.mdb"

But the code above opens a new instance of db2.mdb even if it is already
running!
How can I get connected to db2.mdb without opening it a second time?

Thanks in advance.
 
D

Douglas J. Steele

What exactly do you mean by "connect a Access database to another Access
Database"?

You could try using GetObject instead of CreateObject to get the already
open instance, but I can't really figure out what you're trying to do.
 
A

Arvin Meyer [MVP]

Have you tried setting a reference to the second database? That will allow
you to use its forms, reports, and code. Linking to the tables of the second
database will allow you to use its tables.
 
A

Albert D. Kallal

Dim MyDB as Access.Application
Set MyDB = CreateObject("Access.Application")
MyDB.OpenCurrentDatabase "C:\db2.mdb"

But the code above opens a new instance of db2.mdb even if it is already
running!
How can I get connected to db2.mdb without opening it a second time?

Just delcare a new database ojbect...and go:

Dim db As DAO.Database
Dim rstCust As DAO.Recordset

Set db = OpenDatabase("C:\db2.mdb")

' now....

Set rstCust = db.OpenRecordset("select * from tblCustomers")

So, there is no need at all to launch antoher copy of ms-access if all you
want is to read data....
 
W

Warrio

The thing with referencing the db2 in db1 is that it works perfectly, but it
opens the form into bd1
and the problem is that I want to open a form in db2, give it the focus and
then close db1.

Thanks again!
 
W

Warrio

I found a way after all but it's very arranged!
Access has the option of creating a shortcut to a form and store it as an
AMF file (by drag & droping the form on windows folder)
so all what I tryed to do is to open this file with a shell command (Shell
"C:\OpenMyForm.amf").
However this shows an error "Invalid call procedure"
so I put C:\OpenMyForm.amf in a bat file and opend this bat file from vba
with Shell "C:\OpenMyForm.bat"
and IT WORKS even if it is arranged :0)

But I'm sure there is a way to do this in Access without all this
manipulations... so I'm still interested if anyone finds the answer..
Thanks for your help

PS: the shortcut file contains this:

[Shortcut Properties]
AccessShortcutVersion=1
DatabaseName=Nouveau Microsoft Access Application.mdb
ObjectName=Form2
ObjectType=Form
Computer=PRIVA-INFO
DatabasePath=C:\Documents and Settings\Tarek\Mes documents\Nouveau Microsoft
Access Application.mdb
EnableRemote=0
CreationTime= 1c712f58993fa94
Icon=263
 

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