In the following code I want to check whether a registry key exists before deleting the key. I have a function that checks whether a key exists. See below. I can't get the key to delete, in other words MsgBox "123" never happens.
Dim strKey12
strKey12 = "HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Access\Security\Trusted Locations\Location3\"
If ReadRegistry(strKey12)=True Then
MsgBox "123"
Set objShell = CreateObject("WScript.Shell")
objShell.RegDelete (strKey12)
Set objShell = Nothing
End If
Public Function ReadRegistry(strKey)
Dim strValue
Set objShell = CreateObject("WScript.Shell")
strValue = objShell.RegRead(strKey)
MsgBox strValue
If strValue = "" then
ReadRegistry = False
MsgBox "False"
Else
ReadRegistry = True
MsgBox "True"
end if
End Function