@@ -2,31 +2,43 @@ const AddInName = "ACLib-AccUnit-Loader"
22const AddInFileName = "AccUnitLoader.accda"
33const MsgBoxTitle = "Update ACLib-AccUnit-Loader"
44
5+ Dim AddInFileInstalled, CompletedMsg
6+
57MsgBox "Before updating the add-in file, the add-in must not be loaded!" & chr( 13 ) & _
6- "For safety, close all Access instances." , , MsgBoxTitle & ": Hinweis "
8+ "For safety, close all Access instances." , , MsgBoxTitle & ": Information "
79
8- Select Case MsgBox( "Should the add-in be used as ACCDE ?" + chr( 13 ) & _
10+ Select Case MsgBox( "Should the add-in be used as a compiled file (accde) ?" + chr( 13 ) & _
911 "(Add-In is compiled and copied to the Add-In directory.)" , 3 , MsgBoxTitle)
1012 case 6 ' vbYes
11- if CreateMde(GetSourceFileFullName, GetDestFileFullName) = True then
12- MsgBox "Compiled file was created." , , MsgBoxTitle
13- else
14- MsgBox "Error! Compiled file was not created." , , MsgBoxTitle
15- end if
13+ AddInFileInstalled = CreateMde(GetSourceFileFullName, GetDestFileFullName)
14+ If AddInFileInstalled Then
15+ CompletedMsg = "Add-In was compiled and saved in '" + GetAddInLocation + "'."
16+ Else
17+ CompletedMsg = "Error! Compiled file was not created."
18+ End If
1619 case 7 ' vbNo
1720 DeleteAddInFiles
18- if CopyFileAndRundPrecompileProc(GetSourceFileFullName, GetDestFileFullName) Then
19- MsgBox "File was copied." , , MsgBoxTitle
20- else
21- MsgBox "Error! File was not copied." , , MsgBoxTitle
22- end if
21+ AddInFileInstalled = CopyFileAndRundPrecompileProc(GetSourceFileFullName, GetDestFileFullName)
22+ If AddInFileInstalled Then
23+ CompletedMsg = "Add-In was saved in '" + GetAddInLocation + "'."
24+ Else
25+ CompletedMsg = "Error! File was not copied."
26+ End If
2327 case else
2428
2529End Select
2630
31+ If AddInFileInstalled = True Then
32+ RegisterAddIn GetDestFileFullName()
33+ End If
34+
35+ If CompletedMsg > "" Then
36+ MsgBox CompletedMsg, , MsgBoxTitle
37+ End If
38+
2739
2840'##################################################
29- ' Hilfsfunktionen:
41+ ' Functions
3042
3143Function GetSourceFileFullName()
3244 GetSourceFileFullName = GetScriptLocation & AddInFileName
@@ -37,38 +49,29 @@ Function GetDestFileFullName()
3749End Function
3850
3951Function GetScriptLocation()
40-
4152 With WScript
4253 GetScriptLocation = Replace(.ScriptFullName & ":" , .ScriptName & ":" , "" )
4354 End With
44-
4555End Function
4656
4757Function GetAddInLocation()
48-
4958 GetAddInLocation = GetAppDataLocation & "Microsoft\AddIns\"
50-
5159End Function
5260
5361Function GetAppDataLocation()
54-
5562 Set wsShell = CreateObject( "WScript.Shell" )
5663 GetAppDataLocation = wsShell.ExpandEnvironmentStrings( "%APPDATA%" ) & "\"
57-
5864End Function
5965
6066Function FileCopy(SourceFilePath, DestFilePath)
61- Set AccessApp = CreateObject( "Access.Application" )
6267 set fso = CreateObject( "Scripting.FileSystemObject" )
6368 fso.CopyFile SourceFilePath, DestFilePath
6469 FileCopy = True
6570End Function
6671
6772Function DeleteAddInFiles()
68-
6973 Set fso = CreateObject( "Scripting.FileSystemObject" )
7074 DeleteAddInFilesFso fso
71-
7275End Function
7376
7477Function DeleteAddInFilesFso(fso)
@@ -143,3 +146,64 @@ Function RunPrecompileProcedure(AccessApp, SourceFilePath)
143146 RunPrecompileProcedure = True
144147
145148End Function
149+
150+
151+ '##################################################
152+ ' Register Menu Add-In
153+
154+ Function RegisterAddIn(AddInFile)
155+
156+ Dim AddInDb, AccessApp, rst, ItemValue, wsh
157+
158+ Set AccessApp = CreateObject( "Access.Application" )
159+ Set AddInDb = AccessApp.DBEngine.OpenDatabase(AddInFile)
160+
161+ set wsh = CreateObject( "WScript.Shell" )
162+ Set rst = AddInDb.OpenRecordset( "select Subkey, ValName, Type, Value from USysRegInfo where ValName > '' Order By ValName" , 8 ) 'dbOpenForwardOnly=8
163+ Do While Not rst.EOF
164+ ItemValue = rst.Fields( "Value" ).Value
165+ If Len(ItemValue) > 0 Then
166+ If InStr( 1 , ItemValue, "|ACCDIR" ) > 0 Then
167+ ItemValue = AddInDb.Name
168+ End If
169+ End If
170+ RegisterMenuAddInItem AccessApp, wsh, rst.Fields( "Subkey" ).Value, rst.Fields( "ValName" ).Value, rst.Fields( "Type" ).Value, ItemValue
171+ rst.MoveNext
172+ Loop
173+ rst.Close
174+
175+ AddInDb.Close
176+
177+ End Function
178+
179+ Function RegisterMenuAddInItem(AccessApp, wsh, ByVal SubKey, ByVal ItemValName, ByVal RegType, ByVal ItemValue)
180+ Dim RegName
181+ RegName = GetRegistryPath(SubKey, AccessApp)
182+ With wsh
183+ If Len(ItemValName) > 0 Then
184+ RegName = RegName & "\" & ItemValName
185+ End If
186+ .RegWrite RegName, ItemValue, GetRegTypeString(RegType)
187+ End With
188+ End Function
189+
190+ Function GetRegTypeString( ByVal RegType)
191+ Select Case RegType
192+ Case 1
193+ GetRegTypeString = "REG_SZ"
194+ Case 4
195+ GetRegTypeString = "REG_DWORD"
196+ Case 0
197+ GetRegTypeString = vbNullString
198+ Case Else
199+ Err.Raise vbObjectError, "GetRegTypeString" , "RegType not supported"
200+ End Select
201+ End Function
202+
203+ Function GetRegistryPath(SubKey, AccessApp)
204+ GetRegistryPath = Replace(SubKey, "HKEY_CURRENT_ACCESS_PROFILE" , HkeyCurrentAccessProfileRegistryPath(AccessApp))
205+ End Function
206+
207+ Function HkeyCurrentAccessProfileRegistryPath(AccessApp)
208+ HkeyCurrentAccessProfileRegistryPath = "HKCU\SOFTWARE\Microsoft\Office\" & AccessApp.Version & "\Access"
209+ End Function
0 commit comments