Re: Disable button on custom ribbon

T

Tom van Stiphout

Not a command, because the ribbon works with callbacks. So you can
call InvalidateControl on this button, which will then call back to
your getEnabled callback function, where you can set the Enabled
attribute to True or False.

-Tom.
Microsoft Access MVP
 
T

tighe

Jim,

i had a hard time at first too so maybe some of this will help. i have been
to that site and some items take a leap to get where you want to be.

first make sure you have an onLoad="OnRibbonLoad" to start for your ribbon
item.

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="OnRibbonLoad" >

the vba:
Public Sub OnRibbonLoad(objRibbon As IRibbonUI)
Set gobjRibbon = objRibbon
End Sub

second for the object(button/toggle, etc.) will need to add a
getEnabled="Somename" ' name of the code it will call

<button id="cmdNMA" getEnabled="GetEnabled" /> ' leaving out other useful
ribbon attributes for clarification.

vba:
Public Sub GetEnabled(ctl As IRibbonControl, ByRef Enabled)
gobjRibbon.Invalidate

Select Case ctl.ID ' what ribbon property will be used to find items to enable
Case "cmdNMA": Set Enabled = Forms![Firm_Address]![BD] 'reason enabled
Case "cmdEmailRev": Set Enabled = [Forms]![001_Start]![EmailReview]
'another button id, uses the same code
End Select

End Sub

in this code you will notice it uses Case, so in essence you can load all
items into one Sub referenced by their "id." of course the reason you use to
enabled/disabled is up to you.

without going to much else farther you can replace ID, with Tag so maybe you
have a bunch of similar function buttons that will be enabled at the same
time. GetVisible works almost the same way.

good luck, i will try to keep notice of the post, i no longer receive emails.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top