473,397 Members | 1,960 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,397 software developers and data experts.

What can I check to see if a button has been clicked?

167 100+
I have a scenario that I have several buttons on a form, let's say, button1 & button2. When button1 is clicked, it runs button1 code. When button2 is clicked, it runs button2 code and then calls button1_click and runs button1 code as well. My dilema is when the button1 code is run, I need to know if button1 was clicked causing the code to run as I need to add some code to only run if button1 was clicked and not if it is the case where button1 code is run because it was called by button2 when it was clicked. Hope this isn't too confusing!!
Jun 11 '07 #1
4 1763
FishVal
2,653 Expert 2GB
I have a scenario that I have several buttons on a form, let's say, button1 & button2. When button1 is clicked, it runs button1 code. When button2 is clicked, it runs button2 code and then calls button1_click and runs button1 code as well. My dilema is when the button1 code is run, I need to know if button1 was clicked causing the code to run as I need to add some code to only run if button1 was clicked and not if it is the case where button1 code is run because it was called by button2 when it was clicked. Hope this isn't too confusing!!
I can only guess what you particulary want to run.
But in general I can recommend you the following solution.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub btn1_Click()
  3.     'btn1 click specific code
  4.     CommonCode
  5.     'btn1 click specific code
  6. End Sub
  7.  
  8. Private Sub btn2_Click()
  9.     '....................
  10.     CommonCode
  11. End Sub
  12.  
  13. Private Sub CommonCode()
  14.     '......................
  15. End Sub
  16.  
  17.  
Good luck.
Jun 11 '07 #2
NeoPa
32,556 Expert Mod 16PB
I would have said what Fish said. It's the way you should be thinking of doing this.
Jun 12 '07 #3
ncsthbell
167 100+
I was hoping I could use something like 'IF button1_click true'. I inherited this application which is not exactly structured and I am basically having to make things work. To pull the code out and create separate peices to run is not so easy the way it was written.
Jun 13 '07 #4
NeoPa
32,556 Expert Mod 16PB
It's more OO (Object Oriented) than structured.
An event is fired that causes code to run (the event procedure). This is actually quite straightforward to code if you think it the right way.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.   'Do any Command1 only code here ...
  3.   Call Common()
  4.   '... or here
  5. End Sub
  6.  
  7. Private Sub Command2_Click()
  8.   'Do any Command2 only code here ...
  9.   Call Common()
  10.   '... or here
  11. End Sub
  12.  
  13. Private Sub Common()
  14.   'Code to do the common stuff
  15. End Sub
Jun 13 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jared | last post by:
Radio Button or Check Box and Event Procedures I need to insert either radio buttons or check boxes onto my form. I'm not sure which to use, or if there are other options. I am using the buttons...
7
by: Shaldaman | last post by:
Hi Is there a property in MS Access for the following: 1) For a Command Button on a form, is there a property that can be used to determine if it has been clicked? eg: Me!button7.Clicked - I...
2
by: Krista Lemieux | last post by:
Hello, In my form I have a button, and the button_Click function (which gets called when the button is clicked). However the functionality that I have in the button_Click function, needs to be...
4
by: Shawn | last post by:
Hi. I have a ToolBar with a couple of ToolBarButtons. On postback after clicking on of the buttons Page_Load is called first then the ToolBarButton's click event is called. Is there anyway for...
3
by: Andrew | last post by:
I am new to VBA Please can someone help get me started. I need to know how to use an if statement to check if a button has been pressed i.e. if button 1 is pressed a file will be imported from...
11
by: antonyliu2002 | last post by:
I know that this has been asked and answered thousands of times. As a matter of fact, I know that I need to say If Not Page.IsPostBack Then 'Do something End If for things that needs to be...
1
by: JHawk24821 | last post by:
I am building a simple card matching game where the user picks two buttons on a form out of a group of buttons in an attempt to find a match. I have already taken care of the randomization needed...
3
by: shapper | last post by:
Hello, I need to loop though each row in a GridView and if the checkbox is a Template Field is checked I want to display the value of an invisible column named "LevelName". I tried everything...
5
by: sumeetmakkar | last post by:
Hi all, I am a begineer and working on a project. Facing trouble linking a submit buuton to a page of my choice.Script i am using is: <SCRIPT language=JavaScript><!-- function validate(form) {...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.