ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Duplicating of Message Boxes (https://www.excelbanter.com/excel-discussion-misc-queries/176938-duplicating-message-boxes.html)

Jim May

Duplicating of Message Boxes
 
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

Dave Peterson

Duplicating of Message Boxes
 
..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

Jim May wrote:

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


--

Dave Peterson

Jim May

Duplicating of Message Boxes
 
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

"Dave Peterson" wrote:

..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

Jim May wrote:

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


--

Dave Peterson


Dave Peterson

Duplicating of Message Boxes
 
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.

Jim May wrote:

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

"Dave Peterson" wrote:

..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

Jim May wrote:

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


--

Dave Peterson


--

Dave Peterson

Jim May

Duplicating of Message Boxes
 
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.

"Dave Peterson" wrote:

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.

Jim May wrote:

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

"Dave Peterson" wrote:

..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

Jim May wrote:

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

--

Dave Peterson


--

Dave Peterson


Dave Peterson

Duplicating of Message Boxes
 
You can observe a lot just by watching!

<vbg

Jim May wrote:

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.

"Dave Peterson" wrote:

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.

Jim May wrote:

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

"Dave Peterson" wrote:

..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

Jim May wrote:

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

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson


All times are GMT +1. The time now is 06:34 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com