Results 1 to 5 of 5
  1. #1
    akhmadahdiyat is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Oct 2013
    Posts
    21

    Customized Ribbon, OnAction VBA failed

    hi.. i'm beginner in access 2013


    I created a customized ribbon, A toggle button with OnAction

    <toggleButton id="DaftarItemToogleButton" size="normal" label="DaftarItem" imageMso="TableOfContentsDialog" onAction="DaftarItemToogleButtonOnAction"/>

    when I created a macro to open form named "Daftar Item" it succeed, but I want it in VBA way..
    I'm stuck in VBA, so I convert it from the macro I've created before.
    After convert, delete the macro, the VBA function weren't running. I wonder why..
    Converted macro :

    Function DaftarItemToogleButtonOnAction()
    On Error GoTo DaftarItemToogleButtonOnAction_Err

    DoCmd.OpenForm "Daftar Item", acNormal, "", "", , acNormal

    DaftarItemToogleButtonOnAction_Exit:
    Exit Function

    DaftarItemToogleButtonOnAction_Err:
    MsgBox Error$
    Resume DaftarItemToogleButtonOnAction_Exit

    End Function

    Please help me..
    Last edited by akhmadahdiyat; 10-20-2013 at 03:02 AM. Reason: hopeless

  2. #2
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    India
    Posts
    616
    The function should be in a module as a Public Function. Create a new module and try with the code below.
    Try
    Code:
    Public Function DaftarItemToogleButtonOnAction()
    On Error GoTo DaftarItemToogleButtonOnAction_Err
    
        DoCmd.OpenForm "Daftar Item", acNormal
    
    DaftarItemToogleButtonOnAction_Exit:
        Exit Function
    
    DaftarItemToogleButtonOnAction_Err:
        MsgBox Error$
        Resume DaftarItemToogleButtonOnAction_Exit
    
    End Function
    See this site for further reading http://www.accessribbon.de/en/?Acces...s:ToggleButton

  3. #3
    akhmadahdiyat is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Oct 2013
    Posts
    21
    edit to public func, sub, public sub still failed.
    even in http://www.accessribbon.de sampleribbon2.accdb using "sub" and succed to run.

    Sub MyToogleButtonCallbackOnAction(control As IRibbonControl, pressed As Boolean)
    ' Callback Togglebutton click
    Select Case control.ID
    Case "MyToogleButton1"
    bolEnabled = pressed
    gobjRibbon.InvalidateControl "MyButton"
    Case "MyToogleButton2"
    bolVisible = pressed
    gobjRibbon.InvalidateControl "MyButton"
    End Select
    End Sub


    then I move my custom ribbon to sampleribbon2.accdb

    RibbonName: ToggleButtons
    RibbonXML:
    <toggleButton id="MyToogleButton1" size="large" label="Large Toggle Button" imageMso="HappyFace"
    getPressed="MyToogleButtonCallbackGetPressed" onAction="DaftarItemButtonOnAction"/>
    it succed to call the sub (I changed to DaftarItemButtonOnAction)

    Sub DaftarItemButtonOnAction(control As IRibbonControl, pressed As Boolean)
    MsgBox "DaftarItemButtonOnAction"
    End Sub


    but failed to call the sub in my custom ribbon: (Microsoft Access cannot run the macro or callback function 'DaftarItemButtonOnAction')
    RibbonName: MyRibbon
    RibbonXML:
    <button id="DaftarItemButton" size="large" label="Daftar Item" imageMso="MacroDefault" onAction="DaftarItemButtonOnAction"/>

  4. #4
    akhmadahdiyat is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Oct 2013
    Posts
    21
    I think I knew one thing for sure. A button must have (control As IRibbonControl) and a toggle button must have (control As IRibbonControl, pressed As Boolean)

    <button id="MenuUtamaButton" size="large" label="Menu Utama" imageMso="BlogHomePage" onAction="ButtonClick"/>

    Sub ButtonClick(control As IRibbonControl)
    On Error GoTo exitsub
    DoCmd.OpenForm Left(control.Id, Len(control.Id) - 6)
    Exit Sub
    exitsub:
    MsgBox "Form """ & Left(control.Id, Len(control.Id) - 6) & """ not found."
    End Sub
    this will result opening a form named like button id, but minus button.
    if the form was not found it will pop up message box says the form not found.

    Sub ToggleButtonClick(control As IRibbonControl)
    On Error GoTo exitsub
    DoCmd.OpenForm Left(control.Id, Len(control.Id) - 6)
    Exit Sub
    exitsub:
    MsgBox "Form """ & Left(control.Id, Len(control.Id) - 6) & """ not found."
    End Sub


    but still I can't figure why it cann't run on my database,. Finally I import all my database, etc to sampleribbon2.accdb

    now it's working.. thanks all..

  5. #5
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    India
    Posts
    616
    To use as the function as in my post, you need to modify the Ribbon XML as below.The changes required are in red colour.
    Code:
    <toggleButton id="DaftarItemToogleButton" size="normal" label="DaftarItem" imageMso="TableOfContentsDialog" onAction="=DaftarItemToogleButtonOnAction()"/>

Please reply to this thread with any new information or opinions.

Similar Threads

  1. OnAction attribute error in RibbonXML
    By needtechhelp in forum Programming
    Replies: 2
    Last Post: 10-20-2013, 01:21 PM
  2. Making and Using Customized Ribbons
    By ebrommhead in forum Programming
    Replies: 1
    Last Post: 04-05-2013, 01:00 PM
  3. Customized Scroll Bar
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 09-05-2010, 04:26 PM
  4. Customized Toolbars
    By croydon in forum Programming
    Replies: 4
    Last Post: 10-07-2009, 11:05 AM
  5. customized menu bar
    By marianne in forum Access
    Replies: 13
    Last Post: 04-12-2009, 09:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums