How to change folders with .mdb from within the database (1 Viewer)

rickadams

Registered User.
Local time
Today, 06:39
Joined
Mar 11, 2018
Messages
10
Hi,
I am wondering in there is a way to change to a different database from within a database by closing the first ones and open another set.

Ie:
Databases are in a sub folder and I need to access the same named databases in another sub folder. I am using the WordMerge2008.mdb That Albert D. Kallal graciously supplied and your group suggested.

Select databases from the following folders.

Accessdatabase\Acme Manufacturing(demo)\installations\Cards.mdb
Accessdatabase\Acme Manufacturing(demo)\installations\Users.mdb

Select from within the above folder to change to another folder based on the suggestions from the Accessdatabase\ Folder.

Accessdatabase\Smith (demo)\installations\Cards.mdb
Accessdatabase\Smith (demo)\installations\Users.mdb

The databases are connected with relationships.

Thank you In advance!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:39
Joined
Oct 29, 2018
Messages
21,467
Hi. I'm sure it's possible but we'll probably have to know exactly the scenario when you want this to happen. Otherwise simply closing the current db and opening another is as straightforward as either using FollowHyperlink or the Shell command or the ShellExecute API.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 05:39
Joined
Feb 28, 2001
Messages
27,156
The easiest way to do this is to not do this.

I say that because if one DB is in control and you want to switch to another DB, it is the code from the 1st DB that is running the show. You have to somehow transfer control to the 2nd DB - except that you aren't running a MAIN program - an Access APP is actually a bunch of subroutines. From your discussion, you are doing a lot of hand-holding so you appear to not be able to trust your users. Which means you would do better to not trust them at all.

Instead, you need to build a single database that supports the functions of BOTH databases. (After all, you said they had relationships.) But you create a "shelled" environment using a switchboard form (which you can look up in this forum). That would allow you to define that your users would be able to switch between the "Cards" functions and the "Users" functions by simply launching different dispatcher child forms. Or by switching tab controls that had Users functions on one tab and Cards functions on the other tab. Many ways to skin that particular cat.
 

isladogs

MVP / VIP
Local time
Today, 11:39
Joined
Jan 14, 2017
Messages
18,211
Agree with Doc.
This type of question comes up about once a month and in every case I've said that there was no real reason to do so.

I couldn't quite follow what you meant with regard to folders.
However if you just want code to open an external database and do something then add code like this to a standard module and call it from a button click on a form

There are lots of commented lines of code in case any can be adapted to your purposes

Code:
Public Function RunExternalDatabase() As Boolean
    
    Dim app As Access.Application, strPath As String
   [COLOR="SeaGreen"] 'Start a new MSAccess application[/COLOR]
    Set app = New Access.Application
    
    'Open the remote database, then close the current (or remote) database
    With app
        'Syntax: .OpenCurrentDatabase(filepath, Exclusive, strPassword) - the last 2 items are optional

        strPath = CurrentProject.Path & "\OpenExternalDB.accdb" 'full file path to your database
       
 [COLOR="seagreen"] 'some examples you can adapt[/COLOR]
    [COLOR="seagreen"]  '  strPath = "C:\Programs\MendipDataSystems\JATFA\JATFA.accdb" 'replace with your file path
     '   strPath = "C:\Programs\MendipDataSystems\SDALink\SDALink.accdb" '/cmd AttMarks" 'open a database with a command switch to run a procedure[/COLOR] 
   
    [COLOR="seagreen"] 'open the database - does it have a password?[/COLOR]
         .OpenCurrentDatabase strPath, True 'no db password
    [COLOR="seagreen"] '   .OpenCurrentDatabase strPath, True, "password" 'for use if password exists[/COLOR]
    
  [COLOR="seagreen"]  '    .DoCmd.RunMacro "YourMacroName" 'run a macro

   [COLOR="SeaGreen"]  'do you want to close the external database?[/COLOR]
       ' .CloseCurrentDatabase 'closes external database as that is current[/COLOR]
    End With
    
    'Quit the spawned app - DISABLE if not wanted here
  [COLOR="seagreen"]  'app.Quit acQuitSaveNone[/COLOR]
    Set app = Nothing
    
   [COLOR="seagreen"] 'Quit the current app[/COLOR]
    Application.Quit acQuitSaveNone
    
End Function
 

Users who are viewing this thread

Top Bottom