Acess a db in MsAcess protected with a password.Urgent

Posted on 2003-03-25
Medium Priority
Last Modified: 2010-05-01
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)

Question by:joaquimbie
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Author Comment

ID: 8202700
how you want

Expert Comment

ID: 8202840
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

Accepted Solution

hmadhur earned 75 total points
ID: 8203009
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Expert Comment

ID: 8206436
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

Expert Comment

ID: 8218700
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"



Expert Comment

ID: 8218712
OOPS, please ignore the line

Dim strConnection As String

CAP technology (Copy And Paste) problem :)


Expert Comment

ID: 8531638
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.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

762 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