MS Access VBA Error: Run time error '70' Permission Denied

Viewed 16604

I believe this issue is a result of a recent update to MS Office/Access or Windows 10. When I run this code:

Dim s As String
With CreateObject("Scriptlet.TypeLib")
    s = Left(.Guid, 9)
   newguidx = Right(s, 8)
End With

I get an error: Permission Denied on the With Statement. This is new only only cropped up after my admins updated our systems. I have no option to roll back updates. Anyone come across this and have a work around?

OS: Windows 7 Enterprise Access Version: 2010

Thanks

3 Answers

In Access, we can suffice with this very short function to generate a GUID by leveraging Application.StringFromGUID to cast bytes to a GUID. It generates pretty verbose GUIDs, though, with the format {guid {00000000-0000-0000-0000-000000000000}}.

Declare PtrSafe Sub CoCreateGuid Lib "ole32" (ByVal GUID As LongPtr)
Public Function NewGUID() As String
    Dim b(15) As Byte
    CoCreateGUID VarPtr(b(0))
    NewGUID = Application.StringFromGUID(b)
End Function

You can strip away unwanted characters, for example by replacing the last line of this function with NewGUID = Mid(Application.StringFromGUID(b), 8, 36). Then, the format will be 00000000-0000-0000-0000-000000000000

Since windows update taken out "Scriptlet.TypeLib", try the following:-

Declare Function CoCreateGuid Lib "ole32" (ByRef GUID As Byte) As Long
Public Function GenerateGUID() As String
    Dim ID(0 To 15) As Byte
    Dim N As Long
    Dim GUID As String
    Dim Res As Long
    Res = CoCreateGuid(ID(0))

    For N = 0 To 15
        GUID = GUID & IIf(ID(N) < 16, "0", "") & Hex$(ID(N))
        If Len(GUID) = 8 Or Len(GUID) = 13 Or Len(GUID) = 18 Or Len(GUID) = 23 Then
            GUID = GUID & "-"
        End If
    Next N
    GenerateGUID = GUID
End Function

Alternatively, if you are connecting to SQL Server 2008 or higher, try to use the SQL NEWID() function instead.

Related