View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Lars-Åke Aspelin[_2_] Lars-Åke Aspelin[_2_] is offline
external usenet poster
 
Posts: 913
Default Anyone know why this doesn't work ?

On Wed, 29 Jul 2009 21:26:43 +1200, kirkm wrote:


There's a Form with 2 checkboxes and these Click events

Private Sub chkK1_Click()
chkK1 = True
chkA1 = False
Application.StatusBar = "chkK1"
End Sub

Private Sub chkA1_Click()
chkA1 = True
chkK1 = False
Application.StatusBar = "chkA1"
End Sub


The intent is, as chkK1 is ticked, chkA1 will bceome unticked and Vice
versa.

But it doesn't work! How can it NOT work ???

I've also tried .Value = and .Caption = and removed' = True'
(in case that was automatic), but still no go.

What am I doing wrong? At least the Application.StatusBar message
works !

Thanks - Kirk


A problem with your code seems to be that the manipulation of the
checkbox value from inside the code also fires the click event.
You thereby get into an "infinite loop" that is only interrupted
because some internal event buffer (or what it might be called) gets
overloaded.
Put this statement as the first statement of any of you click
procedures and you will see from the behaviour of cell A1 what I mean

Worksheets("Sheet1").Cells(1, 1) = Worksheets("Sheet1").Cells(1, 1)
+ 1

In my case, Excel 2007, cell A1 is increased to 284 before Excel
"gives up".

I suggest you use radiobuttons instead of checkboxes is you want the
mutual exlusive property. If you insist on using checkboxes, you will
have to try to find the "source" of the click event to see if it is a
mouse click or from user code. I don't know if that is possible in
VBA.

Hope this helps / Lars-Åke