简体   繁体   English

如何使用自执行代码杀死 CurrentDB

[英]How to Kill CurrentDB using self executed code

I have been researching ways to self execute code that would delete the current database file.我一直在研究自我执行会删除当前数据库文件的代码的方法。 I came across a code snippet here that does exactly that for Excel, but this does not seem to translate to Access very well.我在 这里遇到了一个代码片段,它完全适用于 Excel,但这似乎并不能很好地转换为 Access。

 Sub KillMeExcel()
 With ThisWorkbook
    .Saved = True
    .ChangeFileAccess Mode:=xlReadOnly
    Kill .FullName
    .Close False
 End With
 End Sub

There does not seem to be a .ChangeFileAccess Mode in Access, so I haven't gotten further than that. Access 中似乎没有.ChangeFileAccess模式,所以我没有进一步了解。

Is it possible to delete the current database using VBA code?是否可以使用 VBA 代码删除当前数据库?

I would also be wary of sending an open and running Access database via mail.我也会对通过邮件发送打开和运行的 Access 数据库持谨慎态度。

My workaround would be:我的解决方法是:

Launch an external vbs
DoCmd.Quit

and in the vbs:并在 vbs 中:

  • Wait in a loop until the .ldb / .laccdb file is gone (ie the db is closed)循环等待,直到 .ldb / .laccdb 文件消失(即 db 已关闭)
  • Send the mail with attached db发送带有附加数据库的邮件
  • delete the db删除数据库

That is not possible.那是不可能的。 You will get a Permission Denied error - for a reason.您将收到Permission Denied错误 - 出于某种原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 VBA 创建 CurrentDb 的副本 - How do I create copies of CurrentDb using VBA set dbs = currentdb()和直接使用currentDB()之间有什么重要的区别吗? - Is there any important difference between set dbs=currentdb() and using currentDB() directly? 如何在 MS-Access 中使用 VBA 不在 currentdb 中创建表 - How do I create a table in MS-Access using VBA NOT in currentdb MS Access:使用CurrentDB而不是DBEngine(0)(0)时是否有大量开销? - MS Access: Is there a significant overhead when using CurrentDB as opposed to DBEngine(0)(0)? CurrentDb.Execute 删除查询从 VBA 执行时不删除任​​何内容 - CurrentDb.Execute delete query not deleting anything when its executed from VBA 使用CurrentDB中的导入规范将DoCmd.TransferText导入另一个数据库 - DoCmd.TransferText into another DB, using an Import Spec in CurrentDB 如何在excel VBA中而不是CurrentDB中定义文件夹中访问数据库的路径? - How to define a path of access database in a folder instead of CurrentDB in excel VBA? 为什么我不能直接使用CurrentDB()方法将表与vba重新链接? - Why can't I re-link a table with vba using the CurrentDB() method directly? 尽管SQL字符串在查询生成器中正常运行,但使用CurrentDb.Execute(sqlStr)时出错 - Error using CurrentDb.Execute(sqlStr) despite SQL string functioning properly in query builder currentdb执行不插入 - currentdb execute does not insert
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM