Reputation: 1362
I am working on automating the release of new versions of our MS Access application.
We cannot ship the database unencrypted, so I want to add a test that will display a msgbox with a warning that the database is not encrypted.
Does anyone know the object/property I can test?
Upvotes: 0
Views: 180
Reputation: 36750
You can test it by creating a user defined function. Write below function in a module or form module.
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
Then call it from a button or your desired way like this.
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
Upvotes: 1