Solved

make MS Access DB as password protected through Visual Basic Code

Posted on 2002-07-06
10
175 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
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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

707 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