Search code examples
ms-access-2007ms-access-2010digital-certificate

How can I add a certificate to VBA Access project if the Digital Signature item doesn't appear in the Tools menu?


I am trying to get an Access 2000 database to run in the Access 2010 runtime and remove the warning dialog about the file not being trusted. I have done some research and discovered the SelfCert.exe program. This is a good tutorial on certificates. And this, too. Even Microsoft had instructions for Access 2000 indicating that this menu item should exist. However, my Tools menu in the Access 2000 VBA IDE does not have the Digital Signature menu item. What's worse is that when I right-click on menu bar to customize the Tools menu, I do see the Digital Signature... item in the customize list. When I click and drag to add it to the Tools menu, it disregards my command. How stubborn! If I click and drag anything else to the Tools menu, it works like a charm. What?!

How do I install that menu item? Or, better yet, how do I get my database not to have the security warning when I open it from Access 2010 runtime?

I cannot add the Digital Signature... item to the Tools menu


Solution

  • After some more significant research, I discovered the answer to my second question, which was ultimately what I wanted an answer to. How do I get rid of the potential security concern dialog when opening an Access 2000 database in the Access 2010 runtime?

    Microsoft Access Security Notice

    Basically, you need to add the database to the list of trusted locations. The Access 2010 runtime does not offer a UI for this feature, so you have to do it programmatically. This website offers the code: Utter Access Add Trusted Location

    I modified it for the specific requirements in this situation. Run an Access 2000 database in Access 2010 runtime. You will need to modify it for other versions of the runtime depending on the registry settings. Also, I read that this will not work in Windows 8. But I also found that you do NOT need administrative privileges to run this code because it only modifies the HKEY_CURRENT_USER hive in the registry, which the current user has full access to.

    Public Function AddTrustedLocation()
    On Error GoTo err_proc
    'WARNING:  THIS CODE MODIFIES THE REGISTRY
    'You do not need administrator privileges
    'since it only affects the HK_CURRENT_USER hive
    'sets registry key for 'trusted location'
    
    Dim intLocns As Integer
    Dim i As Integer
    Dim intNotUsed As Integer
    Dim strLnKey As String
    Dim reg As Object
    Dim strPath As String
    Dim strTitle As String
    
    strTitle = "Add Trusted Location"
    Set reg = CreateObject("wscript.shell")
    strPath = CurrentProject.path
    
    'Specify the registry trusted locations path for the Access 2010 runtime
    strLnKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Access\Security\Trusted Locations\Location"
    
    On Error GoTo err_proc0
    'find top of range of trusted locations references in registry
    For i = 999 To 0 Step -1
        reg.RegRead strLnKey & i & "\Path"
        GoTo chckRegPths        'Reg.RegRead successful, location exists > check for path in all locations 0 - i.
    checknext:
    Next
    MsgBox "Unexpected Error - No Registry Locations found", vbExclamation
        GoTo exit_proc
    
    chckRegPths:
        'Check if Currentdb path already a trusted location
        'reg.RegRead fails before intlocns = i then the registry location is unused and
        'will be used for new trusted location if path not already in registy
    
        On Error GoTo err_proc1:
        For intLocns = 1 To i
            reg.RegRead strLnKey & intLocns & "\Path"
            'If Path already in registry -> exit
            If InStr(1, reg.RegRead(strLnKey & intLocns & "\Path"), strPath) = 1 Then GoTo exit_proc
    NextLocn:
        Next
    
        If intLocns = 999 Then
            MsgBox "Location count exceeded - unable to write trusted location to registry", vbInformation, strTitle
            GoTo exit_proc
        End If
        'if no unused location found then set new location for path
        If intNotUsed = 0 Then intNotUsed = i + 1
    
        'Write Trusted Location regstry key to unused location in registry
        On Error GoTo err_proc:
        strLnKey = strLnKey & intNotUsed & "\"
        reg.RegWrite strLnKey & "AllowSubfolders", 1, "REG_DWORD"
        reg.RegWrite strLnKey & "Date", Now(), "REG_SZ"
        reg.RegWrite strLnKey & "Description", Application.CurrentProject.Name, "REG_SZ"
        reg.RegWrite strLnKey & "Path", strPath & "\", "REG_SZ"
    
    exit_proc:
          Set reg = Nothing
          Exit Function
    
    err_proc0:
          Resume checknext
    
    err_proc1:
          If intNotUsed = 0 Then intNotUsed = intLocns
          Resume NextLocn
    
    err_proc:
          MsgBox Err.Description, , strTitle
          Resume exit_proc
    
    End Function
    

    I added this function to the AutoExec macro. When the user first logs on, they do receive the security notice; however, it will never appear again as long as the document remains in the trusted location it was first run at. Woo-hoo!