Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Password protecting an mdb

Posted on 2001-06-24
9
Medium Priority
?
190 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
[X]
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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Accepted Solution

by:
ahmadpj earned 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…
Suggested Courses

715 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