![]() |
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? |
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? |
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? |
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? |
All times are GMT +1. The time now is 10:43 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com