Ribbon Creator

speakers_86

Registered User.
Local time
Today, 01:51
Joined
May 17, 2007
Messages
1,919
I have been trying to use ribbon creator to make a custom ribbon. It's pretty straight forward, except for the combo boxes. I want to use a combo box or a drop down box and base the values on a query. Anyone know how to do that?
 
I took a look and couldn't figure out what I am doing wrong.
 
Glad to hear that you at least found something to get you moving. Good luck with your project.
 
Alright, so I kind of sort of have it. It's not quite right yet, but I'll get there tormorrow.

Here was my reference. I was looking at 16. If you like to dl sample db, thats a good site.
 
Ok. Glad to hear you are at least still moving along.
 
I've just about got this all sorted out. But how do you pull the value of the list box after change? Not the index, I want to see what is actually there. Alternatively, how to convert from index to string?

Code:
Sub OnActionDropDown(control As IRibbonControl, _
                     selectedId As String, _
                     selectedIndex As Integer)
    ' Callbackname in XML File "OnActionDropDown"

    ' Callback onAction (DropDown)

    Select Case control.ID

        Case "ddc1"
            ' In Tab:   tab0
            ' In Group: grp0
'            Select Case selectedId
'            End Select
            DoCmd.OpenForm "frmdatabasewindow"
            [Forms]![frmdatabasewindow]![frmDatabaseWindowSub].[Form].Filter = "[group2]='" & label & "'"
        Case "ddc2"
            ' In Tab:   tab0
            ' In Group: grp0
'            Select Case selectedId
'            End Select
        Case "ddc3"
            ' In Tab:   tab0
            ' In Group: grp_1
'            Select Case selectedId
'            End Select
        Case "ddc4"
            ' In Tab:   tab0
            ' In Group: grp_1
'            Select Case selectedId
'            End Select
        Case "ddc5"
            ' In Tab:   tab0
            ' In Group: grp_1
'            Select Case selectedId
'            End Select
        Case Else
            Select Case selectedId
                Case Else
                    MsgBox "The selected ItemID of DropDown-Control """ & control.ID & """ is : """ & selectedId & """" & vbCrLf & _
                           "Die selektierte ItemID des DropDown-Control """ & control.ID & """ ist : """ & selectedId & """", _
                           vbInformation
            End Select
    End Select

End Sub


The callbacks that fill the dropdowns:

Code:
Sub CallbackDDGetItemCount(control As IRibbonControl, ByRef count)
    'Informa a comboBox, através da variável count, a quantidade de registros da tabela tblClientes, que
    'será a quantidade de linhas da combobox.
    Dim QueryName As String
    Select Case control.ID
        Case "ddc1"
            QueryName = "qrygroup2group1Ribbon"
            count = Nz(DCount("*", QueryName), 0)
            'count = Nz(DCount("*", "qrygroup2Group1"), 0)
        Case "ddc2"
            QueryName = "qrygroup3group1Ribbon"
            count = Nz(DCount("*", QueryName), 0)
            'count = Nz(DCount("*", "qrygroupGroup3group1"), 0)
        Case "dd3"
            QueryName = "qrygroup1nullYourObjects"
            count = Nz(DCount("*", QueryName), 0)
            'count = Nz(DCount("*", "qrygroup1null"), 0)
        Case "ddc4"
            QueryName = "qrygroup2group1YourObjects"
            count = Nz(DCount("*", QueryName), 0)
            'count = Nz(DCount("*", "qrygroup2Group1"), 0)
        Case "ddc5"
            QueryName = "qrygroup3group1Yourobjects"
            count = Nz(DCount("*", QueryName), 0)
            'count = Nz(DCount("*", "qrygroup3Group1"), 0)
        Case Else
            count = Nz(DCount("*", "qrygroup1null"), 0)
    End Select



End Sub

Sub CallbackDDGetItemLabel(control As IRibbonControl, index As Integer, ByRef label)
    Static j   As Boolean
    Select Case control.ID
        Case "ddc1"
            Select Case j
                Case False
                    Set rs = CurrentDb.OpenRecordset("qrygroup2group1Ribbon")
                    If rs.RecordCount = 0 Then Exit Sub
                    rs.MoveFirst
                    label = rs!Group2
                    j = True
                Case True
                    rs.MoveNext
                    label = rs!Group2
                    If index = (rs.RecordCount - 1) Then
                        j = False
                        rs.Close
                        Set rs = Nothing
                    End If
            End Select
        Case "ddc2"
            Select Case j
                Case False
                    Set rs = CurrentDb.OpenRecordset("qrygroup3group1Ribbon")
                    If rs.RecordCount = 0 Then Exit Sub
                    rs.MoveFirst
                    label = rs!Group3
                    j = True
                Case True
                    rs.MoveNext
                    label = rs!Group3
                    If index = (rs.RecordCount - 1) Then
                        j = False
                        rs.Close
                        Set rs = Nothing
                    End If
            End Select
        Case "ddc3"
            Select Case j
                Case False
                    Set rs = CurrentDb.OpenRecordset("qrygroup1nullYourObjects")
                    If rs.RecordCount = 0 Then Exit Sub
                    rs.MoveFirst
                    label = rs!Group1
                    j = True
                Case True
                    rs.MoveNext
                    label = rs!Group1
                    If index = (rs.RecordCount - 1) Then
                        j = False
                        rs.Close
                        Set rs = Nothing
                    End If
            End Select
        Case "ddc4"
            Select Case j
                Case False
                    Set rs = CurrentDb.OpenRecordset("qrygroup2group1YourObjects")
                    If rs.RecordCount = 0 Then Exit Sub
                    rs.MoveFirst
                    label = rs!Group2
                    j = True
                Case True
                    rs.MoveNext
                    label = rs!Group2
                    If index = (rs.RecordCount - 1) Then
                        j = False
                        rs.Close
                        Set rs = Nothing
                    End If
            End Select
        Case "ddc5"
            Select Case j
                Case False
                    Set rs = CurrentDb.OpenRecordset("qrygroup3group1Yourobjects")
                    If rs.RecordCount = 0 Then Exit Sub
                    rs.MoveFirst
                    label = rs!Group3
                    j = True
                Case True
                    rs.MoveNext
                    label = rs!Group3
                    If index = (rs.RecordCount - 1) Then
                        j = False
                        rs.Close
                        Set rs = Nothing
                    End If
            End Select
    End Select


    '    Dim rs As Recordset
    '    Select Case control.Id
    '        Case ddc1
    '            Set rs = CurrentDb.OpenRecordset("qrygroup2group1Ribbon")
    '            If rs.RecordCount = 0 Then Exit Sub
    '            rs.MoveFirst
    '            Do Until rs.EOF
    '                label = rs!Group1
    '                rs.MoveNext
    '            Loop
    '    End Select


End Sub
 
Last edited:
Anyone know how to do this? I was thinking of filling an array during the item label callback, but it is hard to think that the information can't simply be pulled from the control. I can see the value, so I don't see why I can't reference it.
 
Anyone know how to do this? I was thinking of filling an array during the item label callback, but it is hard to think that the information can't simply be pulled from the control. I can see the value, so I don't see why I can't reference it.

Yes


This is required as a public variable-
Code:
Public bolList As Variant
Public gobjRibbon As IRibbonUI

XML Callback-
Your callback needs to call the vba function
Code:
onAction="VBAFunction"
The Routines-
This is the OnLoad element-
Code:
Public Sub OnRibbonLoad(ribbon As IRibbonUI)
    'Callbackname im XML File "onLoad"
    
    Call PopulateSelect
   

    Set gobjRibbon = ribbon

End Sub

This populates the combo box
Code:
Sub PopulateSelect()

    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Dim lngLoopCount As Long

    Set db = CurrentDb()
    Set rst = db.OpenRecordset("tblMyTable", dbOpenTable)

    On Error Resume Next
    lngLoopCount = 0
    With rst
        If .EOF Then .MoveFirst
        glngItemCount = .RecordCount
        ReDim bolList(glngItemCount - 1)
        Do While Not (.EOF)
            bolList(lngLoopCount) = ![FieldToBeInComboBox].Value
            .MoveNext
            lngLoopCount = lngLoopCount + 1
        Loop
    End With

    rst.Close
    db.Close
    Set rst = Nothing
    Set db = Nothing
    
    Exit Sub
    
End Sub

The Click action-
Code:
Sub cboSelect_Click(control As IRibbonControl, text As String)

    Dim sCName As String
    Dim rs As DAO.Recordset

    sCName = "[FieldToBeInComboBox] = '" & text & "'"
    Forms![mainform].SetFocus

    With Forms![mainform]
        Set rs = .RecordsetClone
        rs.FindFirst sCName
        If Not rs.NoMatch Then
        .Bookmark = rs.Bookmark
      
        Else
            If MsgBox("The listbox item you have entered is not listed. would you like to add it?", vbYesNo, "messagebox description") = vbYes Then
            AddListBoxItem ' or whatever routine you have to add a new record related to the listbox contents
            Exit Sub
           
        End If
        End If
    End With
     

End Sub
This is required but left as is-
Code:
Sub cboSelect_getItemCount(control As IRibbonControl, ByRef returnedVal)
    returnedVal = glngItemCount

End Sub

Sub cboSelect_getItemID(control As IRibbonControl, index As Integer, ByRef ID)
    ID = "itemcboSelect" & index
End Sub

Sub cboSelect_getItemLabel(control As IRibbonControl, index As Integer, ByRef returnedVal)
    returnedVal = bolList(index)

End Sub

After a new record is added, you need to update the combo box-
Code:
gobjRibbon.InvalidateControl "GrpMyGroup"
you need to replace GrpMyGroup with the name of the group that your combo box is in

I think thats it :)


Cheers


nigel
 
Well I would love to try your code, but I'm at work, and it looks like 2007 does not support my ribbon. Anyone know why?

Code:
<!-- Created with IDBE RibbonCreator 2010 (Version: 1.1012) -->
<!--                http://www.RibbonCreator2010.com               -->
<!--                 http://www.RibbonCreator2010.de               -->

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="OnRibbonLoad" loadImage="LoadImages">
  <ribbon startFromScratch="false">
    <tabs>
      <tab id="tab0" insertBeforeMso = "TabHomeAccess"  label="Aphrodite" getVisible ="GetVisible" tag = "RibbonName:=IDBERibbonCreator2010;CustomTagValue1:=;CustomTagValue2:=;CustomTagValue3:=" > 
        <group id="grp0" autoScale="false" centerVertically="false" label="Aphrodite Objects" getVisible ="GetVisible" tag = "RibbonName:=IDBERibbonCreator2010" > 
          <button id="btn1" size="large" label="DB Window" imageMso="ChooseForm" tag="RibbonName:=IDBERibbonCreator2010;inMenu:=;CustomTagValue1:=;CustomTagValue2:=;CustomTagValue3:=;CustomPicture:=;CustomPicturePath:=" onAction="OnActionButton" getVisible="GetVisible" getEnabled="GetEnabled" />
          <button id="btn2" size="large" label="Close All" imageMso="BroadcastEnd" tag="RibbonName:=IDBERibbonCreator2010;inMenu:=;CustomTagValue1:=;CustomTagValue2:=;CustomTagValue3:=;CustomPicture:=;CustomPicturePath:=" onAction="OnActionButton" getVisible="GetVisible" getEnabled="GetEnabled" />
          <button id="btn3" size="large" label="AutoExec" imageMso="ArrangeByImportance" tag="RibbonName:=IDBERibbonCreator2010;inMenu:=;CustomTagValue1:=;CustomTagValue2:=;CustomTagValue3:=;CustomPicture:=;CustomPicturePath:=" onAction="OnActionButton" getVisible="GetVisible" getEnabled="GetEnabled" />
          <editBox id="ebx1" label="Search for" screentip="Search for an object name" supertip=" " getText="GetTextEditBox" onChange="OnChangeEditBox" tag="RibbonName:=IDBERibbonCreator2010;inMenu:=;CustomTagValue1:=;CustomTagValue2:=;CustomTagValue3:=;DefaultValue:=;CustomPicture:=;CustomPicturePath:=" getVisible="GetVisible" getEnabled="GetEnabled" />
          <dropDown id="ddc1" label="Group2" onAction="OnActionDropDown" getVisible="GetVisible" getEnabled="GetEnabled" getItemCount="CallbackDDGetItemCount" getItemLabel="CallbackDDGetItemLabel" tag="RibbonName:=IDBERibbonCreator2010;inMenu:=;CustomTagValue1:=;CustomTagValue2:=;CustomTagValue3:=;DefaultValue:=;CustomPicture:=;CustomPicturePath:=">
          </dropDown>
          <dropDown id="ddc2" label="Group3" onAction="OnActionDropDown" getVisible="GetVisible" getEnabled="GetEnabled" getItemCount="CallbackDDGetItemCount" getItemLabel="CallbackDDGetItemLabel" tag="RibbonName:=IDBERibbonCreator2010;inMenu:=;CustomTagValue1:=;CustomTagValue2:=;CustomTagValue3:=;DefaultValue:=;CustomPicture:=;CustomPicturePath:=">
          </dropDown>
        </group>
        <group id="grp_1" autoScale="false" centerVertically="false" label="Your Objects" getVisible ="GetVisible" tag = "RibbonName:=IDBERibbonCreator2010" > 
          <dropDown id="ddc3" label="Group1" onAction="OnActionDropDown" getVisible="GetVisible" getEnabled="GetEnabled" getItemCount="CallbackDDGetItemCount" getItemLabel="CallbackDDGetItemLabel" tag="RibbonName:=IDBERibbonCreator2010;inMenu:=;CustomTagValue1:=;CustomTagValue2:=;CustomTagValue3:=;DefaultValue:=;CustomPicture:=;CustomPicturePath:=">
          </dropDown>
          <dropDown id="ddc4" label="Group2" onAction="OnActionDropDown" getVisible="GetVisible" getEnabled="GetEnabled" getItemCount="CallbackDDGetItemCount" getItemLabel="CallbackDDGetItemLabel" tag="RibbonName:=IDBERibbonCreator2010;inMenu:=;CustomTagValue1:=;CustomTagValue2:=;CustomTagValue3:=;DefaultValue:=;CustomPicture:=;CustomPicturePath:=">
          </dropDown>
          <dropDown id="ddc5" label="Group3" onAction="OnActionDropDown" getVisible="GetVisible" getEnabled="GetEnabled" getItemCount="CallbackDDGetItemCount" getItemLabel="CallbackDDGetItemLabel" tag="RibbonName:=IDBERibbonCreator2010;inMenu:=;CustomTagValue1:=;CustomTagValue2:=;CustomTagValue3:=;DefaultValue:=;CustomPicture:=;CustomPicturePath:=">
          </dropDown>
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>
 
Hi

2007 will support ribbons so you must have incorrect syntax. Without checking myself which I will do later, XML is very specific. Group id is different to groupid and groupId. It has to be in camel case too.

What if any, errors are you getting?

Cheers

N
 
See the attached picture. The ribbon works in 2010. But here on my work computer, it just errors, it will open, but no custom ribbon.
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    86.4 KB · Views: 172
I'm too tired to work through this now, but I have some questions/statements after looking at your code. Let me provide what I already have more clearly first.

The XML:
Just look above this post.

Callback GetItemCount. My understanding is that this sub determines how long the drop down list will be. Is that right?
Code:
Sub CallbackDDGetItemCount(control As IRibbonControl, ByRef count)
    Dim QueryName As String
    Select Case control.ID
        Case "ddc1"
            QueryName = "qrygroup2group1Ribbon"
            count = Nz(DCount("*", QueryName), 0)
        Case Else
            count = Nz(DCount("*", "qrygroup1null"), 0)
    End Select
End Sub


Here is the GetItemLabel. I believe this is what populates the drop down. Once I get the values in the drop down, I don't know how to get them back out. I think an array as you seem to be proposing would work. I just don't see why I can't get the values out more simply.
Code:
Sub CallbackDDGetItemLabel(control As IRibbonControl, index As Integer, ByRef label)
    Static j   As Boolean
    Select Case control.ID
        Case "ddc1"
            Select Case j
                Case False
                    Set rs = CurrentDb.OpenRecordset("qrygroup2group1Ribbon")
                    If rs.RecordCount = 0 Then Exit Sub
                    rs.MoveFirst
                    label = rs!Group2
                    If rs.RecordCount = 1 Then Exit Sub
                    j = True
                Case True
                    rs.MoveNext
                    label = rs!Group2
                    If index = (rs.RecordCount - 1) Then
                        j = False
                        rs.Close
                        Set rs = Nothing
                    End If
            End Select
    End Select
End Sub

The on action. I believe this fires when the end user makes a selection in the drop down box.
Code:
'DropDown
Sub OnActionDropDown(control As IRibbonControl, selectedId As String, selectedIndex As Integer)
    Select Case control.ID
        Case "ddc1"
            DoCmd.OpenForm "frmdatabasewindow"
            [Forms]![frmdatabasewindow]![frmDatabaseWindowSub].[Form].Filter = "[group2]='" & strText & "'"
         Case Else
            Select Case selectedId
                Case Else
                    MsgBox "Unhandled case in OnActionDropDown in basRibbonCallbacks."
            End Select
    End Select
End Sub


I am looking at your sub PopulateSelect. You said that that populates the combo box, but when I look at it, it looks like it fills an array. I think the drop down is populated in Callback GetItemLabel. Is that right? Also, you provided code for a click event. Does this object have a click event?

Note- I cut a lot of my code out just to make it simpler to read. I cut out irrelevant stuff about other controls.
 
This line uses the schema version 2010, which is incompatible with the 2007 version

<customUI ...microsoft.com/office/2009/07/customui" onLoad="OnRibbonLoad" loadImage="LoadImages">


use the scheme of the 2007 version that caters for you to use with Access 2010

<customUI ....microsoft.com/office/2006/01/customui" onLoad="OnRibbonLoad" loadImage="LoadImages">
 
Okay Ari, it errors with this too.

Code:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="OnRibbonLoad" loadImage="LoadImages">
  <ribbon startFromScratch="false">
 
After following instructions here about showing UI errors, I got a much more detail error message. There are some things that are not compatible with 2007. They were the group autoCenter, a picture, and a few other properties of groups. When I removed all of these things, there was an error about the type on my callback.

edit- I'll play with this more later, but will 2010 work with 2007 ribbons?
 

Users who are viewing this thread

Back
Top Bottom