Stop a Form from Closing

A

Aaron

Hi!

I would like to find a way to prevent a form from closing
if the user leaves a textbox blank. Is there anyway to
get the Form_Close() procedure from not completing if
certain criteria are met???

Thanks in Advance!
Aaron
 
M

Marshall Barton

Aaron said:
I would like to find a way to prevent a form from closing
if the user leaves a textbox blank. Is there anyway to
get the Form_Close() procedure from not completing if
certain criteria are met???


The Unload event has a Cancel argument
 
J

Jim Allensworth

Hi!

I would like to find a way to prevent a form from closing
if the user leaves a textbox blank. Is there anyway to
get the Form_Close() procedure from not completing if
certain criteria are met???

Thanks in Advance!
Aaron

Try the form's Unload event. It, unlike the Close even, can be
cancelled.

Also, you might think about using the form's before update event -
since we are talking about data validation.

- Jim
 
H

Hedi

Yes in the Unload Event of the form

Private Sub Form_Unload(Cancel As Integer)
If (Not len(MyTextBox)) Then
Cancel = True
End If
End Sub

Where MyTextBox is the text box to test for emptiness.

Hedi
 
G

Guest

Thanks for the quick response. The event still completed
even though the textbox was null I also tried

If isnull(password) then
Cancel = True
end if

and

If Len(password)<0 then
Cancel =True
end if

Any thoughts/ideas? Thank you very very much!
 

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