Forms OnExit

M

Marcus Lloyd

I'm using the OnExit event to trigger validation checks on the textbox, this
all works fine, but when I close the form it triggers the OnExit event.

What I would like to do is cancel the OnExit event when I close the form,
How do I achieve this?

Sample of On Exit Code:

If .Text <> "" Or .Text <> Null Then

....Execute commands

End If

regards

Marcus
 
T

TC

You should really use AfterUpdate, not OnExit, to perform field
validation. The former event only fires when the user has actually
entered or changed the value in the field. The latter event fires
whenever you leave the field, whether the user had entered or changed
it, or not.

As for the problem you've asked about, this is always tricky to handle.
It is possible, but quite complicated, to do what you have actually
asked for. But the easier solution, is to use BeforeUpdate, and tell
the users this: "If you enter a value, and the error message appears,
and you want to close the form, you'll have to press the Escape key a
few times to erase what you entered, before you can close the form."

So, try using BeforeUpdate & the Escape key, as described above.

HTH,
TC [MVP Access]
 
T

TC

PS:

.Text <> Null is ALWAYS FALSE;
.Text > Null is ALWAYS FALSE;
.Text < Null is ALWAYS FALSE;
.Text = Null is ALWAYS FALSE !

You need to read-up about Null values and how they work in expressions
:)

HTH,
TC [MVP Access]
 
T

TC

PPS (gasp!)

The .Text property of a control is a string value, not a variant, so it
can /never/ be null. There's no point testing .Text for Null, even if
you were doing that properly. This is a different problem to the fact
that expressions containing Null, are always Null.

The .Value property of a control, is a variant, and therefore can be
null. You'd test for that by using the IsNull() function. So, the
following has the TC-AOK-stamp-of-approval:

If IsNull(.Value) then ...

HTH,
TC [MVP Access]
 

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