Intercepting click event of built-in button

T

Thomson Mui

Hi,

I'm using VB6 to write an Outlook Add-in for Outlook 2003. I need to
intercept the click event of some built-in buttons from the Explore object
because the Outlook object model does not have all the events I need.

The problem is if I have multiple explorers running, the click event will be
triggered multiple times, when the button is pressed once. I know I need to
set the .tag property to some unique value to avoid the event being trigged
more than once, if it is a new button, but the trick does not work for
built-in button controls.

I have a class to wrap the explorer collection and the class has it's own
variable to hold the button object

My code looks like this:


Set oBtnHelp = oExplorer.CommandBars("Standard").Controls("Help")
oBtnHelp.tag = "some unique value for each explorer"
......
......
Private Sub oBtnHelp_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
'Do something for this event
End Sub

Could anyone show me what I need to do to fix the issue?

Thanks,
Thomson
 
K

Ken Slovak - [MVP - Outlook]

You can't set the properties on built-in buttons that would enable avoiding
this, so you have to use something like flags to avoid the problem. Set a
global flag when the click is first handled and let the other handlers test
for that flag. Use something like a timer to clear the flag after a short
period of time so the next legitimate click is then handled.
 
T

Thomson Mui

Thanks alot. I will try your suggestion.


Ken Slovak - said:
You can't set the properties on built-in buttons that would enable avoiding
this, so you have to use something like flags to avoid the problem. Set a
global flag when the click is first handled and let the other handlers test
for that flag. Use something like a timer to clear the flag after a short
period of time so the next legitimate click is then handled.
 
M

Michael

An additional thing you could give a try is to get the explorers.count
and then count the events triggered by the relevant button. Once the
explorers.count has been reached you can get ready for the next click event.
Finally you can mix this with the previous suggestions from Ken just in
case one event will not be fired for an unknown reason...

happy coding!

-Michael
 

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