How to determine when command button is clicked

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2009
Posts: 3
Reputation: success_always is an unknown quantity at this point 
Solved Threads: 0
success_always success_always is offline Offline
Newbie Poster

How to determine when command button is clicked

 
0
  #1
May 19th, 2009
Hi guys,

One form1 I have 2 command buttons - Add new record and other to view/edit existing record (the user can enter record id and click view/edit existing record button).

If the user clicks Add new record, the user is taken to the next screen where the record id is auto-generated & new record is created. Whereas if Edit/View existing record is clicked, existing information for that record will be displayed on the next screen.

How do I determine which command button has been pressed on form1 so that on form2 Add or Update code can be called based on the button clicked.

Any input is greatly appreciated, thanks!
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 66
Reputation: c0deFr3aK is an unknown quantity at this point 
Solved Threads: 10
c0deFr3aK's Avatar
c0deFr3aK c0deFr3aK is offline Offline
Junior Poster in Training

Re: How to determine when command button is clicked

 
0
  #2
May 19th, 2009
Try to add a module then put a global variable
Example:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Module1
  2. Public AddUpdate As String
  3. End Module

On form1.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Button1_Click()
  2. 'Assuming this button is an Add button
  3. AddUpdate ="Add"
  4. End Sub
  5.  
  6. Private Sub Button2_Click()
  7. 'Assuming this button is an Update button
  8. AddUpdate ="Update"
  9. End Sub

On form2
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Form_Load()
  2. Label1.Caption = AddUpdate
  3. End Sub

so with that simple concept Form2 can determine what button was pressed in Form1.
Last edited by c0deFr3aK; May 19th, 2009 at 1:49 am.
"Remember your creator before you die"
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 300
Reputation: jireh is an unknown quantity at this point 
Solved Threads: 42
jireh's Avatar
jireh jireh is offline Offline
Posting Whiz

Re: How to determine when command button is clicked

 
0
  #3
May 20th, 2009
Module Code:
Public ButtonPressed As String

Button1 Code:
ButtonPressed = "Button1"

Button2 Code:
ButtonPressed = "Button2"

to get what button is pressed...
Select Case ButtonPressed
Case "Button1"
       ...your statement here
Case "Button2"
       ...your statement here
Case Else
       ...your statement here
End Select

Why do you need to know what button is pressed?
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 3
Reputation: success_always is an unknown quantity at this point 
Solved Threads: 0
success_always success_always is offline Offline
Newbie Poster

Re: How to determine when command button is clicked

 
0
  #4
May 22nd, 2009
Thanks guys for your help! I was digressed to another project & just got back to this. The solution worked.

I had to know which button is pressed because if the user clicked "Add", behind the scenes I'm auto generating new record id in a particular format. If the user clicked "update/view record", then I just need to display existing record info.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 300
Reputation: jireh is an unknown quantity at this point 
Solved Threads: 42
jireh's Avatar
jireh jireh is offline Offline
Posting Whiz

Re: How to determine when command button is clicked

 
0
  #5
May 25th, 2009
so does this thread solved?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC