| | |
How to determine when command button is clicked
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2009
Posts: 3
Reputation:
Solved Threads: 0
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!
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!
Try to add a module then put a global variable
Example:
On form1.
On form2
so with that simple concept Form2 can determine what button was pressed in Form1.
Example:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Module1 Public AddUpdate As String End Module
On form1.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Button1_Click() 'Assuming this button is an Add button AddUpdate ="Add" End Sub Private Sub Button2_Click() 'Assuming this button is an Update button AddUpdate ="Update" End Sub
On form2
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Form_Load() Label1.Caption = AddUpdate 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"
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 SelectWhy do you need to know what button is pressed?
A conclusion is the place where you got tired of thinking. http://www.martin2k.co.uk/forums/index.php?showforum=4
http://www.a1vbcode.com/a1vbcode/vbforums/Forum3-1.aspx
http://www.developerfusion.co.uk/for...orum&ForumID=4
•
•
Join Date: May 2009
Posts: 3
Reputation:
Solved Threads: 0
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.
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.
so does this thread solved?
A conclusion is the place where you got tired of thinking. http://www.martin2k.co.uk/forums/index.php?showforum=4
http://www.a1vbcode.com/a1vbcode/vbforums/Forum3-1.aspx
http://www.developerfusion.co.uk/for...orum&ForumID=4
![]() |
Similar Threads
- command button (Visual Basic 4 / 5 / 6)
- display image when button clicked (Java)
- Command Button Validation (Visual Basic 4 / 5 / 6)
- Problem with VAT+COding for Command button (Visual Basic 4 / 5 / 6)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Macro: please help!!!
- Next Thread: Vbcombobox problem...........
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





