Click to See Complete Forum and Search --> : Microsoft Access OLE Automation Connection


November 3rd, 1999, 07:59 AM
Hi all,
I'm trying to connect, via OLE Automation, my application to a lock by password an Access data base using ADO. The connection only works if I disable the password in the database itself, then run my application. This situation is not suitable since I do not want the users to be able to enter the database through Access but through my application only. Does anyone now how to be able through a file DSN and OLE Automation to open a lock Access Database? Or does anyone have a simpler solution?

Regards,

November 4th, 1999, 04:27 PM
Q161016 - ACC: How to Use DAO to Open Password-Protected Database (95/97)
http://support.microsoft.com/support/kb/articles/q161/0/16.asp

The following code will do the trick for Acc 2000:

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:\My Documents\test.mdb"
Set acc = New Access.Application
acc.Visible = True
Set db = acc.DBEngine.OpenDatabase(strDbName, False, False, ";PWD=cool") 'cool is the password
acc.OpenCurrentDatabase strDbName
db.Close
Set db = Nothing
End Sub