how to open another database using VBA

ryetee

Registered User.
Local time
Today, 23:11
Joined
Jul 30, 2013
Messages
965
Whilst looking how to do this I found this thread http://www.access-programmers.co.uk/forums/showthread.php?t=129779

It seems that the code that works is

dim accapp as access.application

set accapp = new access.application

accapp.opencurrentdatabase("c:\whatever\blah.mdb")
accapp.visible = true

I'm trying to load an accdb file so have replaced blah.mdb with blah.accdb. I don't believe this should cause any problems.

I have tried this and it works to a fashion.

It loads the database blah.accdb for a nano second!

If I step through the code blah.accdb becomes visible when "accapp.visible = true" is executed. However the following line is Exit Sub and once this is executed the database disappears.

If when "accapp.visible = true" is executed and before executing "End Sub" I switch to blah.accdb and click one of the options and then execute "End Sub" then blah.accdb remains open.


I am using access 2010 and one of the comments states "This works perfectly in Access 2010. Thanks!"



I'm obviously missing something. Does anyone know what?
 
This link explains and shows how to do it.

I actually had found this page but wasn't sure what point 3,4 and 5 meant.
That said the code after point 5 is more or less what I have. I didn't have the ",True" after the file name on the OpenCurrentDatabase line. I left it as the default false as I was not sure what "Exclusive as Boolean" meant.

With it set to default it seems to work but what is "Exclusive as Boolean" ?
 
"Exclusive as Boolean" (True of False) means open the database exclusively (True), that is, no one else can simultaneously open or be connected to it. False meaning that multiple users can simultaneously open or be connected to it. True is the usual case for a multi-user database, especially when changes have to be made to the program and/or the tables. If multlple users have a database open, one cannot open it exclusively.
 
OK - sort of guessed that. Which bit is opened exclusively in my case?
Let me explain further

In first.accdb all i have is a form with 3 buttons on it
If I click on button a I open a.accdb with the boolean set to true
If I click on button b I open b.accdb with the boolean set to true
If I click on button c I open c.accdb with the boolean set to true

Each of a.accdb, b.accdb and c.accdb are all linked to tables in tables.accdb.

Each PC has a copy of first.accdb a.accdb,b.accdb, and c.accdb so I guess opening them exclusively doesn't matter. But is this exclusivity passed onto tables.accdb?

Hope this makes sense!
 

Users who are viewing this thread

Back
Top Bottom