PC Review


Reply
Thread Tools Rate Thread

Command Button question

 
 
Jim
Guest
Posts: n/a
 
      14th Oct 2007
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?S2V2aW4gQg==?=
Guest
Posts: n/a
 
      14th Oct 2007
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
>
>
>

 
Reply With Quote
 
Jim
Guest
Posts: n/a
 
      14th Oct 2007
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" <(E-Mail Removed)> wrote in message
news:B03055C7-6DF3-4454-A80F-(E-Mail Removed)...
> 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
>>
>>
>>



 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      15th Oct 2007
> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Command Button Question Jeanette Cunningham Microsoft Access Getting Started 0 12th May 2009 05:11 AM
Command Button Question/Help =?Utf-8?B?VGhhdCBDcmF6eSBIb2NrZXkgRG9vZA==?= Microsoft Access Form Coding 4 27th Aug 2007 09:36 PM
Command Button question Patrick Simonds Microsoft Excel Programming 9 6th Nov 2006 07:20 PM
Command Button Question Bob Microsoft Access 1 22nd Apr 2006 06:04 AM
command button question Gary Keramidas Microsoft Excel Programming 4 18th Jun 2005 08:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:48 PM.