List all open databases

Scouseneil

New member
Local time
Today, 13:21
Joined
Sep 26, 2012
Messages
3
Hi,

I was wondering if there is a way to list all currently opened Access databases? It feels like this must be possible by referring to the databases collection, but I just don't know how.

Also, is it possible to refer to controls on a form in one open database from code in another database? (and obviously if so, how?)

Thanks
 
Last edited:
Answer to your first question is given below:

Code:
Public Function dbsTest()
'This Code is running in the Current Database and running under Workspace(0)
'Besides that a second database (c:\mdbs\ChartSample.accdb)
'is opened under the same Workspace on the same machine
'This program will give the list of two databases.
'Databases opened on the same machine under the same
'Workspace only will be listed in this example.

Dim wsp As Workspace, db As Database
Dim j As Integer, k As Integer
Dim strdbs As String, crlf As String

crlf = Chr$(13) & Chr$(10)

Set wsp = DBEngine.Workspaces(0)
Set db = wsp.OpenDatabase("c:\mdbs\ChartSample.accdb")

k = wsp.Databases.Count
For j = 0 To k - 1
   If j = 0 Then
     strdbs = wsp.Databases(j).Name
   Else
     strdbs = strdbs & crlf & wsp.Databases(j).Name
   End If
Next

MsgBox strdbs

db.Close

Set db = Nothing
Set wsp = Nothing

End Function

For answer to your second question, sample Code taken from Microsoft Access Help Document is pasted below for reference:

Code:
' Include the following in Declarations section of module.
Dim appAccess As Access.Application

Sub DisplayForm()

    Dim strDB as String

    ' Initialize string to database path.
    Const strConPathToSamples = "C:\Program " _
        & "Files\Microsoft Office\Office11\Samples\"

    strDB = strConPathToSamples & "Northwind.mdb"
    ' Create new instance of Microsoft Access.
    Set appAccess = _
        CreateObject("Access.Application")
    ' Open database in Microsoft Access window.
    appAccess.OpenCurrentDatabase strDB
    ' Open Orders form.
    appAccess.DoCmd.OpenForm "Orders"
End Sub
 
apr pillai,

Thanks so much, that's just what I wanted!

Scouseneil
 

Users who are viewing this thread

Back
Top Bottom