I'm developing an app for a client in MS Access using VBA. I'm new to the Ribbon but I do understand how to enable/disable buttons based on when a form is opened. My challenge now is enabling a button (Open Document) when node is clicked in a list view on another form.
To further explain: A master form contains a list of documents in a ListViewCtl control with the Doc ID as a tag. When the user clicks a node a global variable (gbCurDoc) is set to the tag. That's when I'd like to enable the button in the ribbon that, when clicked, opens the file (gbCurDoc > 0). But I want that button disabled if no document is selected (gbCurDoc = 0).
My VBA:
Public Sub ControlEnabled(control As IRibbonControl, ByRef enabled)
Select Case control.Tag
Case "DocOpen"
If gbCurDoc = 0 Then
enabled = False
Else
enabled = True
End If
myRibbon.InvalidateControl ("DocOpen")
End Select
End Sub
The XML looks like this:
<button id="DocOpen" getImage="GetImageCallBack" size="large" tag="DocOpen" onAction="ribOpenForm" getEnabled="ControlEnabled" supertip="Open Document" />