Solved

make MS Access DB as password protected through Visual Basic Code

Posted on 2002-07-06
10
181 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Suggested Courses
Course of the Month4 days, 21 hours left to enroll

635 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