Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,316
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Button Question Bob Phillips Excel Programming 0 January 2nd 07 10:50 PM
Command Button question Patrick Simonds Excel Programming 9 November 6th 06 07:20 PM
Command Button question Giselle[_2_] Excel Programming 7 January 28th 06 03:20 AM
Command Button Question Todd D. Levy Excel Programming 4 July 7th 04 03:18 PM


All times are GMT +1. The time now is 04:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"