Solved

make MS Access DB as password protected through Visual Basic Code

Posted on 2002-07-06
10
180 Views
Last Modified: 2013-11-25
My problem is fairly simple. i have created a database through Visual Basic 6.0. The code successfully created the database but i want to make this newly created database file as password protected. Just like we can do password protected to our MS WORD document file so no one else can read the essential contents. i think i have described my problem please contact me if you still un sure...
i need it soon so i placed 500 points.
0
Comment
Question by:younus_malik
[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
10 Comments
 
LVL 5

Expert Comment

by:kcm76
ID: 7133522
0
 
LVL 5

Accepted Solution

by:
kcm76 earned 500 total points
ID: 7133534
0
 
LVL 5

Expert Comment

by:kcm76
ID: 7133545
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:pierrecampe
ID: 7133547
or if you use DAO you can use:

Dim db As DAO.Database
Set db = DBEngine.OpenDatabase("TheDatabase.mdb", True)
db.NewPassword "Oldpassword", "Newpassword"
db.Close

note that "Oldpassword" can be "" (for db's that do not yet have a password

0
 
LVL 33

Expert Comment

by:hongjun
ID: 7133550
Try the below function. You need to add DAO Object Library References.


Public Function SetDatabasePassword(DBPath As String, _
newPassword As String) As Boolean
   
'Usage: Password protect a database that previously had no
'password

'Parameters: sDBPath: Full Path to Access Database
'newPassword: the password
'returns true on success false otherwise

If Dir(DBPath) = "" Then Exit Function

Dim db As DAO.Database

On Error Resume Next
Set db = OpenDatabase(DBPath, True)
If Err.Number <> 0 Then Exit Function
db.newPassword "", newPassword
SetDatabasePassword = Err.Number = 0
db.Close

End Function


hongjun
0
 
LVL 33

Expert Comment

by:hongjun
ID: 7133552
pierrecampe, sorry for my similar post. I did not see your post when I am making my post.

hongjun
0
 
LVL 5

Expert Comment

by:kcm76
ID: 7133559
**************************************
Experts, pls contribute as much as possible, this would really help others who view this thread in paq section in future.
**************************************

http://www.mvps.org/access/modules/mdl0036.htm

************* Code Start *****************
Function foo()
    Dim db As Database
    Dim oAcc As Access.Application

    Const TMP = "fooz.mdb"

    Set db = DBEngine.CreateDatabase(TMP, _
                        dbLangGeneral)
    db.NewPassword "", "doooo"
    db.Close
    Set db = Nothing

    Set oAcc = New Access.Application
    Set db = oAcc.DBEngine.OpenDatabase(TMP, _
                            False, False, ";PWD=doooo")
    oAcc.OpenCurrentDatabase TMP
    db.Close
    Set db = Nothing
End Function
0
 
LVL 33

Expert Comment

by:hongjun
ID: 7133560
>>Experts, pls contribute as much as possible
I am touched by your hardworking contribution but I think that a specific solution targetted to the question would be enough.

hongjun
0
 
LVL 33

Expert Comment

by:hongjun
ID: 7133561
Regardless of the amount of points assigned.

hongjun
0
 

Author Comment

by:younus_malik
ID: 7133573
Thanks to all you Guys. you all come up with the correct and precise answers but i choose this man cause he replied me first and fast.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 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…

734 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