What is the Excel VB code to extract data from a password protected database?

Posted on 2009-05-11
Last Modified: 2012-05-06

I have written some VB ocde in Excel that will extract data from Access and dump it into a spreadsheet. The problem is that the database is password protected and so therefore when I use the code stated I get an error message stating that the password is invalid. Any help would be appreciated.



Dim DB As Database

Dim DATE_T As Date

Dim EMPLACEMENT, Sql As String

Dim Branch(20) As String

Dim TrnFmly(8) As String

Dim TICKER(200) As String

Dim CURR(200) As String

Dim DPL(200) As Double

Dim MPL(200) As Double

Dim I As Integer

Dim J As Integer

Dim K As Integer

Dim L As Integer

Dim RIEN As Variant

Dim prod_type As String


DATE_T = Cells(3, 7).Value


EMPLACEMENT = "O:\Treasury\Daily\Daily Profit and Loss\MARGIN ANALYSIS DATABASE.mdb"

       Sql = "SELECT QRY_UNION_DEALS.[Deal No]"

        Sql = Sql & " FROM QRY_UNION_DEALS "


        Set DB = OpenDatabase(EMPLACEMENT)

        Set RST = DB.OpenRecordset(Sql)




        ActiveCell.CopyFromRecordset RST


End Sub

Open in new window

Question by:f19l
1 Comment
LVL 46

Accepted Solution

tbsgadi earned 500 total points
ID: 24355202
something like

Set db = DBEngine.OpenDatabase(".\EMPLACEMENT.mdb",       False, False, ";pwd=password")

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access 2016 VB code 9 102
Hide vba in gp 7 82
Child Form in front 4 38
MsgBox 4 46
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

910 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

21 Experts available now in Live!

Get 1:1 Help Now