How to Disable/Enable two pushbuttons at the same time using a checkbox in LO Basic

Good day to everyone!

I want to thank Lupp for the code I started with. It was written for only one button on the worksheet.
https://ask.libreoffice.org/t/button-properties-enabled-on-off/60881

I would like it to work with two buttons, but it only works on hte first button. I have tried arranging this code a dozen different ways. I am at a loss.

The macro runs on a "1’ or “0” value in a cell linked to a checkbox. I want both pushbuttons Enabled or both Disabled depending in the status of checkbox…

Can anyone tell why this does not work and how to correct it?

Much thanks in advance

Sub ToggleButtonStatus(pEvent)

activeM = pEvent.Source.Model
activeM2 = pEvent.Source.Model
myButtonName = activeM.Tag
myButtonName2 = activeM2.Tag
theForm = activeM.Parent
theForm2 = activeM2.Parent
myButton = theForm.getByName(myButtonName)
myButton2 = theForm2.getByName(myButtonName2)

If activeM.State = 0 OR activeM2.State = 0 Then
     myButton.Enabled  = False
     myButton.Label   = "Not Enabled"
     myButton2.Enabled  = False
     myButton2.Label   = "Not Enabled"
   Else
      myButton.Enabled = True
      myButton.Label   = "Enabled"  
      myButton2.Enabled = True
      myButton2.Label   = "Enabled"
End If   

End Sub

pretty similar, aren’t they ?

or 2 forms ? :thinking: