ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Bypass Textbox Validation (https://www.excelbanter.com/excel-programming/303672-bypass-textbox-validation.html)

Myrna Rodriguez

Bypass Textbox Validation
 
Hi VB Bugs...

I created a userform with textboxes to facilitate data entry on Excel
spreadsheet. I validated the textboxes to display a message box if
empty.
Userform automatically appears when file is open.
However, if I decide not to input data on userform & wish to
CANCEL(unload userform), a message box still appears.
How can I bypass validation for textboxes and proceed to CANCEL form??

Thanks and will validate your sugguestions!!
Myrna

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Jim Rech

Bypass Textbox Validation
 
I assume you're running your validation routines from Sub
UserForm_QueryClose. If so, check the value of the CloseMode argument that
is passed to it. If it's 0 then the "x" was used to close the form. If
Unload caused it to close the value is 1.

--
Jim Rech
Excel MVP
"Myrna Rodriguez" wrote in message
...
| Hi VB Bugs...
|
| I created a userform with textboxes to facilitate data entry on Excel
| spreadsheet. I validated the textboxes to display a message box if
| empty.
| Userform automatically appears when file is open.
| However, if I decide not to input data on userform & wish to
| CANCEL(unload userform), a message box still appears.
| How can I bypass validation for textboxes and proceed to CANCEL form??
|
| Thanks and will validate your sugguestions!!
| Myrna
|
| *** Sent via Devdex http://www.devdex.com ***
| Don't just participate in USENET...get rewarded for it!



Myrna Rodriguez

Bypass Textbox Validation
 

Hi...

This is the code I am currently using to validate textbox.

Private Sub txtfast_Exit(ByVal Cancel As MSForms.ReturnBoolean)
'display msgbox if textbox fast is empty
If txtfast.Text = "" Then
MsgBox "Enter FAST File"
Cancel = True
End If
End Sub

**The message box appears successfully when empty, but when I close
userform by click on "X" the message box pops up. I would like to Cancel
userform even if textbox is empty.

Thanks,
Myrna





*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Charles

Bypass Textbox Validation
 
Myrna Rodriguez,

Try using a close command button on your userform.


Private Sub CommandButton1_Click()
Unload UserForm1
End Sub

HTH

Charle

--
Message posted from http://www.ExcelForum.com


Jim Rech

Bypass Textbox Validation
 
This is the code I am currently using to validate textbox

You might defer all your validating until the user tries to close the form.

Or you could consider this approach:

Dim ExitMode As Boolean

Private Sub UserForm_Activate()
ExitMode = False
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
ExitMode = True
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If ExitMode = False Then
If TextBox1.Text = "" Then MsgBox "Warning"
End If
End Sub

--
Jim Rech
Excel MVP
"Myrna Rodriguez" wrote in message
...

Hi...

This is the code I am currently using to validate textbox.

Private Sub txtfast_Exit(ByVal Cancel As MSForms.ReturnBoolean)
'display msgbox if textbox fast is empty
If txtfast.Text = "" Then
MsgBox "Enter FAST File"
Cancel = True
End If
End Sub

**The message box appears successfully when empty, but when I close
userform by click on "X" the message box pops up. I would like to Cancel
userform even if textbox is empty.

Thanks,
Myrna





*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!





All times are GMT +1. The time now is 05:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com