Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Command Button question
Is there a way to establish whether a command button has been pressed
I wish to execute some code on exiting one control only if a particular command button had been pressed Example Private Sub cbRestaurant_Exit(ByVal Cancel As MSForms.ReturnBoolean) If command Button pressed Then Do This Exit Sub End If more code here End Sub Regards & TIA |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Command Button question
You could write a 1 or 0 value out to a cell in an unused worksheet and then
check that value to verify if the command button has been pressed before executing your code.. -- Kevin Backmann "Jim @Eclipse.co.uk" wrote: Is there a way to establish whether a command button has been pressed I wish to execute some code on exiting one control only if a particular command button had been pressed Example Private Sub cbRestaurant_Exit(ByVal Cancel As MSForms.ReturnBoolean) If command Button pressed Then Do This Exit Sub End If more code here End Sub Regards & TIA |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Command Button question
Thanks for the suggestion Kevin I will try it tomorrow,
I don't think I explained my requirements very well. What I am trying to achieve is probably not possible In essence I am trying to prevent the On Exit code from running when the Exit is caused by pressing a particular command button but allowing it to run in all other instances thanks again "Kevin B" wrote in message ... You could write a 1 or 0 value out to a cell in an unused worksheet and then check that value to verify if the command button has been pressed before executing your code.. -- Kevin Backmann "Jim @Eclipse.co.uk" wrote: Is there a way to establish whether a command button has been pressed I wish to execute some code on exiting one control only if a particular command button had been pressed Example Private Sub cbRestaurant_Exit(ByVal Cancel As MSForms.ReturnBoolean) If command Button pressed Then Do This Exit Sub End If more code here End Sub Regards & TIA |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Command Button question
Is there a way to establish whether a command button has been pressed
Use a variable with UserForm-wide scope to track the buttons pushed. I wish to execute some code on exiting one control only if a particular command button had been pressed I'm thinking code something like that below my signature (it assumes 3 CommandButton Click events and a TextBox's Exit event). Every time a CommandButton is pressed, that button's Name is stored in the LastPressedButton variable. All you do in the Exit event is check if that button was the last one pressed. Rick Dim LastPressedButton As String Private Sub CommandButton1_Click() LastPressedButton = "CommandButton1" ' Put rest of your code here End Sub Private Sub CommandButton2_Click() LastPressedButton = "CommandButton2" ' Put rest of your code here End Sub Private Sub CommandButton3_Click() LastPressedButton = "CommandButton3" ' Put rest of your code here End Sub Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean) If LastPressedButton = "CommandButton2" Then Cancel = True ' Any other code you might want to execute End If ' Your normal Exit code goes here End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Command Button Question | Excel Programming | |||
Command Button question | Excel Programming | |||
Command Button question | Excel Programming | |||
Command Button Question | Excel Programming |