[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 235
  • Last Modified:

How to open another database

Could someone please show me a line of code to open another database with the password of 'password'.

Thanks in advance.
1 Solution
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Do you mean "open", as in connect to the Tables?

Or "open" as in open up Forms, Reports, etc?

If the first:

Sub OpenDB()
 Dim db As DAO.Database
 Dim ws As DAO.WorkSpace
 Dim rst As DAO.Recordset
 Set ws = DBEngine.WorkSpaces(0)
 Set db = ws.OpenDatabase _
 ("Full Path to your Database", False, False, "MS Access;PWD=password")
 '<<< do whatever you need here >>>>
End Sub

Open in new window

From here: http://support.microsoft.com/kb/209953

If the second ... then it's a bit more difficult.
You have not specified if you use DAO of ADODB. Here is an example of ADODB:
    Dim cn As ADODB.Connection
    Dim strConnect As String
    Set cn = New ADODB.Connection
    strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Jet OLEDB:Database Password=password" & _
        ";Data Source=c:\temp\another.mdb;"
    cn.Open strConnect

Open in new window

CRB1609Author Commented:
Perfect.  Thank you.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now