Access VBA - Launch password protected database and close existing one

让人想犯罪 __ 提交于 2019-12-08 04:19:26

You can use the following:

Private Sub Form_Load()
 Dim acc As Access.Application
 Dim db As DAO.Database
 Dim strDbName As String

 strDbName = "C:\database Folder\secureDB.accdb"
 Set acc = New Access.Application
 acc.Visible = True
 acc.OpenCurrentDatabase strDbName, False, "swordfish"
 Set db = acc.CurrentDb() 'Don't know why you want a reference to the db
 acc.UserControl = True
 Application.Quit
End Sub

The relevant part is acc.UserControl = True, that forces the DB to stay visible and stops it from closing as soon as the reference to the Application object gets destroyed.

A sample database that stores the main database password encrypted with a salted user password can be found in this answer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!