Solved

Password protecting an mdb

Posted on 2001-06-24
9
183 Views
Last Modified: 2010-05-02
Please someone show me how to protect a database and how to open the protected database.  Dont give me some long example, just get to the point.

    Set myDB = DBEngine(0).CreateDatabase(FileName, dbLangGeneral)
    Set myDB = DBEngine.Workspaces(0).OpenDatabase(FileName)

    blah blah add fields

    myDB.close

Thanks!
0
Comment
Question by:groone
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 33

Expert Comment

by:hongjun
ID: 6223090
How to protect a database
==========================
1. File->Open. Then open the access file as "Exclusive".
2. Tools->Security->Set Database Password
3. Type and confirm your database password.
That's all.

How to open the protected database (I am using ADO)
===================================================
' You got to add Microsoft ActiveX Data Objects 2.1 or other version library
Dim objConn as ADODB.Connection
Dim FileName as string
Dim passwd as string

FileName = "C:\Windows\Desktop\db1.mdb"
passwd = "abcdef"

Set objConn = New ADODB.Connection
objConn.Open "Driver={Microsoft Access Driver (*.mdb)};dbq=" & FileName & ";uid=sa;pwd=" & passwd & ";"
...

hongjun
0
 
LVL 3

Author Comment

by:groone
ID: 6223110
Notice the database is being created by code using dao3.5 not ADO.  I am creating the database on the fly and need it to be password protected as it is being created from within the VB 6.0 code.  Sorry, thought the question would have been obvious.
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6223133
Taken from MSDN. Might be of help to you.

Sub OpenDatabaseX()

   Dim wrkJet As Workspace
   Dim dbsNorthwind As Database
   Dim dbsPubs As Database
   Dim dbsPubs2 As Database
   Dim dbsLoop As Database
   Dim prpLoop As Property

   ' Create Microsoft Jet Workspace object.
   Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)

   ' Open Database object from saved Microsoft Jet database
   ' for exclusive use.
   MsgBox "Opening Northwind..."
   Set dbsNorthwind = wrkJet.OpenDatabase("Northwind.mdb", _
      True)

   ' Open read-only Database object based on information in
   ' the connect string.
   MsgBox "Opening pubs..."
   Set dbsPubs = wrkJet.OpenDatabase("Publishers", _
      dbDriverNoPrompt, True, _
      "ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers")

   ' Open read-only Database object by entering only the
   ' missing information in the ODBC Driver Manager dialog
   ' box.
   MsgBox "Opening second copy of pubs..."
   Set dbsPubs2 = wrkJet.OpenDatabase("Publishers", _
      dbDriverCompleteRequired, True, _
      "ODBC;DATABASE=pubs;DSN=Publishers;")

   ' Enumerate the Databases collection.
   For Each dbsLoop In wrkJet.Databases
      Debug.Print "Database properties for " & _
         dbsLoop.Name & ":"

      On Error Resume Next
      ' Enumerate the Properties collection of each Database
      ' object.
      For Each prpLoop In dbsLoop.Properties
         If prpLoop.Name = "Connection" Then
            ' Property actually returns a Connection object.
            Debug.Print "  Connection[.Name] = " & _
               dbsLoop.Connection.Name
         Else
            Debug.Print "  " & prpLoop.Name & " = " & _
               prpLoop
         End If
      Next prpLoop
      On Error GoTo 0

   Next dbsLoop

   dbsNorthwind.Close
   dbsPubs.Close
   dbsPubs2.Close
   wrkJet.Close

End Sub

hongjun
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Accepted Solution

by:
ahmadpj earned 100 total points
ID: 6223181
Hi, groone, This is the answer:

Dim MyDB As Database
Dim FileName As String

FileName = "C:\win98\desktop\db1.mdb" 'change it as your will

Set MyDB = DBEngine(0).CreateDatabase(FileName, dbLangGeneral)

'set a password to it..
MyDB.NewPassword "", "MyPass"
MyDB.Close

'opening protected database
Set MyDB = DBEngine.OpenDatabase(FileName, False, 0, ";pwd=MyPass")
MyDB.Close


 good Luck.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6223303
I think ahmadpj get the answer but i am not sure of this line:
Set MyDB = DBEngine.OpenDatabase(FileName, False, 0, ";pwd=MyPass")
maybe it should be:
Set MyDB = DBEngine.OpenDatabase(FileName, 0,false, ";pwd=MyPass")
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6223339
groone,
do you managed to set the database password?

hongjun
0
 
LVL 3

Author Comment

by:groone
ID: 6224196
Thanks!  Worked perfectly except you had the false and 0 in the wrong place other than that was a good answer.  Brief and to the point.
0
 
LVL 1

Expert Comment

by:ahmadpj
ID: 6226285
I'm glad to be useful here:)
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6226312
Thanks for thanks to me, too
;)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

815 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

11 Experts available now in Live!

Get 1:1 Help Now