Cancel button to bypass MsgBox

  • Thread starter Myrna Rodriguez
  • Start date
M

Myrna Rodriguez

hi VB addicts!!
hope all bugs are conquered...

i created a userform in Excel.
I validated a textbox when empty to trigger MsgBox.
However, when I wish to cancel userform...MsgBox displays
not allowing to cancel.
What can I do bypass MsgBox when cancelling userform entirely??

My code:
'textbox FAST
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

'Cancel Button
Private Sub cmdcancel_Click()
'cancel userform1
Unload UserForm1
End Sub


thanks in advance & have a happy day!!
myrna
 
J

Juan Pablo González

Mhm... why don't you validate the txtfast in the "OK" button instead ?
 
B

Bob Phillips

Myrna,

Use a module scope variable, and set it to a value in the cancel procedure,
then test that in the exit routine. Something like

Dim fCancel As Boolean

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

'Cancel Button
Private Sub cmdcancel_Click()
'cancel userform1
fCancel = True
Unload UserForm1
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
M

Myrna Rodriguez

I validated textboxes in command button OK.
When I Cancel, Msgbox appears and not letting me trigger
Cancel event. I used the code, but no luck...thanks Mr. Bob
Any other suggestion??
thanks...myrna
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top