This page is about creating and installing Microsoft Access Add-ins, and how to fix some of the errors that you might encounter.
Never made an add-in before? Its easy with a little knowledge, and a template you can download free
An add-in enables you run code in any database without having to create or import modules. Add-ins can save time and make your programs more accessible.
Add-ins aren't very well documented, and can be quirky to install, but when success happens, they're wonderful! I hope this page helps you, and saves you some frustration.
Run as administrator, USysRegInfo table, database properties, errors, code tips, etc.
To be recognized as an add-in, the install file needs to have an ACCDA extension. This will start as another file that has been renamed such as an ACCDB or ACCDE file. Access recognizes the ACCDA file extension. When you open it, you can do anything you could before.
Your add-in now appears on the Add-ins menu.
To see the USysRegInfo table that you'll be creating, you must set the Navigation Options to Show System Objects.
The USysRegInfo table holds information for the Windows Registry. The USys table prefix means that this is a user system table, and you must create it.
The USysRegInfo table should have the following data structure. I don't think the size of text fields matters, so you can make them shorter as long as they're long enough to hold what's needed.
Fieldname | Data Type | Size | Description |
---|---|---|---|
Subkey | Text | 255 | name of the registry Subkey where setting is stored. HKEY_CURRENT_ACCESS_PROFILE\Menu Add-Ins will be expanded to the official Add-in path for your software and version |
Type | Long | 4 | type of entry. 0=key, 1=string, 4=DWORD |
ValName | Text | 255 | registry value name |
Value | Text | 255 | registry value |
After you fill USysRegInfo with values, it might look something like this:
Its okay to have extra records. Key, Library, and Expression are required. Subkey is the same for each record thats part of the same menu option. You can create multiple Subkeys, but instead of doing that, consider launching a menu form.
The Subkey field is the same on each record for items relating to a menu option. You can put multiple subkeys in the USysRegInfo table if you want multiple options on the drop-down add-in menu. My opinion, however, is that it is better to show the user a menu form so they can pick one of multiple options. This way, the add-ins list stays shorter.
UsysRegInfo needs records for these value names:
Library Value is the path and filename. In this example, |ACCDIR will be expanded to the default library path for add-ins.
then the Expression Value would be:
Title, Company, and Comments are good to fill since they'll show up later in the Add-in Manager.
Title, Company, and Comments are displayed in the Add-in Manager
If you wish to remove an add-in, for whatever reason, first uninstall it from Access. This removes information in the registry.
To remove an add-in from Access, select it and click Uninstall.
The "x" indicator will go away when the add-in isn't installed.
The file is still there even though it isn't being used. Its readily available in case you want to install the add-in again.
It is important to uninstall before moving or deleting the file from the library path so the registry values are deleted. Otherwise, you may end up with an error message you can't get rid of.
In my case, an add-in didn't complete its installation because the case-sensitive Subkey error (discussed below) bit me, but there was no add-in to remove.
Somewhere, however, an incomplete key must was made in the registry, so I got an error message about that. That error didn't affect using other add-ins, including one with the same name as the error. I found the bad key in the registry, deleted it, and the error went away.
For my version of Access, the official registry key where add-ins are is:
HOWEVER, there is some discussion that if you expliticly specify a key, then Access won't dump add-ins when it updates.
If you export the Menu Add-ins key and its subkeys, you get a file like this:
HKEY_USERS\S-1-5-21-0123456789-0123456789-0123456789-1001 is the specification for HKEY_CURRENT_USER.
Add-ins can be tricky to get to work, especially the first few times. There are some things that will cause an add-in not to install, and it may not always be the same! What has worked in the past might not work another time, and vice-verse,
'New database sort order' (Options, General) can be an issue. If necessary to change, compact and repair database for it to take effect. Choose General.
Subkey can be case sensitive. Start with
HKEY_CURRENT_ACCESS_PROFILE\Menu Add-Ins\.
Its ironic that "Add-Ins" might need to use capital "I" since the key name in the registry uses a lowercase "i".
Make sure Key, Library, and Expression are specified in UsysRegInfo. Make sure their values are right. Ensure that subkey is correct and the same for all records of a menu option.
If you get a "bad state" error, something might be wrong with a name. Check the file name in the UsysRegInfo table. Make sure that your VBA Project Name, Module name, and Procedure names are all unique.
It seems that to avoid losing add-ins with updates, put a specific registry key in the Subkey field of the USysRegInfo table that isn't the version-specific path that Access will change.
This was unintentionally done during the AccessUserGroups presentation, and it caused Access to crash!
In one of my add-ins, I was using DMax. Recently that had to be changed to use a recordset. Should have done it that way to begin with.
This presentation to the Lunchtime chapter of AccessUserGroups.org, hosted by Maria Barnes, is packed with information.
This covers basics of creating an add-in for Microsoft Access
Here are some code tips for your add-in.
To open a form, specify the function name to run in the USysRegInfo table. In this case, Expression would be:
=LaunchMenu()
Function LaunchMenu() '200429 strive4peace DoCmd.OpenForm "MyMenuFormname" End Function
Anything you can do with a database object, like use a TableDef or OpenRecordset, will be done in whatever database you refer to.
To refer to the current database, use
Dim db As DAO.Database Set db = CurrentDb 'do stuff Set db = Nothing
To refer to the code database, use
Dim db As DAO.Database Set db = CodeDb 'do stuff Set db = Nothing
'make a blank database
DBEngine.CreateDatabase sPathFileDatabase,dbLangGeneral
Function Link2TableOtherDatabase(psPathFileDatabase As String _ ,psTablename As String) 'strive4peace 'When you are using Make Table and Append queries, 'use the optional IN clause to specify the path and filename of an external database. 'Then use this procedure to link to the table 'CALLS ' DropTheTable Dim db As DAO.Database _ ,tdf As DAO.TableDef 'set db to be the current database Set db = CurrentDb 'if table is already in the current database, delete it Call DropTheTable(psTablename, db) 'link to table With db Set tdf = .CreateTableDef(psTablename) tdf.Connect = ";Database=" & psPathFileDatabase tdf.SourceTableName = psTablename .TableDefs.Append tdf .TableDefs.Refresh End With 'release object variables Set tdf = Nothing Set db = Nothing End Function
Here for code to DropTheTable, which is called by Link2TableOtherDatabase. It deletes a table if it is in the passed or current database.
Dim AccessObject As AccessObject _ ,Obj As Object Dim i As Integer _ ,iCount As Integer _ ' --- Forms iCount = CurrentProject.AllForms.Count For i = 0 To iCount-1 Set AccessObject = CurrentProject.AllForms(i) DoCmd.OpenForm AccessObject.Name,acViewDesign Set Obj = Forms(AccessObject.Name) 'do stuff DoCmd.Close acForm,AccessObject.Name,acSaveNo Next i ' --- Reports iCount = CurrentProject.AllReports.Count For i = 0 To iCount-1 Set AccessObject CurrentProject.AllReports(i) DoCmd.OpenReport AccessObject.Name,acViewDesign Set Obj = Reports(AccessObject.Name) 'do stuff DoCmd.Close acReport,AccessObject.Name,acSaveNo Next i 'release object variables Set AccessObject = Nothing Set Obj = Nothing
Add-in Template for Access 365
Add-in Template for Access 2007
Add-ins are wonderful when they're working right! If you find yourself importing the same code over and over, consider turning it into an add-in!
When I started learning about Add-ins, there wasn't much good documentation on them, and still isn't. I hope this page will be a valuable resource for you, and prevent you from stumbling on the same things that I did!
Every now and then, something knocks out the installed add-ins even though the files are still there. In those cases, you just need to select each one and install what you want again. Alternately, you could back up and restore that branch of the registry, but I think I'd rather not do it that way.
If you get an error that I didn't mention, and fix it, please let me know what you did! Thanks ~