Link to home
Start Free TrialLog in
Avatar of jackbenson
jackbensonFlag for United Kingdom of Great Britain and Northern Ireland

asked on

use VBA to load a Ribbon in Access 2010

Hi,

i have a database that is used by different users.

i have create the USysRibbon table and created 2 ribbons.

at the moment in Options.. Curent Database.. i can select a Ribbon to use.

What i hope is that there is some VBA that i can use instead of using the database options so i can load a ribbon.

This way i can load different ribbons for different users.

i have tried DoCmd.ShowToolbar but that did not work.

thanks

jack
Avatar of rockiroads
rockiroads
Flag of United States of America image

You can try changing the database property

CurrentDb.Properties("CustomRibbonID").Value = "MyRibbonName"

db usually requires a restart to see the changes though
Avatar of jackbenson

ASKER

excellent

that works.

you have to have a value set in Options.. Curent Database.. Ribbon Name

otherwise i get an error saying that the Property Does Not Exist when i try to set it.

would be great if there was a way that did not require a re-start.

thanks

jack
if its a new property you can create one. We can check the error code then create the property if it dont exist.

when you select it manually like you did via Options, Access itself tells you right? Perhaps its because it is something that is loaded on application startup (access internals) and it is not easily configurable when using access. So
Here is a function to create a new Property:

Public Function SDB_SetProperty(argPrpName As String, argPrpType, argPrpVal)

'ExtName:Set Property
'Actions:Sets the specified database property
   
    On Error GoTo SDB_SetProperty_Error
   
    Dim prp As Property
    CurrentDb.Properties(argPrpName) = argPrpVal
    SDB_SetProperty = True
   
SDB_SetProperty_Exit:
    On Error Resume Next
    Set prp = Nothing
    Err.Clear
    Exit Function

SDB_SetProperty_Error:
    If Err.Number = 3270 Then   'Property not found
        Set prp = CurrentDb.CreateProperty(argPrpName, argPrpType, argPrpVal)
        CurrentDb.Properties.Append prp
        SDB_SetProperty = True
    Else
        SDB_SetProperty = False
        MsgBox "An unexpected error has occurred: " & Err.Number & "  " & Err.Description
    End If
    GoTo SDB_SetProperty_Exit

End Function

mx
THANKS MX

i am calling the function as follows:

DB_SetProperty "CustomRibbonID", dbText, "TOOLS"

where "TOOTS" is the name of my ribbon

but i get the following message - Type Missmatch

the problem is caused on this line of code:
Set prp = CurrentDb.CreateProperty(argPrpName, argPrpType, argPrpVal)

what is the correct value for argPrpType that i should be passing?

thanks

jack
ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial