Exit form without adding a record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form "Info" which has a default field filled in "=date()" when I
click the exit button it adds another record but everything is blank except
the autonumber and the date field. this also happens when I hit the clear
fields button.

Here is the code for the exit button...
DoCmd.Close acForm, "Info"

and for the clear fields button...
cboDate = Date
txtName = Null
txtZipCode = Null
cboBranch = Null
txtPhone = Null
txtEmail = Null
cboContactMethod = Null
cboBest = Null

I am trying to make it so it does not add a new record when these buttons
are hit. Thanks for your suggestions in advance!
 
JR said:
I have a form "Info" which has a default field filled in "=date()"
when I click the exit button it adds another record but everything is
blank except the autonumber and the date field. this also happens
when I hit the clear fields button.

Here is the code for the exit button...
DoCmd.Close acForm, "Info"

and for the clear fields button...
cboDate = Date
txtName = Null
txtZipCode = Null
cboBranch = Null
txtPhone = Null
txtEmail = Null
cboContactMethod = Null
cboBest = Null

I am trying to make it so it does not add a new record when these
buttons are hit. Thanks for your suggestions in advance!

A default value on a field will NOT cause a record to be created. However
code that sets the value of any control (even to a null) WILL cause a record
to be started and that record will try to save when you leave the record or
close the form.

Your "Clear" button should just issue an Undo on the form rather that
setting values on all the controls. If you see this happen even when you
don't use the clear button then you have code some place else that is
setting a value.
 
Rick Brandt said:
A default value on a field will NOT cause a record to be created. However
code that sets the value of any control (even to a null) WILL cause a record
to be started and that record will try to save when you leave the record or
close the form.

Your "Clear" button should just issue an Undo on the form rather that
setting values on all the controls. If you see this happen even when you
don't use the clear button then you have code some place else that is
setting a value.

so what about the exit button that adds a record?
 
JR said:
so what about the exit button that adds a record?

Exiting the form *in any fashion* will save the current record if it has
been dirtied.

If you are saying that all a user has to do is navigate to the new record
position, press your Exit button, and this is writing a record to the table
then you must have some code or a macro that is dirtying the record. You
need to eliminate that.
 
On Fri, 4 May 2007 10:58:02 -0700, JR Brown <JR
I am trying to make it so it does not add a new record when these buttons
are hit. Thanks for your suggestions in advance!

Add a line

Me.Undo


John W. Vinson [MVP]
 
Back
Top