PC Review


Reply
Thread Tools Rate Thread

Anyone know why this doesn't work ?

 
 
kirkm
Guest
Posts: n/a
 
      29th Jul 2009

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
 
Reply With Quote
 
 
 
 
kirkm
Guest
Posts: n/a
 
      30th Jul 2009
On Wed, 29 Jul 2009 18:24:22 -0400, smartin <(E-Mail Removed)>
wrote:


>So what happens? I would expect, by reading this code, that you could
>only untick a box by ticking the other one.


That's exactly what I want, i.e you can only choose one of them.
But what does happen is odd. Try it out. I think Excels applying a
built in toggle which won't disable.
 
Reply With Quote
 
kirkm
Guest
Posts: n/a
 
      30th Jul 2009
On Wed, 29 Jul 2009 22:40:21 -0400, smartin <(E-Mail Removed)>
wrote:


>
>Works as expected. I click on box 1 and, regardless of its previous
>state, it becomes or remains selected, box 2 becomes or remains
>unselected, and status bar reads box 1. Similar for box 2. And, box 1
>and box 2 always have opposite state.


Weird. That sounds like what I wanted it to do.... but doesn't.
The first click on Box1 select 1 with Box2 is unselected. Then click
Box2 and nothing happens. (Except the status bar message)
>
>What are you trying to do? If you want mutually exclusive selections,
>options buttons are the control of choice.


Yes, that works. But check boxes were preferred.
 
Reply With Quote
 
Lars-Åke Aspelin
Guest
Posts: n/a
 
      30th Jul 2009
On Wed, 29 Jul 2009 21:26:43 +1200, kirkm <(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Defrag doesn't work because chkdsk doesn't work =?Utf-8?B?bWVnYW4=?= Windows XP Performance 2 3rd Jun 2007 03:21 PM
macro doesn't properly record AutoSum (and SendKeys doesn't work) =?Utf-8?B?Y3JpbXNvbmtuZw==?= Microsoft Excel Programming 2 21st Nov 2006 02:11 PM
Idle-timed Hibernate and/or standby sometimes works and sometimes doesn't, why doesn't it work properly all the time??? harry Windows XP Customization 1 15th Jan 2004 09:34 PM
Idle-timed Hibernate and/or standby sometimes works and sometimes doesn't, why doesn't it work properly all the time???????? harry Windows XP Performance 0 15th Jan 2004 08:35 AM
Idle-timed Hibernate and/or standby sometimes works and sometimes doesn't, why doesn't it work properly all the time?????? harry Windows XP Help 0 15th Jan 2004 08:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:34 PM.