Re: Still not able to UNDO a new record entered
From: Dirk Goldgar (dg_at_NOdataSPAMgnostics.com)
Date: 11/02/04
- Next message: Marshall Barton: "Re: combo box if statement"
- Previous message: Dirk Goldgar: "Re: OrderBy property"
- In reply to: midnite oil: "Still not able to UNDO a new record entered"
- Next in thread: midnite oil: "Re: Still not able to UNDO a new record entered"
- Reply: midnite oil: "Re: Still not able to UNDO a new record entered"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 1 Nov 2004 22:37:53 -0500
"midnite oil" <midnite@msn.com> wrote in message
news:%23JtBXlHwEHA.3872@TK2MSFTNGP11.phx.gbl
> Hi,
>
> Thought I had the solution earlier this afternoon :( using
> DoCmd.RunCommand acCmdUndo.
>
> Main form has 2 required fields. Subform has 1 required field. All
> fields are bound to tables. I have a form_Unload function to trap if
> user click [X] to exit form, if yes, message is displayed to inform
> user to click the Return Main Menu button to exit instead. If its a
> new record, ValidateAllRequired function will validate all required
> fields entered, if not, give the user the option to abort or or
> continue with the entry.
>
> Test Case 1 : On the Main form I entered both required fields, click
> [X] to close form. My form_Unload event gets executed and inform me
> to click Return Main Menu to exit which I did and I get the message
> that Subform required field is missing - do I want to continue or
> exit - I choose the exit option. DoCmd.RunCommand acCmdUndo gets
> executed and removed the record that has been created in the Main
> form and all is good.
>
> Test Case 2 : On the Main form I entered both required fields as
> well as required field in subform. Remove the required field entry
> in the subform. Click [X], message informs me to click Return Main
> Menu to exit, click Continue data entry. Enter the required field in
> subform. Remove one of the required fields in Main form. Click
> Return Main Menu button, receives message that Main form required
> field is not entered, abort or continue the data entry. I selected
> ABORT - DoCmd.RunCommand acCmdUndo gets executed but it did not Undo
> the main form record.
>
> I am lost now. I have to control the form such that the parent must
> only exist with a child record. Can someone please, please help me
> with this !
It sounds as though your data design is rather unusual, and may be worth
reexamining. I think the problem you are running into comes from the
fact that it is not possible to enter data on a subform without Access
saving the main form's record. That's because Access assumes that the
subform will be used to add a "child" record that is related to the
"parent" record on the main form, and therefore the parent record must
be saved so as to maintain referential integrity. Access saves the
main-form record as soon as the focus is moved to the subform, and there
is no way you can stop it. So once you've entered a record on the
subform, you can't Undo the main form, because its record has already
been saved. You could delete the record, if knew it didn't previously
exist, or you could restore its values from a backup table if it did,
but you can't just "undo" it.
And then there's your requirement that each main-form record *must* have
a child record. There's no way to enforce this through referential
integrity, because a parent record must be saved before a child record
can be created. The best you can do is put some rather elaborate code
into the form, in several different events, to try to keep the user on
the current main record until a subform record has been added to it. I
wrote such code once, as a test, so it can be made to work, though I
wouldn't care to vouch for its reliability.
But why is it that the parent must not exist without a child? Normally,
relationships that are described as "one-to-many" or "one-to-one", such
as would be represented by a main form and subform, are really more
accurately described as "one-to-zero-or-many", or "one-to-zero-or-one".
One table's record is primary and must exist, while the other table's
record is secondary and may or may not exist. If the child record
*must* exist, would its fields be better placed in the parent record
instead?
-- Dirk Goldgar, MS Access MVP www.datagnostics.com (please reply to the newsgroup)
- Next message: Marshall Barton: "Re: combo box if statement"
- Previous message: Dirk Goldgar: "Re: OrderBy property"
- In reply to: midnite oil: "Still not able to UNDO a new record entered"
- Next in thread: midnite oil: "Re: Still not able to UNDO a new record entered"
- Reply: midnite oil: "Re: Still not able to UNDO a new record entered"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|