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

Acess a db in MsAcess protected with a password.Urgent

I would like to acess a db in MsAcess protected with a password using Visual Basic. How can I do. .

I have the following code:

Mydb = App.Path & "\school.mdb"

Set db = OpenDatabase(Mydb)

1 Solution
joaquimbieAuthor Commented:
how you want
If you go to www.google.com and search for "Connection Strings" you will find many sites that have example connection strings.  You will find an example with a password.  The code you have looks like you are using DAO.  I have been told that this is still the fastest when dealing with ACCESS, but you may want to look at ADO which provides some more control and functionality.  This is where the connection strings come into play.  I am not that familiar with DAO due to the fact that when I started getting heavy into VB DAO was dying and the engineers on the team wanted us to keep up with the most current components.  Hope that helped
I think that you are using DAO.
So the correct syntax is:

    Dim db As Database
    Set db = OpenDatabase("C:\db1.mdb", dbDriverNoPrompt, False, ";DATABASE=C:\db1.mdb;UID=Admin;PWD=as;")

The last parameter should be as it looks. Only change the database path and the password. There has to be a semi colon before DATABASE. For more information Check MSDN for OpenDatabase method

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Here's how I do it in my application:

Public Sub Connect()
   Set mobjConnection = New ADODB.Connection

   Dim strConn As String

   strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
             "Data Source=t:\database\DATABASE.MDB;" & _
             "Jet OLEDB:System database=t:\database\System.MDW"

' In the two lines above, change the path of the system.mdw
' and the path and name of the database.mdb to match your system setup.
   mobjConnection.Open ConnectionString:=strConn, _
               UserID:="UserID", Password:="Password"

End Sub
I assume that you have already password protected the access database using MS Access.

Make a reference to ADO 2.0 (Project/References)

Now open the database like this,

Dim strConnection As String
Set cnn = New ADODB.Connection

cnn.open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
 "Data Source=" & App.Path & "\school.mdb"
& "Jet OLEDB:Database Password=yourwish"


OOPS, please ignore the line

Dim strConnection As String

CAP technology (Copy And Paste) problem :)

Hi joaquimbie,
This old question (QID 20562343) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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