A dynamic ribbon dropdown?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NicholasMcM
    New Member
    • Sep 2011
    • 1

    A dynamic ribbon dropdown?

    I am creating a custom ribbon with a dropdown/combo box, is there anyway of making this dynamic, by basing it on a query?

    Thanks in advance,

    Nicholas
  • Hennepin
    New Member
    • Oct 2009
    • 25

    #2
    What ever triggers to change your query will change a variable (cmbTDEngGroup in the example code) that can be seen by your ribbon callbacks. Then need to invalidate the control forcing it to reload'

    Code:
    Public gobjRibbon As IRibbonUI
    Dim comboLabels() as string
    
    ' Callback Count of items and fills in items into arrays
    Sub RibbonCBGetItemCount(control As IRibbonControl, ByRef count)
    
        Dim i As Integer, s As String
        Dim rst_type As Recordset
    
        s = "SELECT DISTINCTROW DC_Desc FROM Drawing_Catagory WHERE  DC_level0 = " & cmbTDEngGroup & " ORDER BY DC_level1;"
        Set rst_type = CurrentDb.OpenRecordset(s, dbOpenForwardOnly)
        i = 0
        ReDim comboLabels(i) ' comboLabels is a dynamic array 
        comboLabels(i).sLabel = ""
        i = 1
        Do Until rst_type.EOF
            ReDim Preserve comboLabels(i)
            comboLabels(i) = rst_type!DC_Desc
            rst_type.Move 1
            i = i + 1
        Loop
        count = i
        rst_type.Close
    end sub    
    
    
    ' callback to get each item
    Sub RibbonGetItemLabel(control As IRibbonControl, Index As Integer, ByRef label)
        Select Case control.id
            Case "cmbComboGroup"
                label = comboLabels(Index).sLabel
            Case Else
        End Select
    End Sub

    Comment

    Working...