The following works if the key exists in the Registry
Thanks
John
If the key does not exist I get the error seen in the attachment.Function RegKeyExists2(i_RegKey As String) As Boolean
Dim myWS As Object
On Error GoTo ErrorHandler
'access Windows scripting
Set myWS = CreateObject("WScript.Shell")
'try to read the registry key
myWS.RegRead i_RegKey
'key was found
RegKeyExists2 = True
Exit Function
ErrorHandler:
'key was not found
RegKeyExists2 = False
End Function
Private Sub Command11_Click()
If RegKeyExists2("HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Access\Security\Trusted Locations\Location10\") = False Then
MsgBox ("Code for adding registry key")
Else
MsgBox ("Key exists - do nothing")
End If
Thanks
John