Clearing a form before closing it

J

JMorrell

I have a form that upon a user's input, is populated with various bits of
data. If the user decides to not continue, there is also a button to clear
all the data before closing the form. This button worked well before
migrating the data to an SQL Server, which won't allow null values on one of
the fields that gets cleared. When I bypass the error, I'm able to get past
it, but is inconvenient for the general user (not to mention bad programming).

Is there a way to clear the entire form, or do I have to set values of "" to
each field before I close the form?

tia,
 
L

Larry Linson

Why do you find it necessary to do this? Have you modified the contents of
some Control on the Form so that closing it would write a new record, or
overwrite an old one?

If the form is bound, and you want to Cancel any updates and not write the
record, pressing the Esc key twice will do it, or from VBA code you could
use

SendKeys ("ESC","ESC")

Larry Linson
Microsoft Access MVP
 
6

'69 Camaro

It would probably be best if you could train your users to use the <ESC>
key, but if you want to put some code behind a button to prevent the
addition of a new record or changes to an existing record, then I would
recommend using the "Undo" method of the form. The syntax is:

Me.Undo

The SendKeys command isn't always reliable, since the window focus can
change at unexpected times, causing the simulated keystrokes may be
delivered to the wrong program. However, if you'd like to see the syntax,
here it is:

SendKeys "{ESC}{ESC}", False

HTH.

Gunny

P.S. I'll reply to your other thread about the non-updateable query problem
later this P.M.

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.
 
J

JMorrell

that's exactly what I need. Thanks.

'69 Camaro said:
It would probably be best if you could train your users to use the <ESC>
key, but if you want to put some code behind a button to prevent the
addition of a new record or changes to an existing record, then I would
recommend using the "Undo" method of the form. The syntax is:

Me.Undo

The SendKeys command isn't always reliable, since the window focus can
change at unexpected times, causing the simulated keystrokes may be
delivered to the wrong program. However, if you'd like to see the syntax,
here it is:

SendKeys "{ESC}{ESC}", False

HTH.

Gunny

P.S. I'll reply to your other thread about the non-updateable query problem
later this P.M.

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.
 
Top