Call AddTrustedLocation("C:\Apps\ETS") Call AddTrustedLocation("\\americas.shell.com\americas\E & P\SEPCO Woodcreek\PROJ_07\Onshore Asset\ETS & MAPPING\Project Tracking") WScript.Quit Private Function AddTrustedLocation(strPath) Dim intLocns Dim i Dim intNotUsed Dim strLnKey Dim reg Dim strTitle strTitle = "Add Trusted Location" Set reg = CreateObject("wscript.shell") 'Specify the registry trusted locations path for the version of Access used strLnKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\" & Format(Application.Version, "##,##0.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 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: Resume exit_proc End Function
Gain unlimited access to on-demand training courses with an Experts Exchange subscription.Get Access
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE
Connect with Certified Experts to gain insight and support on specific technology challenges including: