Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

make MS Access DB as password protected through Visual Basic Code

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
younus_malik
Asked:
younus_malik
1 Solution
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
pierrecampeCommented:
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
 
hongjunCommented:
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
 
hongjunCommented:
pierrecampe, sorry for my similar post. I did not see your post when I am making my post.

hongjun
0
 
kcm76Commented:
**************************************
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
 
hongjunCommented:
>>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
 
hongjunCommented:
Regardless of the amount of points assigned.

hongjun
0
 
younus_malikAuthor Commented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now