Remove Custom Menu Bars from Microsoft Access 2003

October 21, 2009 · Posted in Technology 

Run the following command from the VB Immediate Window (CTRL-G) inside Microsoft Access to remove any custom command bars present in the currently loaded database:

CurrentDb.Execute “DELETE * FROM MSysAccessStorage WHERE ParentId IN (SELECT msa.Id FROM MSysAccessStorage AS msa WHERE msa.Name = ‘Cmdbars’;);”

Execute the following code to completely remove all custom command bars from the Windows Registry (this will speed up load-time for Microsoft Access:

Sub RemoveCustomMenusFromRegistry()

'HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Access\Settings\CommandBars
Dim lCBHandle As Long
Dim sValues() As String
Dim a As Long

lCBHandle = RegistryAPI.OpenRegistryKey(RegistryAPI.HKEY_CURRENT_USER, "Software\Microsoft\Office\11.0\Access\Settings\CommandBars")
RegistryAPI.GetRegistryKeyValues lCBHandle, sValues()
For a = LBound(sValues) To UBound(sValues)
If sValues(a) Like "ACBCustom Popup*" Then
RegistryAPI.DeleteRegistryValue lCBHandle, sValues(a)
End If
Next a
RegistryAPI.CloseRegistryKey (lCBHandle)

End Sub

RegistryAPI Module:

Option Compare Database
Option Explicit

' PREDEFINED REGISTRY KEYS
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_CONFIG = &H80000005
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003

' KEY SECURITY ACCESS METHODS
Private Const STANDARD_RIGHTS_ALL = &H1F0000
Private Const KEY_CREATE_LINK = &H20
Private Const KEY_CREATE_SUB_KEY = &H4
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_EVENT = &H1
Private Const KEY_NOTIFY = &H10
Private Const KEY_QUERY_VALUE = &H1
Private Const READ_CONTROL = &H20000
Private Const SYNCHRONIZE = &H100000
Private Const STANDARD_RIGHTS_EXECUTE = (READ_CONTROL)
Private Const STANDARD_RIGHTS_READ = (READ_CONTROL)
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
Private Const KEY_EXECUTE = ((KEY_READ) And (Not SYNCHRONIZE))
Private Const KEY_SET_VALUE = &H2
Private Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))

Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type

' REGISTRY API FUNCTIONS
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long
Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, ByVal lpType As Any, lpData As Byte, lpcbData As Long) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long

' REGISTRY ERROR RETURN VALUES
Private Const ERROR_NO_MORE_ITEMS = 259&
Private Const ERROR_SUCCESS = 0&

' REGISTRY VALUE TYPES
Private Const REG_BINARY = 3
Private Const REG_DWORD = 4
Private Const REG_DWORD_BIG_ENDIAN = 5
Private Const REG_DWORD_LITTLE_ENDIAN = 4
Private Const REG_EXPAND_SZ = 2
Private Const REG_FULL_RESOURCE_DESCRIPTOR = 9
Private Const REG_LINK = 6
Private Const REG_MULTI_SZ = 7
Private Const REG_NONE = 0
Private Const REG_SZ = 1

Function OpenRegistryKey(ByVal KeyParent As Long, ByVal KeyName As String) As Long

Dim lKeyHandle As Long
Dim lResult As Long

lResult = RegOpenKeyEx(KeyParent, KeyName, 0, KEY_ALL_ACCESS, lKeyHandle)
If lResult = 0 Then
OpenRegistryKey = lKeyHandle
Else
Err.Raise "Error Opening Registry Key. RegOpenKeyEx Returned " & lResult, "RegistryAPI"
End If

End Function

Function CloseRegistryKey(ByVal KeyHandle As Long)

RegCloseKey KeyHandle

End Function

Sub GetRegistryKeyValues(ByVal KeyHandle As Long, ByRef KeyValueNames() As String)

Dim a As Long
Dim lRet As Long
Dim sValue As String
Dim lValueLen As Long
Dim bData As Byte
Dim lDataLen As Long

lDataLen = 0

Do Until lRet <> ERROR_SUCCESS
sValue = String(16384, 0)
lValueLen = Len(sValue)
lRet = RegEnumValue(KeyHandle, a, ByVal sValue, lValueLen, 0, vbNullChar, ByVal bData, lDataLen)
If lRet = ERROR_NO_MORE_ITEMS Then
Exit Do
End If
ReDim Preserve KeyValueNames(a)
KeyValueNames(a) = Left(sValue, lValueLen)
a = a + 1
Loop

End Sub

Function DeleteRegistryValue(ByVal KeyHandle As Long, ByVal ValueName As String) As Long

Dim lRet As Long

lRet = RegDeleteValue(KeyHandle, ValueName)
DeleteRegistryValue = lRet

End Function

Since WordPress makes such a mess of this code and I have no clue how to easily fix it, I will post this on my main site via notepad.exe, then provide a link from here to it. D’OH!

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Please answer the anti-spam question: * Time limit is exhausted. Please reload CAPTCHA.