Clearing all controls on a form

T

T.

Hey all,

I need to write a script that will go through all the controls on my forms
and clear them. I have something that sets values to Null and "" but when
users try to save something or close the form they always get warnings about
not having a primary key and telling you that you can't save it, then it
asks you if you want to close it anyways, say yes and all is ok.

Is there a way so that you can go into the form put in some data, clear it
all and then close the form without getting those stupid warnings?? If you
just open the form and close it without touching anything it doesn't give
warnings at all.

TIA,

T.
 
R

Rick Brandt

T. said:
Hey all,

I need to write a script that will go through all the controls on my forms
and clear them. I have something that sets values to Null and "" but when
users try to save something or close the form they always get warnings about
not having a primary key and telling you that you can't save it, then it
asks you if you want to close it anyways, say yes and all is ok.

Is there a way so that you can go into the form put in some data, clear it
all and then close the form without getting those stupid warnings?? If you
just open the form and close it without touching anything it doesn't give
warnings at all.

If you are using a bound form then clearing all of the fields is not the
same as canceling the creation of the record. That is why you get all of
the warnings, because to Access it looks as if you are trying to save a
blank record. You should use Me.Undo if you want to cancel the creation of
a new record. If you want to remove an existing record entirely then you
need to delete it (again, not the same as clearing all of the fields).
 
T

T.

So if I have a button that users can click to "erase" the form and put
Me.Undo in the click() procedure it will "undo" any changes made on the
current record?

Thanks,

T.
 
R

Rick Brandt

T. said:
So if I have a button that users can click to "erase" the form and put
Me.Undo in the click() procedure it will "undo" any changes made on the
current record?

If it is a new record that has never been saved, yes. If it has ever been
saved then Undo will simply cancel any changes made since the last save,
but the record will not be removed entirely.
 
T

T.

Perfect!! Thank you so much.

T.


Rick Brandt said:
If it is a new record that has never been saved, yes. If it has ever been
saved then Undo will simply cancel any changes made since the last save,
but the record will not be removed entirely.
 

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