Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Desable "Cancel" event

Ive been trying to write a routine to prevent empty textboxes. Im using the
TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean) event. But since I
disabled the close button and using a CommandButton instead; if the user
doesnt make any entry at all, itll still trigger the error message when
closing the form. Is there a way around it. Can I cancel the cancel event
while closing the form from the CommandButton?

I cant retain the focus on the control. I also tried the BeforeUpdate event
but didnt get the expected results. Do you know of any good source of
related documentation?




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Desable "Cancel" event

Public bBlockEvents as Boolean

Private Sub Textbox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
if bBlockEvents then exit sub


End sub

Sub CmdExit_Click()
bBlockEvents = True


end Sub

so use a public variable in the userform module to indicate your intention
and exercise control.

--
Regards,
Tom Ogilvy


"LuisE" wrote:

Ive been trying to write a routine to prevent empty textboxes. Im using the
TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean) event. But since I
disabled the close button and using a CommandButton instead; if the user
doesnt make any entry at all, itll still trigger the error message when
closing the form. Is there a way around it. Can I cancel the cancel event
while closing the form from the CommandButton?

I cant retain the focus on the control. I also tried the BeforeUpdate event
but didnt get the expected results. Do you know of any good source of
related documentation?




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 182
Default Desable "Cancel" event

Hi,

Just adding without ignoring Tom's code:

Private Sub CommandButton1_Click()
If TextBox1 = "" Then TextBox1.SetFocus: Exit Sub
Unload Me
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox1 = "" Then Cancel = True
End Sub


--
Regards,

Halim



"LuisE" wrote:

Ive been trying to write a routine to prevent empty textboxes. Im using the
TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean) event. But since I
disabled the close button and using a CommandButton instead; if the user
doesnt make any entry at all, itll still trigger the error message when
closing the form. Is there a way around it. Can I cancel the cancel event
while closing the form from the CommandButton?

I cant retain the focus on the control. I also tried the BeforeUpdate event
but didnt get the expected results. Do you know of any good source of
related documentation?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Desable "Cancel" event

Once Again Thank you

"Tom Ogilvy" wrote:

Public bBlockEvents as Boolean

Private Sub Textbox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
if bBlockEvents then exit sub


End sub

Sub CmdExit_Click()
bBlockEvents = True


end Sub

so use a public variable in the userform module to indicate your intention
and exercise control.

--
Regards,
Tom Ogilvy


"LuisE" wrote:

Ive been trying to write a routine to prevent empty textboxes. Im using the
TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean) event. But since I
disabled the close button and using a CommandButton instead; if the user
doesnt make any entry at all, itll still trigger the error message when
closing the form. Is there a way around it. Can I cancel the cancel event
while closing the form from the CommandButton?

I cant retain the focus on the control. I also tried the BeforeUpdate event
but didnt get the expected results. Do you know of any good source of
related documentation?




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
MACRO: Selecting "Cancel" from a drop down to copy and paste entirerow to another sheet Nicole Hannington Excel Discussion (Misc queries) 1 July 20th 09 07:11 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
"cancel" caption doesn't show up on cancel dialog Janis Excel Programming 2 September 14th 06 11:32 PM
how to stop program with loop by click "Cancel" button miao jie Excel Programming 2 December 16th 04 02:42 PM
Close workbook with "Cancel=TRUE" in the BeforeClose()" Wellie[_3_] Excel Programming 1 October 16th 04 09:46 PM


All times are GMT +1. The time now is 07:47 AM.

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

About Us

"It's about Microsoft Excel"