UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Programmatically Set The Default Ribbon..., Access 2010    
 
   
AdamL
post Jul 7 2017, 03:37 PM
Post#1



Posts: 143
Joined: 12-March 00
From: New York, NY


I've created my first two custom ribbons named, "Users" & "Developer" in the USysRibbons table. When I change them prior to opening the database in the File > Options > Current Database > Ribbon Name: setting they work flawlessly. However, I would like to programmatically load the applicable ribbon upon the starting of the database based on the user. (Determine the Windows login name on the current computer and if it is me, load the "Developer" ribbon if it isn't me, load the "Users" ribbon.)

In this Post Can we programmatically set the default ribbon? robcooper's reply suggests the following:

After calling LoadCustomUI, try:
CurrentProject.Properties.Add "CustomRibbonID", "<MyRibbon>"

If this is correct, I don't know how or when to call LoadCustomUI and then place the above statement.

Any help would be greatly appreciated.

Adam
Go to the top of the page
 
theDBguy
post Jul 7 2017, 03:55 PM
Post#2


Access Wiki and Forums Moderator
Posts: 71,220
Joined: 19-June 07
From: SunnySandyEggo


Hi Adam,

If you're using the USysRibbons table, I don't think you'll need to use the LoadCustomUI method anymore.

Just a thought...

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Microsoft Access MVP | Access Website | Access Blog | Email
Go to the top of the page
 
AdamL
post Jul 7 2017, 03:59 PM
Post#3



Posts: 143
Joined: 12-March 00
From: New York, NY


theDBguy,

If that's the case, do you have any idea where I would place this statement to change the custom ribbon?

CurrentProject.Properties.Add "CustomRibbonID", "<MyRibbon>"

Adam
Go to the top of the page
 
theDBguy
post Jul 7 2017, 04:08 PM
Post#4


Access Wiki and Forums Moderator
Posts: 71,220
Joined: 19-June 07
From: SunnySandyEggo


Try creating a public function with this code and then execute it from an Autoexec macro.

Hope it helps...

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Microsoft Access MVP | Access Website | Access Blog | Email
Go to the top of the page
 
AdamL
post Jul 7 2017, 04:29 PM
Post#5



Posts: 143
Joined: 12-March 00
From: New York, NY


Unfortunately, that didn't work, besides I'd rather do it outside of an Autoexec Macro. Are there any other suggestions? Thanks.

Adam
Go to the top of the page
 
theDBguy
post Jul 7 2017, 10:56 PM
Post#6


Access Wiki and Forums Moderator
Posts: 71,220
Joined: 19-June 07
From: SunnySandyEggo


Hi,

I only know two places where you can execute code at start up, the autoexec macro or the display form.

There is another way by using a command line switch.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Microsoft Access MVP | Access Website | Access Blog | Email
Go to the top of the page
 
AdamL
post Jul 8 2017, 06:31 AM
Post#7



Posts: 143
Joined: 12-March 00
From: New York, NY


After many trials and errors, I have determined the issue is Microsoft changed the way Ribbons are handled from Access 2007 to Access 2010. You no longer need the LoadCustomUI. (As theDBguy stated earlier.) Therefore, this code won't work in Access 2010:

After calling LoadCustomUI, try:
CurrentProject.Properties.Add "CustomRibbonID", "<MyRibbon>"

I found this very informative article about Creating Dynamic Ribbon Customizations, but it is for Access 2007:

https://msdn.microsoft.com/en-us/library/dd...office.12).aspx

This leaves me where I started. How can I programmatically set the default ribbon in Access 2010? Anyone? blush.gif

Adam
Go to the top of the page
 
theDBguy
post Jul 8 2017, 02:02 PM
Post#8


Access Wiki and Forums Moderator
Posts: 71,220
Joined: 19-June 07
From: SunnySandyEggo


Hi Adam,

I posted this demo over a year ago. It's not exactly what you are asking for, but I hope it might give you some ideas or options.

Hope it helps...
Attached File(s)
Attached File  theDBguyTwoRibbonsDemo.zip ( 36.81K )Number of downloads: 12
 

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Microsoft Access MVP | Access Website | Access Blog | Email
Go to the top of the page
 
AdamL
post Jul 9 2017, 06:22 AM
Post#9



Posts: 143
Joined: 12-March 00
From: New York, NY


theDBguy,

Thanks for the demo database. As demonstrated in your example, I guess I could programmatically set the ribbon for every form in the database. It would be tedious but it would work. It just seems that there should be a way to programmatically set the default ribbon for the entire database at runtime. Thanks again for your help.

Adam
Go to the top of the page
 
theDBguy
post Jul 9 2017, 10:22 AM
Post#10


Access Wiki and Forums Moderator
Posts: 71,220
Joined: 19-June 07
From: SunnySandyEggo


Hi Adam,

I agree, there should be. If I find another way, I'll let you know. In the meantime, I added two lines to the demo to do what you're asking. However, it requires a restart of the app to see the default ribbon change.

Hope it helps...
Attached File(s)
Attached File  theDBguyTwoRibbonsDemo.zip ( 39.87K )Number of downloads: 12
 

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Microsoft Access MVP | Access Website | Access Blog | Email
Go to the top of the page
 
AdamL
post Jul 9 2017, 12:08 PM
Post#11



Posts: 143
Joined: 12-March 00
From: New York, NY


theDBguy,

As in your demo database, this works just fine:

CODE
CurrentDb.Properties("CustomRibbonID") = Me.cboRibbon   ' Where Me.cboRibbon = the name of the Ribbon


But as you stated, it requires a restart of the database which defeats the purpose for what I want to accomplish. Thanks for all your help. I hope someone can give us another way. (If there is one.) smile.gif

Adam
Go to the top of the page
 
theDBguy
post Jul 9 2017, 02:39 PM
Post#12


Access Wiki and Forums Moderator
Posts: 71,220
Joined: 19-June 07
From: SunnySandyEggo


Hi Adam,

Not sure you realize even if you change the default ribbon manually by going through the options menu, it still requires a restart for the change to take effect. So, I am not really sure what you're trying to accomplish by changing the default ribbon on an already started database application. The only other option I could think of is to use a launcher app to change the default ribbon on the actual database file and then launches it.

Just my 2 cents...

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Microsoft Access MVP | Access Website | Access Blog | Email
Go to the top of the page
 
AdamL
post Jul 9 2017, 03:13 PM
Post#13



Posts: 143
Joined: 12-March 00
From: New York, NY


theDBguy,

As I originally stated:

QUOTE
I've created my first two custom ribbons named, "Users" & "Developer" in the USysRibbons table. When I change them prior to opening the database in the File > Options > Current Database > Ribbon Name: setting they work flawlessly. However, I would like to programmatically load the applicable ribbon upon the starting of the database based on the user. (Determine the Windows login name on the current computer and if it is me, load the "Developer" ribbon if it isn't me, load the "Users" ribbon.)


Thanks.

Adam
Go to the top of the page
 
mklein
post Jul 9 2017, 03:18 PM
Post#14



Posts: 264
Joined: 7-August 12
From: BC, Canada


I believe you could solve this by making a single application-level main ribbon, but creating additional tabs that you could then programmatically show or hide based on some criteria. So imagine you create a boolean function called GetUserIsDeveloper() which does just what you think. Then you can add a tab to the application's ribbon with code like...
CODE
      <tab id="tabTest" label="Test Tab" insertBeforeMso="TabHomeAccess" getVisible="RibbonGetVisible" >
        <group id="grpTest" label="Test Group" >
          <button id="btnTest" label="Test Button" />
        </group>
      </tab>

...and add a callback, like...
CODE
Sub RibbonGetVisible(irc As IRibbonControl, state)
    Select Case irc.ID
        Case "tabTest"
            state = GetUserIsDeveloper()
    End Select
End Sub

...which calls the Public Function GetUserIsDeveloper() as Boolean.

Using this approach you can conditionally show or hide a "Developer" tab on a main ribbon.

hth
Mark

--------------------
| Mark Klein | Access 2010 | Windows 10 | Visual Studio 2013
Go to the top of the page
 
AdamL
post Jul 9 2017, 03:30 PM
Post#15



Posts: 143
Joined: 12-March 00
From: New York, NY


Mark,

That is an excellent approach and now a second alternative to programmatically setting the ribbon for every form in the database. It is becoming painfully apparent that you can't change the default ribbon programmatically as I want to. Thanks.

Adam
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    12th December 2017 - 10:27 PM