Requery creates new record

G

Guest

i have an Access2003 database with a main form that has several sub forms.
Part of my code writes data to the main form when it is about to close.

Below is my section of code that is causing me problems. When i requery my
form it somehow creates a new record. So all the data on my form is lost and
a blank record appears. i need to requery my form to prevent the save dialog
box from appearing.

Forms![frmWorkOrders]![frmWorkOrdersQuote].Form![QuotePrintedDate].Value =
Date ' Creates Date In Date Printed Field When Quote Was Printed.
MsgBox "4"
Forms!frmWorkOrders.Requery
MsgBox "5"
Forms!frmWorkOrders.Combo73.Value = "Quote Sent" ' Once Quote Is
Printed,Status Is Changed To Quote Sent.
Forms!frmWorkOrders.StatusDate.Value = Now ' Change Status Date.
DoCmd.Close acForm, "frmWorkOrders", acSaveYes ' Close WO Form.


Any ideas why it is creating a new record on requery?
 
M

Marshall Barton

StuJol said:
i have an Access2003 database with a main form that has several sub forms.
Part of my code writes data to the main form when it is about to close.

Below is my section of code that is causing me problems. When i requery my
form it somehow creates a new record. So all the data on my form is lost and
a blank record appears. i need to requery my form to prevent the save dialog
box from appearing.

Forms![frmWorkOrders]![frmWorkOrdersQuote].Form![QuotePrintedDate].Value =
Date ' Creates Date In Date Printed Field When Quote Was Printed.
MsgBox "4"
Forms!frmWorkOrders.Requery
MsgBox "5"
Forms!frmWorkOrders.Combo73.Value = "Quote Sent" ' Once Quote Is
Printed,Status Is Changed To Quote Sent.
Forms!frmWorkOrders.StatusDate.Value = Now ' Change Status Date.
DoCmd.Close acForm, "frmWorkOrders", acSaveYes ' Close WO Form.

Any ideas why it is creating a new record on requery?


Because you are setting values?? Requery will save the
record if any bound field has been changed. I think you
should get rid of the requery and find a more appropriate
way to deal with whatever issue prompted you to use it.

Note that your close statement is saving the form's design,
generally a BAD THING. You should go out of your way to
prevent that by using:
DoCmd.Close acForm, Me.Name, acSaveNo
or, if this form is closing another form:
DoCmd.Close acForm, "other form", acSaveNo

If you want save the modified record, use:
Me.Dirty = False
or the DoCmd equivalent/
 

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