Form Closing

J

Jeff

Hi,

I have a TextBox that has an Input Mask.

So when the focus leaves the TextBox, if the format of the
data is invalid a msgbox will display saying that the
format is invalid. Which is ok.

However when you Close out of the Form (Click on the X to
close), if the data is still invalid in that TextBox the
Invalid Msgbox will still appear. I don't want that to
happen.

Here are some of things I tried, none of which do what I
want done...

I know you can trap the Error in
Private Sub Form_Error(DataErr As Integer, Response As
Integer)

But if I trap it, it will also "trap" when user leaves the
focus of the TextBox. Again I want the msgbox to appear
when user exits TextBox but NOT when user exits the Form,
to just ignore that the data is invalid & close.


I also tried on the Exit Event, Lost Focus Event, & the
AfterUpdate Event of the TextBox but again the same thing
happens. Those Events are triggered when user Click on
the X to close out the Form. So if I put logic there to
say the data is invalid, it will then also pop up when
user closes out of the form, which I dont want to happen.


In EXCEL VBA there is an QueryClose Event of the Form,
where it would work there, it doesnt trigger the Exit,
LostFocus, or After Update Events of controls. However
this Event doesn't exist in Access (I already posted a
question on this).
So is their something similar ?

Or any way I can get a Form to close with ignoring the
controls ?

Any help would be greatly appreciated.

Thank you very much,
Jeff
 
R

Ronald W. Roberts

Jeff said:
Hi,

I have a TextBox that has an Input Mask.

So when the focus leaves the TextBox, if the format of the
data is invalid a msgbox will display saying that the
format is invalid. Which is ok.

However when you Close out of the Form (Click on the X to
close), if the data is still invalid in that TextBox the
Invalid Msgbox will still appear. I don't want that to
happen.

Here are some of things I tried, none of which do what I
want done...

I know you can trap the Error in
Private Sub Form_Error(DataErr As Integer, Response As
Integer)

But if I trap it, it will also "trap" when user leaves the
focus of the TextBox. Again I want the msgbox to appear
when user exits TextBox but NOT when user exits the Form,
to just ignore that the data is invalid & close.


I also tried on the Exit Event, Lost Focus Event, & the
AfterUpdate Event of the TextBox but again the same thing
happens. Those Events are triggered when user Click on
the X to close out the Form. So if I put logic there to
say the data is invalid, it will then also pop up when
user closes out of the form, which I dont want to happen.


In EXCEL VBA there is an QueryClose Event of the Form,
where it would work there, it doesnt trigger the Exit,
LostFocus, or After Update Events of controls. However
this Event doesn't exist in Access (I already posted a
question on this).
So is their something similar ?

Or any way I can get a Form to close with ignoring the
controls ?

Any help would be greatly appreciated.

Thank you very much,
Jeff
Hit the esc key then close the form.

Ron
 
K

Kelvin

The validation error occurs before the form is closes. There is no way to
trap the validation error when the form closes. Your best bet would be to
make your own exit button and perform the trap for the close there. You can
trap the focus through the LostFocus event.

Kelvin
 

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