Can anyone help with _click() events?

P

Peter

I'm trying to display a form that cycles through a list of items and
displays checkboxes that are ticked or unticked depending on the item
properties.

I have written code that uses the _click() event to determine if the
status has changed (ie someone has ticked what was previously unticked /
vice versa) and then retrieve via an inputbox some more details which
are then inserted into the sheet.

HOWEVER, what seems to happen is that Excel is recognising the cycling
of items as being _click events and pops up the box for input whenever
the checkbox moves from unticked to ticked because the item it refers to
has that property even if you haven't clicked on the actual checkbox.

Am I missing something fundamental?

Any help gratefully received.

Peter
 
B

Bob Phillips

Peter,

It would help if you show us the code, and explain what type of checkboxes
they are (worksheet forms, control toolbox or userforms).

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
P

Peter

Bob said:
Peter,

It would help if you show us the code, and explain what type of checkboxes
they are (worksheet forms, control toolbox or userforms).

OK, it's a user form laid out as follows...

SPIN Control TextBox Checkbox1 Checkbox2

As the spin button is moved up and down (corresponding to a unique ID) a
corresponding textbox.value is displayed together with the status of two
possible flags, checkbox1 and Checkbox2. Example:

Member_ID Name Committe_Member Attending_annual_trip
1 Jason Y N
2 Paul N Y

etc. (FYI this is an abstracted example, the actual usage would take too
long to explain!)

So, in this example when Paul gets elected to the committee I want to
put a tick in the box and add an e-mail address to a list (and vice
versa). If Jason decides to go on the trip I want to be able to place a
tick in the checkbox which will automatically fire up an input box that
asks how much money he is placing as a deposit.

My difficulty is this, if I move to a member_ID which has the
annual_trip button already checked then the input box pops up as if the
_click() event has fired. I could understand it if I had used _change()
as the displayed Checkbox2.Value will have "changed"

Hope this clarifies?

Peter
 
S

Stephen Bullen

Hi Peter,
My difficulty is this, if I move to a member_ID which has the
annual_trip button already checked then the input box pops up as if the
_click() event has fired. I could understand it if I had used _change()
as the displayed Checkbox2.Value will have "changed"

Hope this clarifies?

Setting the value of a check box does indeed fire the _Click event. Most
people get around this by using a 'mbNoEvents' module-level variable:

Dim mbNoEvents As Boolean

'In the spin button code:
mbNoEvents = True
CheckBox1.Value = True
CheckBox2.Value = False
mbNoEvents = False

Private Sub CheckBox1_Click()

If mbNoEvents then Exit sub

'... do whatever
End Sub



Regards

Stephen Bullen
Microsoft MVP - Excel
www.oaltd.co.uk
 
P

Peter

Stephen said:
Setting the value of a check box does indeed fire the _Click event. Most
people get around this by using a 'mbNoEvents' module-level variable:

Dim mbNoEvents As Boolean

'In the spin button code:
mbNoEvents = True
CheckBox1.Value = True
CheckBox2.Value = False
mbNoEvents = False

Private Sub CheckBox1_Click()

If mbNoEvents then Exit sub

'... do whatever
End Sub

Many, many thanks for this. As it happens I'd worked something out on
the same lines embedded in the _click code but yours is a more elegant
solution.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top