[This question has been posted on Utter Access https://www.utteraccess.com/topics/2.../posts/2831149
I am trying to replicate an application that worked with Access 2010 for use if Office 365 Access. This involves an encrypted passworded .accdr file where the password is hidden in the code and only known by the developer. When the .accdr opens it presents the user with a login screen where credentials can be maintained by a user administrator. As an aside, the application is split front-end and back-end and most of the tables are held in MySQL. I think this technique is important because the end user experience is like a bespoke c# application and provides a robust level of security preventing access to database passwords, tables and code.
The Access 2010 application code came from an MSDN Developer Article, no longer web viewable which acknowledge that, unlike passworded .accdb and .accde database, opening a runtime database with a password is not straightforward. The technique this article suggested was to open a non-passworded .accdb which opens, via Shell, a dummy .accdb database in runtime mode. The dummy database then uses GetObject to connect to the dummy database. The dummy database is closed and the 'real database' (the passworded runtime db ) is opened automatically with the password.
Here is the code, which fails on the line appRT.OpenCurrentDatabase strPathToDatabase, False, strPasswordx with the error message that the file does not exist, is opened by another user or is not an .adp file.
Code:
Function Hide1()
' removes toolbar
DoCmd.ShowToolbar "Ribbon", acToolbarNo
' positions database window on RHS
Call ScreenRL(True)
'---Placeholder pause for code to backup and compact the main database
Call sapiSleep(3000)
' Opens the "real database"
Call StartPasswordedDatabaseRuntime("C:\MouSe\NFM140.accdb", "xxxxxx", "C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE", True)
End Function
Function StartPasswordedDatabaseRuntime( _
strPathToDatabase As String, _
Optional strPasswordx As String, _
Optional strPathToRuntime As String, _
Optional blnQuit As Boolean)
Dim appRT As Access.Application
Dim strPathToDummy As String
Dim i As Long
Const Q As String = """"
'On Error GoTo Error1
Call ScreenRL(True)
If Len(strPathToRuntime) = 0 Then
strPathToRuntime = SysCmd(acSysCmdAccessDir) & "msaccess.exe"
End If
strPathToDummy = "C:\scratchdir\dglink.accdb"
If Len(Dir(strPathToDummy)) = 0 Then
Application.DBEngine.CreateDatabase strPathToDummy, dbLangGeneral, dbVersion40
End If
Shell _
Q & strPathToRuntime & Q & " " & Q & strPathToDummy & Q & " /runtime", _
windowstyle:=6
i = 1
Do While i > 300000
i = i + 1
Loop
Set appRT = GetObject(strPathToDummy)
MsgBox strPathToDatabase & vbCrLf & strPasswordx 'This correctly displays db credentials which work when the .accdr is opened directly.
With appRT
.CloseCurrentDatabase
End With
DoEvents
DoEvents
appRT.OpenCurrentDatabase strPathToDatabase, False, strPasswordx 'This line fails with the message Microsoft Access cannot open the database because it is missing, opened exclusively by another user or is not an adp file.
Call ScreenRL(True)
DoCmd.Maximize
If blnQuit Then
Application.Quit
End If
Exit Function
Error1:
MsgBox "Sorry we have problems.. " & vbCrLf & Err.Number & vbCrLf & Err.Description
Application.Quit
End Function
Is there another way to open a passworded, encrypted runtime database in the current version of Access? Alternatively, can anyone help by pointing out how to correct the run-time error? Thanks.