none
how to link buttons by events in toolbar activex access 2010 RRS feed

  • Question

  • i have form i added active x toolbar MSComctlLib.Toolbar.2

    i added many buttons but i want on click on button make some events

    Sunday, June 19, 2016 8:15 AM

Answers

  • In the Declarations section of your form's VBA module write:
    |Dim WithEvents myToolbar As MSComctlLib.Toolbar

    In your form's Form_Open event write:
    Set myToolbar = Me.Toolbar7.Object

    Now the myToolbar.ButtonClick event is available, where you can write your code to do whatever the button indicates. For example:
    Private Sub myToolbar_ButtonClick(ByVal Button As MSComctlLib.Button)
        If Button.Caption = "Form1" then DoCmd.OpenForm "Form1"
    End Sub


    -Tom. Microsoft Access MVP

    Sunday, June 19, 2016 4:43 PM
  • Hi moghamer016,

    you have to use the code like below. properties are available for that.

    If Button.Caption = "F3" And Button.ButtonMenus.Item(3).Text = "Form3" Then DoCmd.OpenForm "Form3"

    property name are also same when you set by Toolbar properties window.

    Note if you write this line on existing event then it will execute when you click on dropdown.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by moghamer016 Tuesday, June 21, 2016 3:53 AM
    Tuesday, June 21, 2016 3:18 AM
    Moderator

All replies

  • Can you please elaborate and also post your code?

    Best regards, George

    Sunday, June 19, 2016 3:48 PM
  • In the Declarations section of your form's VBA module write:
    |Dim WithEvents myToolbar As MSComctlLib.Toolbar

    In your form's Form_Open event write:
    Set myToolbar = Me.Toolbar7.Object

    Now the myToolbar.ButtonClick event is available, where you can write your code to do whatever the button indicates. For example:
    Private Sub myToolbar_ButtonClick(ByVal Button As MSComctlLib.Button)
        If Button.Caption = "Form1" then DoCmd.OpenForm "Form1"
    End Sub


    -Tom. Microsoft Access MVP

    Sunday, June 19, 2016 4:43 PM
  • thanks for replay
    i don't know how upload my sample db any way
    i use access 2010
    i opened access and create form in design then i click on activex control to add Microsoft toolbar control  6.0 sp6

    then i add two buttons on toolbar one of them drop down

    i want on click on form2 button just open form2 and on click on form3 from drop down menu just open form3 etc.
    thanks

    Monday, June 20, 2016 1:48 AM
  • thanks for replaythere is no code just activex control i don't know how to add vba code to activate buttons on click


    i don't know how upload my sample db any way
    i use access 2010
    i opened access and create form in design then i click on activex control to add Microsoft toolbar control  6.0 sp6

    then i add two buttons on toolbar one of them drop down

    i want on click on form2 button just open form2 and on click on form3 from drop down menu just open form3 etc.
    thanks
    Monday, June 20, 2016 1:49 AM
  • Hi moghamer016,

    I have check and test the suggestion given by the Tom van Stiphout (MVP).

    it is working and opening form when you click on Microsoft Toolbar control.

    he had mentioned the steps to create an event and how to place code on that.

    but its look like you still confused and not getting it what he suggest you.

    I would recommend you to again try to follow the steps mentioned by him and still after that you having problem let us know. we will try to help you further.

    if you think that Microsoft Toolbar control is something difficult to use then you can also use command buttons.

    if you want to use command buttons Follow the steps below.

    First add the buttons then go to its properties.

    Then select Event Tab.

    Then create Event on OnClick.

    Vbe editor will be open.

    place the code below and try to run the form.

    DoCmd.OpenForm "Employees"

    if you think that the suggestion given by the Tom van Stiphout (MVP) solves your issue please mark the suggestion given by him as an Answer.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, June 20, 2016 2:40 AM
    Moderator
  • thanks sir it's working
    but if button like drop down menu
    how can i write code
    i try
    If Button.ButtonMenus.Text = "form3" Then DoCmd.OpenForm "Form3"

    but not working

    thanks

    Monday, June 20, 2016 4:15 AM
  • thanks sir it's working
    but if button like drop down menu
    how can i write code
    i try
    If Button.ButtonMenus.Text = "form3" Then DoCmd.OpenForm "Form3"

    but not working

    thanks
    Monday, June 20, 2016 4:15 AM
  • Hi moghamer016,

    you can only make 1 myToolbar_ButtonClick Event.

    I think you are trying to create multiple myToolbar_ButtonClick Event.

    in the same event you have to place the code to check the DropDown.

    like below.

    Private Sub myToolbar_ButtonClick(ByVal Button As MSComctlLib.Button)
         If Button.Caption = "Form1" Then DoCmd.OpenForm "Form1"
         If Button.Caption = "Form3" Then DoCmd.OpenForm "Form3"
     End Sub
    
     

    I had tested and it opening the form 3 when you click on Dropdown.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, June 20, 2016 4:41 AM
    Moderator
  • thanks
    but Dropdown button caption is sales
    and it has 2 buttons like invoice and form3

    i want when i click on form3 button from sales menu just open form3
    thanks

    Monday, June 20, 2016 4:53 AM
  • Hi moghamer016,

    you have to use the code like below. properties are available for that.

    If Button.Caption = "F3" And Button.ButtonMenus.Item(3).Text = "Form3" Then DoCmd.OpenForm "Form3"

    property name are also same when you set by Toolbar properties window.

    Note if you write this line on existing event then it will execute when you click on dropdown.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by moghamer016 Tuesday, June 21, 2016 3:53 AM
    Tuesday, June 21, 2016 3:18 AM
    Moderator
  • Hi moghamer016,

    you can visit the links below in which you can find the events for toolbar on which you can try to check combo box value.

    Toolbar Events

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, June 21, 2016 3:31 AM
    Moderator
  • thanks it works i used this code
    Private Sub myToolbar_ButtonMenuClick(ByVal ButtonMenu As MSComctlLib.ButtonMenu)
    If ButtonMenu.Text = "form3" Then DoCmd.OpenForm "form3"
    End Sub

    thanks
    done
    Tuesday, June 21, 2016 4:29 AM