473,324 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Event handler for multiple command buttons

I would to set up a event routine for several command buttons. I need to be
able to identify by the caption or something whick button caused the event
to trigger. I think it's in the "sender" or "e" objects.
Private Sub cbOWN2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cbOWN2.Click, cbOWN3,Click

IF sender.caption = "cbOWN2" THEN bla bla bla ELSE yatta yatta

End Sub
Nov 18 '05 #1
2 1363
I figured it out. Use the CommandName and OnCommand attributes and then
define the function like so
e.CommandName then is the CommandName attribute of the button clicked
Public Sub cbIPID_click(ByVal sender As Object, ByVal e As CommandEventArgs)

"David A. Beck" <da****@beckb.com> wrote in message
news:eX**************@TK2MSFTNGP09.phx.gbl...
I would to set up a event routine for several command buttons. I need to be able to identify by the caption or something whick button caused the event
to trigger. I think it's in the "sender" or "e" objects.
Private Sub cbOWN2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cbOWN2.Click, cbOWN3,Click

IF sender.caption = "cbOWN2" THEN bla bla bla ELSE yatta yatta

End Sub

Nov 18 '05 #2
The sender is the object that triggered the event. Since it is passed in as
an object variable, you will need to cast it to the appropriate type and
then invoke the methods or properties you need in order to uniquely identify
who broadcast the event.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"David A. Beck" <da****@beckb.com> wrote in message
news:eX**************@TK2MSFTNGP09.phx.gbl...
I would to set up a event routine for several command buttons. I need to be able to identify by the caption or something whick button caused the event
to trigger. I think it's in the "sender" or "e" objects.
Private Sub cbOWN2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cbOWN2.Click, cbOWN3,Click

IF sender.caption = "cbOWN2" THEN bla bla bla ELSE yatta yatta

End Sub

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script...
18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
2
by: Keith Smith | last post by:
Is there a way to attach event handler code to multiple controls?
6
by: Steve Caliendo | last post by:
Hi, I'm creating 5 ImageButton controls in the panel control, and I have a unique ID specified for each one. When I click on any one of them, the Page_Load executes (Of course), but how do I...
3
by: akki | last post by:
I create link buttons dynamically in the code and give them IDs through which I can distinguish them.I want to know how to create a single event handler for all the link buttons that I create The...
6
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to...
9
by: jeff | last post by:
New VB user...developer... Situation...simplified... - I want to wrap a pre and post event around a system generated where the pre-event will always execute before the system event and the...
2
by: Bundy | last post by:
Hi On my webpages I have replaced the submit button with a rolling submit button using the script below (Script 1). This script is used by many of my webpages and is included in a external...
2
by: =?Utf-8?B?TWlrZSBSYW5k?= | last post by:
I have created a method that dynamically creates a single button control (as a proof-of-concept, I would like to be able to create multiple buttons). I set properties on this control including an...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.