Solved

Password protecting an mdb

Posted on 2001-06-24
9
181 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 1

Accepted Solution

by:
ahmadpj earned 100 total points
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
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
Comment Utility
groone,
do you managed to set the database password?

hongjun
0
 
LVL 3

Author Comment

by:groone
Comment Utility
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
Comment Utility
I'm glad to be useful here:)
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Thanks for thanks to me, too
;)
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

743 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

18 Experts available now in Live!

Get 1:1 Help Now