Setting the Ribbon Name in Code
You don't need to use the options dialog to set a custom ribbon for your Microsoft Access application.
The typical way to choose a custom ribbon in an Access application is via File > Options > Current Database > Ribbon Name.
But what if you want to assign that ribbon name in code? It's quite easy once you know where the information is stored: in a database property named CustomRibbonID:
So, if we wanted to set the application-level ribbon to our Print Preview ribbon, we could use the following code:
CurrentDB.Properties("CustomRibbonID").Value = "gbRibbonPrintPreview"
Handling the "Property not found" Error
Now, let's say you haven't set a custom Ribbon Name through the Options dialog yet–or you set it at one time but then cleared it out:
If your "Ribbon and Toolbar Options" look like the above screenshot, then you won't be able to assign a value to the CustomRibbonID database property because it doesn't exist:
In this situation, you would need to create the property itself and then append it to the database properties collection. You can do this in a single line of code if you wanted to:
CurrentDB.Properties.Append CurrentDB.CreateProperty("CustomRibbonID", dbText, "gbRibbonTaxColl2k")
The problem is that if you run the above code and the property already exists, then you'll get a different error message:
The SetProp()
Routine
Rather than worrying about whether the property exists or not, you can just use my SetProp()
routine which will handle either scenario gracefully:
SetProp "CustomRibbonID", "gbRibbonTaxColl2k"
Referenced articles
External references
Image by Bruno /Germany from Pixabay