Hi All,
As mentioned in title, I want not to save the main form if I do not enter the data in the subform?
I tried many methods and search without luck
I hope if some one can help me here;
Thanks.
Hi All,
As mentioned in title, I want not to save the main form if I do not enter the data in the subform?
I tried many methods and search without luck
I hope if some one can help me here;
Thanks.
I think you would need to run some code in the main forms Close or Unload event to check for the existence of data in the subform and then delete the main form record if none is found.
If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
Bob Fitzpatrick
Then how could you ever enter data in the Subform? The Main Form Record would always be deleted, because a Main Form Record has to exist before entering a Subform Record.
Linq ;0)>
The problem with making anything foolproof...is that fools are so darn ingenious!
All posts/responses based on Access 2003/2007
only way I can think would work would be to use unbound main and subforms then use vba transaction coding (begintrans/committrans) to ensure mainform data is inserted, get the record identify, add it to the subform family key and append those records
I believe the technical term for that is a mare's nest!
The question this begs...actually two questions is...
Why would you enter a Main Form Record if you didn't have data at hand for a Subform Record?
And if you simply had to enter the Main Form Record...and discover you don't have data at hand for a Subform Record...why not simply delete the Main Form Record?
Linq ;0)>
The problem with making anything foolproof...is that fools are so darn ingenious!
All posts/responses based on Access 2003/2007
Thanks for the reply,I believe the technical term for that is a mare's nest!
The question this begs...actually two questions is...
Why would you enter a Main Form Record if you didn't have data at hand for a Subform Record?
And if you simply had to enter the Main Form Record...and discover you don't have data at hand for a Subform Record...why not simply delete the Main Form Record?
Linq ;0)>
The database are shared on network, where data entry colleagues enter by mistake the form and forget about subform. finally I have some many records nonsense. That is why I'm looking for a solution?
Bob was, unusually for him, mistaken...you can't do that! Think about it...You have to have a Record, in the Main Form, before you enter a Record in the Subform. When you finish entering a new Record, in the Main Form, there will never be a Record in the Subform...there can't be.
Linq ;0)>
The problem with making anything foolproof...is that fools are so darn ingenious!
All posts/responses based on Access 2003/2007
I know that there would never be a record in the sub form without a record in the main form. However, it is possible to create a record in the main form without creating one in the sub form which, as I understood it, is what the OP is trying to eliminate. My suggestion was for code in the main forms Close or Unload event to check for this eventuality and then delete the main form record if no sub form record exists. As I understand the order of events, neither of these events will fire until the user tries to close the main form. I was not suggesting that the code should be run when a user moves the focus from the main form to the sub form, if that is what you thought I meant. Obviously, that would never work as needed.Bob was, unusually for him, mistaken...you can't do that! Think about it...You have to have a Record, in the Main Form, before you enter a Record in the Subform. When you finish entering a new Record, in the Main Form, there will never be a Record in the Subform...there can't be.
Linq ;0)>
If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
Bob Fitzpatrick
Sorry, Bob! I misunderstood!
Linq ;0)>
The problem with making anything foolproof...is that fools are so darn ingenious!
All posts/responses based on Access 2003/2007
For the benefit of the OP I have attached a simple example of what I meant.
Feel free to ask any questions you may have.
If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
Bob Fitzpatrick
Following Bob's suggestion, here's another way that works:
Code:Private Sub Form_Unload(Cancel As Integer) If DCount("*", "SubTableName", "MainID = " & Me.MainID) < 1 Then DoCmd.SetWarnings False DoCmd.RunCommand acCmdSelectRecord DoCmd.RunCommand acCmdDelete DoCmd.SetWarnings True End If End Sub
The problem with making anything foolproof...is that fools are so darn ingenious!
All posts/responses based on Access 2003/2007