访问VBA-启动受密码保护的数据库并关闭现有数据库 [英] Access VBA - Launch password protected database and close existing one

查看:148
本文介绍了访问VBA-启动受密码保护的数据库并关闭现有数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立一个包含vba代码的启动器"数据库,该数据库将打开第二个受密码保护的数据库. (然后,我可以将启动程序数据库转换为accde,以便无法读取包含密码的VBA)

I am trying to set up a "Launcher" database which contains vba code that will open a second database which is password protected. (I can then convert the launcher db to accde so the VBA containing the password cannot be read)

到目前为止,我有以下代码...

I have the following code so far...

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
 Set db = acc.DBEngine.OpenDatabase(strDbName, False, False, ";PWD=swordfish")

 acc.OpenCurrentDatabase (strDbName)

 Application.Quit

End Sub

打开启动器数据库时,将加载一个表单,该表单随后将触发上述代码.它可以工作,但问题是最后一行仅用于关闭启动器数据库,但实际上同时关闭了两个数据库.我也尝试过使用shell打开主数据库,但是无法以这种方式传递密码.

When the launcher db is opened a form loads which subsequently fires the above code. It works but the problem is the last line which is intended to close the launcher db only but actually closes both databases. I have also tried opening the main database using shell but am unable to pass the password this way.

有人知道我怎样才能在关闭第二个数据库的同时关闭第一个数据库?

Does anyone know how I can just close the first database while keeping the second one open?

推荐答案

您可以使用以下内容:

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

相关的部分是acc.UserControl = True,它强制DB保持可见状态,并在销毁对Application对象的引用后立即停止关闭它.

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.

可以在此答案

这篇关于访问VBA-启动受密码保护的数据库并关闭现有数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆