How to open another database

Posted on 2014-08-18
Last Modified: 2014-08-18
Could someone please show me a line of code to open another database with the password of 'password'.

Thanks in advance.
Question by:CRB1609
    LVL 84

    Accepted Solution

    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:

    If the second ... then it's a bit more difficult.
    LVL 24

    Expert Comment

    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


    Author Closing Comment

    Perfect.  Thank you.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    The first two articles in this short series — Using a Criteria Form to Filter Records ( and Building a Custom Filter ( — discuss in some detail how a form can be…
    QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
    In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now