vba 如何在共享和独占模式之间切换 Access 数据库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1191809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I switch an Access database between shared and exclusive mode?
提问by apenwarr
I'm working on a program that needs to edit some objects in an Access database. It also runs a subprogram (long story) that tries to access the underlying JET database while Access still has it openvia ODBC.
我正在开发一个需要编辑 Access 数据库中某些对象的程序。它还运行一个子程序(长篇故事),该程序尝试访问底层 JET 数据库,而 Access 仍然通过 ODBC打开它。
The problem is that as soon as I start editing Form objects using VBA - for example, using Application.LoadFromText - Access changes the database to exclusive mode. Exclusive mode itself is fine, and I know why it needs it. But I need to be able to switch back to "shared" mode afterwards so that I can run my subprogram.
问题是,一旦我开始使用 VBA 编辑表单对象(例如,使用 Application.LoadFromText),Access 就会将数据库更改为独占模式。独占模式本身很好,我知道它为什么需要它。但是之后我需要能够切换回“共享”模式,以便我可以运行我的子程序。
I've observed that if you use the UI to open a Form in Design mode, Access switches the database to Exclusive. (You can confirm this by trying to open it from another computer.) But when you then close the form designer, Access immediately switches it back to shared mode, which is what I would hope for.
我观察到,如果您使用 UI 在设计模式下打开窗体,Access 会将数据库切换到独占模式。(您可以通过尝试从另一台计算机打开它来确认这一点。)但是当您关闭表单设计器时,Access 会立即将其切换回共享模式,这正是我所希望的。
Is there a way to switch it back and forth myself using VBA / COM calls?
有没有办法使用 VBA/COM 调用自己来回切换?
I know I can call Application.CloseCurrentDatabase() followed by OpenCurrentDatabase(), but that closes all the windows and upsets the UI, so it's not ideal.
我知道我可以先调用 Application.CloseCurrentDatabase(),然后调用 OpenCurrentDatabase(),但这会关闭所有窗口并扰乱 UI,因此它并不理想。
回答by David
Is splitting the database into a separate front-end with the forms/modules/etc. and back-end with the tables an option? That way if the front-end is locked, the back-end is still accessible. Access has a database splitting wizard for just that.
将数据库拆分为具有表单/模块/等的单独前端。和后端与表的一个选项?这样,如果前端被锁定,后端仍然可以访问。Access 有一个数据库拆分向导。
回答by Smandoli
You might try .UserControl and .Visible. I use them to transfer control in automated processes. I don't know if they will help here, but you can down-vote if they don't.
您可以尝试 .UserControl 和 .Visible。我使用它们在自动化流程中转移控制。我不知道他们是否会在这里提供帮助,但如果他们不这样做,您可以投反对票。