0

I have tried arranging this code a dozen different ways. I am at a loss. It only works on the first button.

The macro runs on a "1' or "0" value in the cell linked to a checkbox. I want either both pushbuttons Enabled or both Disabled.

Can anyone tell why this does not work?

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" myButton.Enabled = True myButton2.Label = "Enabled" End If End Sub 

2 Answers 2

1

You never enable the second button, because of a simple copy+paste error:

Else myButton.Enabled = True myButton.Label = "Enabled" myButton.Enabled = True ^^^ should have been myButton2 myButton2.Label = "Enabled" 
Sign up to request clarification or add additional context in comments.

Comments

1

It looks like you are setting the activeM and activeM2 to the same object, the pEvent.Source.Model, so they both reference the same control.

Specify the second button differently. You can put both names in the tag and then split them when you are checking in the subroutine, or you can hardcode the button names. Hardcoding would be easier to manage.

Sub ToggleButtonStatus(pEvent) activeM = pEvent.Source.Model theForm = activeM.Parent myButton = theForm.getByName("MyButtonName") ' Replace with actual name myButton2 = theForm.getByName("MyButtonName2") ' Replace with actual name If activeM.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 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.