943,866 Members | Top Members by Rank

Ad:
May 19th, 2009
0

How to determine when command button is clicked

Expand Post »
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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
success_always is offline Offline
3 posts
since May 2009
May 19th, 2009
0

Re: How to determine when command button is clicked

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.
Reputation Points: 11
Solved Threads: 10
Junior Poster in Training
c0deFr3aK is offline Offline
71 posts
since Mar 2009
May 20th, 2009
0

Re: How to determine when command button is clicked

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?
Reputation Points: 11
Solved Threads: 49
Posting Whiz
jireh is offline Offline
316 posts
since Jul 2007
May 22nd, 2009
0

Re: How to determine when command button is clicked

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
success_always is offline Offline
3 posts
since May 2009
May 25th, 2009
0

Re: How to determine when command button is clicked

so does this thread solved?
Reputation Points: 11
Solved Threads: 49
Posting Whiz
jireh is offline Offline
316 posts
since Jul 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Macro: please help!!!
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Vbcombobox problem...........





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC