NetTalk Central

Author Topic: Auto Create Child Record  (Read 4415 times)

Jim A

  • Full Member
  • ***
  • Posts: 203
    • View Profile
    • Email
Auto Create Child Record
« on: April 08, 2013, 04:44:37 PM »
I have a parent Inventory Record that can have a child record in one of the following Child Files: Truck, Stock, Trailer, etc.  The Inventory record has an Inv:InvClass that determines which of the files to use.  I have no problem doing Updates.  I simply do an update of the proper child file, based on the Inv:InvClass.

I am having major trouble trying to do Inserts.  I finally broke the process apart so that I call an Insert form from the Menu (its only purpose is to Insert the parent record).  It inserts the Inventory record as it should.  I was hoping to be able to Create the corresponding child record, based on the Inv:InvClass.  I have not been able to do this.

The files are related by
Truck:InvMachineID = Inv:InvMachineId AND
Truck:Inv:InvId         = Inv:InvId

I prime the Child File accordingly and try Access:Truck.Insert -- but no joy.

This should work, correct?  What embed should I use?  Sorry for all the questions.

Thank you.



Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Auto Create Child Record
« Reply #1 on: April 08, 2013, 08:17:32 PM »
my first guess is that you're doing it in the wrong place.
ie you're assuming that
Inv:InvMachineId and Inv:InvId are set to something in the place where you run your code.
So tell us more about these fields - are they autnumbered fields? Are they set by the user? Do you set them in code?

cheers
Bruce



Jim A

  • Full Member
  • ***
  • Posts: 203
    • View Profile
    • Email
Re: Auto Create Child Record
« Reply #2 on: April 09, 2013, 02:50:56 AM »
Hi Bruce; Both are Longs.  Inv:InvMachineID is set by code and is the top member of the duplex Key.  Inv:InvID is auto-number.at the bottom of the key.

These are being set just fine.  It's just creating the child that is the problem.

Thanks.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Auto Create Child Record
« Reply #3 on: April 09, 2013, 05:42:32 AM »
Hi Jim,

if you add some debugging to your code I think you'll find yur code is running _before_ the auto-number component is applied.
by default NetTalk only creates the record (and hence sets the autonumber) when the form is "saved" - not when the form is "opened". If you need to add child records before the form is saved then there's an option on the Advanced tab - something like "auto number when form opens even if not necessary". If you tick that on the the record is created when the form _opens_ (but be aware that the user may never Save, nor Cancel the form, so you can end up with "half hearted" records.)

cheers
Bruce

Jim A

  • Full Member
  • ***
  • Posts: 203
    • View Profile
    • Email
Re: Auto Create Child Record
« Reply #4 on: April 09, 2013, 06:25:25 AM »
Hi Bruce:  Moving the code into a later embed point worked.  I appreciate the help.

Thank you!

Jim A

  • Full Member
  • ***
  • Posts: 203
    • View Profile
    • Email
Re: Auto Create Child Record
« Reply #5 on: April 10, 2013, 04:34:49 PM »
HI Bruce: Just to make sure I'm doing this at the right time, could you please suggest the last embed point where the user has committed to the parent record so I can add the child at that point?

Thanks.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Auto Create Child Record
« Reply #6 on: April 10, 2013, 09:37:16 PM »
depending on the form action, one of

PostInsert
PostCopy
Postchange
PostDelete

routines.

(in your case PostInsert I would think.)

cheers
Bruce

Jim A

  • Full Member
  • ***
  • Posts: 203
    • View Profile
    • Email
Re: Auto Create Child Record
« Reply #7 on: April 11, 2013, 12:08:17 PM »
Great!  Thank you!