Saving a recordset on a form

N

Nelson

I am using a form to set up a record in a "master file" and a 2nd form to
enter line information in a second "detail table" There is a one to many
relationship / "link" between the two tables.
The user fills in the "master form" , and then clicks open the "detail form".
A public statement loads the master form ID / Link on the detail form, to be
used as the link between the two forms / tables.

When trying to exit the "detail form" there is an error created as the
master form is not saved yet, therefore the "link" is not established for the
one to many relationship.
If the user exits the "master form" and then reopens, the save is complete
and the process works fine.

I have tried the "DoCmd.RunCommand acCmdSave" and "DoCmd.RunCommand
acCmdSaveRecord" and receive an error on these stating they are not available.

Does anyone have an idea how to solve this?

Thank you
Nelson
 
J

Jeanette Cunningham

Hi Nelson,
Stop the user from opening the detail form if the master form record has not
been saved.
Is the master form a bound form?
If so, you can use code like this to save the record on the master form. Put
the code on the button that opens the detail form (assuming the button is on
the master form).

If Me.Dirty = True Then
Me.Dirty = False
End If

The above is the suggested method of saving a record. Setting the form's
dirty property to false forces the save.

If there is an error and the record can't be saved, prevent the user from
opening the detail form.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
J

John W. Vinson

I am using a form to set up a record in a "master file" and a 2nd form to
enter line information in a second "detail table" There is a one to many
relationship / "link" between the two tables.
The user fills in the "master form" , and then clicks open the "detail form".
A public statement loads the master form ID / Link on the detail form, to be
used as the link between the two forms / tables.

When trying to exit the "detail form" there is an error created as the
master form is not saved yet, therefore the "link" is not established for the
one to many relationship.
If the user exits the "master form" and then reopens, the save is complete
and the process works fine.

I have tried the "DoCmd.RunCommand acCmdSave" and "DoCmd.RunCommand
acCmdSaveRecord" and receive an error on these stating they are not available.

Does anyone have an idea how to solve this?

Thank you
Nelson

Any reason not to use a Form with a Subform, which handles this for you
automatically!?

You need to not only open the "detail" form with the ID in the Wherecondition
argument, but also set it as the default value of the linking field in the
child form (perhaps by passing its value in the Openargs parameter). Perhaps
you could post your code.

To save a record on the main form, you can use either

DoCmd.RunCommand acCmdSaveRecord

in the event which opens the child form, or

If Me.Dirty = True Then
Me.Dirty = False
End If

in the same place. Neither of these will work on the child form. acCmdSave
saves *design changes to the structure of the form*, not the record.
 

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