Clearing all controls on a form

  • Thread starter Thread starter T.
  • Start date Start date
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.
 
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).
 
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.
 
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.
 
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.
 
Back
Top