Question How to open a password protected database

genesis

Registered User.
Local time
Today, 04:01
Joined
Jun 11, 2009
Messages
205
I have two database A and B.

database A is password protected.

How or what is the VBA code that I can make in a command button that in Database B that will open the database A (not link the table) application? I not that good at vba.

thanks.
 
Do you know the password for the protected mdb?
 
yes I do know the password because it is my work Dcrake.

can you teach me how to do that or what that vba code is.....

I have found this but i dont know if this is...............



Option Compare Database
Option Explicit

Sub OpenPasswordProtectedDB()

'Define as Static so the instance of Access
'doesn't close when the procedure ends.
Static acc As Access.Application
Dim db As DAO.Database
Dim strDbName As String
strDbName = "C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb"
Set acc = New Access.Application
acc.Visible = True
Set db = acc.DBEngine.OpenDatabase(strDbName, False, False, ";PWD=nwind")
acc.OpenCurrentDatabase strDbName
db.Close
Set db = Nothing
End Sub



OR ----------------------------



Public Function OpenPasswordProtectedDatabase(DBPath As String, _
Password As String) As Object

'Usage: Open Password protected database
'Parameters: DBPath: Full Path to Access Database
'Password: the Password
'returns the database, in it's open state if successful.
'Otherwise return value will evalute to nothing

On Error Resume Next
Dim db As DAO.Database

Set db = DAO.OpenDatabase(DBPath, False, False, _
";pwd=" & Password)

If Err.Number = 0 Then
Set OpenPasswordProtectedDatabase = db
Else
Set OpenPasswordProtectedDatabase = Nothing
End If

End Function


that was just sample of what i have researched in the net.
 
Last edited:
What do you mean when you say 'open the database'?

I can't tell whether you mean that you want to connect to it to pull data out, or if you mean you want to launch a separate Access window with the database opened into it.
 
just open it to launch a separate access window with the database opened into it.

NOT link or import.

was my code above sufficient or not yet?
 
I don't think any of that code is going to launch a separate Access window (and I don't know how to do what you're asking.

(I'm also unsure why you'd want to do it - you're talking about opening up the back end - is this to provide an administrator-only backdoor or something?)
 
Code:
Public obDAO As DAO.Workspace, obDB As DAO.Database

Sub OpenConnection()

    Set obDAO = DAO.DBEngine.Workspaces(0)
    Set obDB = obDAO.OpenDatabase([B]strDBPath[/B], False, False, ";pwd=" & [B]DBPass [/B]& "")
    ConnectionState = True
    
End Sub

Where strDBPath is the full path and file name that you want to open and DBPass is the active password
 

Users who are viewing this thread

Back
Top Bottom