Duplicating of Message Boxes

J

Jim May

The below shows the 2 MB's Twice -- OK the first time, but I ned to
eliminate them from ccurring the 2nd time (text only shows - no values)
Thanks,

Private Sub ComboBox1_Change()
Application.EnableEvents = False
MsgBox "You have chosen " & ComboBox1.Value
MsgBox "The next step in this macro will deselect it"
Me.ComboBox1.ListIndex = -1
Application.EnableEvents = True
End Sub
 
D

Dave Peterson

..enableevents will stop worksheet events, workbook events, application events
from firing. Not events for these controls.

But you can mimic it:

Dim BlkProc as boolean
Private Sub ComboBox1_Change()
if blkproc = true then exit sub

MsgBox "You have chosen " & ComboBox1.Value
MsgBox "The next step in this macro will deselect it"

blkproc = true
Me.ComboBox1.ListIndex = -1
blkproc = false

End Sub
 
J

Jim May

Thanks Dave. Can you reinterate a bit on what the code is doing here?
I can follow it some, but not all-the-way.
Thanks,
Jim
 
D

Dave Peterson

The code just sets a toggle. You turn it on right before you change something
that would cause the _change procedure to fire.

It doesn't stop the event from firing a second time, but that first line says
that if the toggle is on, don't do any of the real code--just get the heck out.

And after you make the change, you turn that toggle off.

Step through it and you'll see that it really does fire twice.
 
J

Jim May

Pretty Cool, it's amazing what all you have to consider in doing something
like this.
Thanks, Dave I (much) better understand - by stepping through the code.
 
D

Dave Peterson

You can observe a lot just by watching!

<vbg>

Jim said:
Pretty Cool, it's amazing what all you have to consider in doing something
like this.
Thanks, Dave I (much) better understand - by stepping through the code.
 

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

Similar Threads

Problem with code 0
Out of Stack Space error 2
code crashing my programme??????? 4
Please check my code!!!! 1
cancel a combobox change 1
ComboBox doing a double take? 2
Combo Box 0
Userform problem (Listindex) 1

Top