View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jim Rech Jim Rech is offline
external usenet poster
 
Posts: 2,718
Default 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!