Access VBA: many CommandButton execute same code

后端 未结 2 1870
清歌不尽
清歌不尽 2021-01-27 19:58

I have a form with many buttons. Most of these buttons have a .tag field where I identify their function (numeric field)

Every button, on click, should execute same code

相关标签:
2条回答
  • 2021-01-27 20:28

    You can call a function from the form module directly from the button click events, and use Screen.ActiveControl to determine the calling button.

    Private Function GenericButton()
    
        Debug.Print "Called from " & Screen.ActiveControl.Name
    
        Call WriteTimbraIN(CInt(Screen.ActiveControl.Tag))
        DoCmd.Close
    
    End Function
    

    And then assign =GenericButton() as OnClick event.
    You can do this in one go by multi-selecting all buttons and then setting the property.

    0 讨论(0)
  • 2021-01-27 20:40

    Yes, use WithEvents. An example can be found here:

    Create Windows Phone Colour Palette and Selector using WithEvents

    0 讨论(0)
提交回复
热议问题