vba - 以编程方式测试 MS Access 数据库是否已加密
问题描述
我正在努力自动发布我们的 MS Access 应用程序的新版本。
我们无法发送未加密的数据库,因此我想添加一个测试,该测试将显示一个带有数据库未加密警告的 msgbox。
有人知道我可以测试的对象/属性吗?
解决方案
您可以通过创建用户定义的函数来测试它。在模块或表单模块中编写以下函数。
Public Function IsDbSecured(ByVal sDb As String) As Boolean
On Error GoTo Error_Handler
Dim oAccess As Access.Application
Set oAccess = CreateObject("Access.Application")
oAccess.Visible = False
'If an error occurs below, the db is password protected
oAccess.DBEngine.OpenDatabase sDb, False
Error_Handler_Exit:
On Error Resume Next
oAccess.Quit acQuitSaveNone
Set oAccess = Nothing
Exit Function
Error_Handler:
If Err.Number = 3031 Then
IsDbSecured = True
Else
MsgBox "Error Number: " & Err.Number & vbCrLf & "Error Description: " & Err.Description, vbCritical, "Error"
End If
Resume Error_Handler_Exit
End Function
然后像这样从按钮或您想要的方式调用它。
Private Sub Command1_Click()
Dim fileTestPath As String
'Change your database path here.
fileTestPath = "C:\Users\Harun.Rashid\Documents\Test_Close.accdb"
If IsDbSecured(fileTestPath) = True Then
MsgBox "Your database is encrypted by password"
End If
End Sub
推荐阅读
- context-free-grammar - 上下文无关和上下文敏感的语法是什么意思?
- r - 在ggplot2中对齐多线轴标题
- vba - 如何防止一个段落跨越两页
- d3.js - vega-lite:如何将 JSON 中的日期指定为包含年、月和日数的单独字段?
- javascript - 点击被忽略:标签元素与表单控件相关联的问题
- java - 在仍然更改属性的同时重试 Spring Data Flow 任务
- ruby-on-rails - 覆盖模型中的 ActiveSupport::Concern
- java - 如何在 Appium-Java 中获取水平条的最后一个元素?
- jetty - 带有 Embedded-Jetty 或 Spark-Java 的 Apache Shiro - 有可能吗?
- sql - 如何构建根据特定条件变化的动态 SQL 表达式