• option button in toolbar (Access 2000)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » option button in toolbar (Access 2000)

    Author
    Topic
    #432309

    Can somebody help me build an option button in a toolbar ? I mean a button with dropped down 2 possibilities needed to build a code.I can build a single button with the code shown below.i will be grateful if someone could help me built an option button with the same code.

    Sub ToolbarCustomers()

    Dim cbr As Object
    Dim cbb As Object
    ‘ msoBarTop = 1
    Set cbr = CommandBars.Add(Name:=”MyToolbarCustomers”, Position:=1, Temporary:=True)

    1. msoControlButton = 1 First buton MyBack2
    Set cbb = cbr.Controls.Add(Type:=1, Temporary:=True)
    With cbb
    ‘.Caption = “My Button”
    ‘ msoButtonCaption = 2
    ‘ .Style = 2
    .FaceId = 41
    .Width = 60
    .FontWeight = 800

    .OnAction = “MyBack2”
    End With

    Viewing 0 reply threads
    Author
    Replies
    • #1013854

      There’s no such thing as an “Option Button” or Option Group for toolbar, the Office CommandBar object model does not provide this functionality. Your choices for toolbar controls are limited to command buttons, menus, edit controls, and combo boxes. You can simulate the functionality of an Option Group by setting the CommandBarButton State property to “Up” (not selected) or “Down” (selected) to indicate which “option” is currently selected.

      Attached file (Access 2K format) demonstrates how to do this using the CommandBarButton OnAction property. Custom toolbar “Toolbar 1” should be displayed when open db. When you click one of the card suit buttons, the button will be “selected”. The buttons under “Menu 1” are grouped into “Option Groups” – click buttons to see how works. The text-only menu items will display a checkmark to indicate the “selected” option. In actual use you’d replace the dummy msgbox with actual code to run when button is selected. The code is generic so that you don’t have to specify which group the button is in – just be sure that each button in “option group” has the same Tag property, and that the Tag is unique for each group.

      Public Function ButtonOnActionFunction()
      SetToolbarButtonState
      MsgBox "Toolbar Button " & Application.CommandBars.ActionControl.Caption & " OnAction function.", _
      vbInformation, "BUTTON ON ACTION FUNCTION"
      End Function

      Private Function SetToolbarButtonState()
      On Error GoTo Err_Handler

      Dim ctl As Office.CommandBarControl
      Dim ctlActive As Office.CommandBarControl
      Dim strMsg As String
      Dim strCaption As String

      Set ctlActive = Application.CommandBars.ActionControl
      strCaption = ctlActive.Caption

      ' Loop thru controls in parent object:
      For Each ctl In ctlActive.Parent.Controls
      ' test Tag property to match that of active button control
      If ctl.Tag = ctlActive.Tag Then
      If ctl.Caption = strCaption Then
      ' "Select" item:
      ctl.State = msoButtonDown
      Else
      ' "De-Select" item:
      ctl.State = msoButtonUp
      End If
      Else
      ' do nothing - not in same "Option group"
      End If
      Next ctl

      Exit_Proc:
      Set ctl = Nothing
      Set ctlActive = Nothing
      Exit Function
      Err_Handler:
      Select Case Err.Number
      Case 0
      Resume Next
      Case Else
      strMsg = "Error No " & Err.Number & ": " & Err.Description
      MsgBox strMsg, vbExclamation, "SetToolbarButtonState - Unexpected Error"
      Resume Exit_Proc
      End Select
      End Function

      Note – can also define event procedures for command bar controls but in this case was simpler to use OnAction property to run code.

      HTH

    Viewing 0 reply threads
    Reply To: option button in toolbar (Access 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: