SQL - adding child record from parent form 
Author Message
 SQL - adding child record from parent form

In a form (parent file) where the primary key is an autoincrement key on the
SQL server, I have a browse for a child file.  If the user goes to add a
child record without having first saved the parent record, the autoincrement
key remains zero and the child record isn't saved with the correct
relational key value.  I want to force an add(parent file) when the 'insert'
button for the child browse is pressed and self.request = insertrecord.  Of
course, I then need to also retrieve the new primary key value so that it is
added to the child record.  What's the best/easiest way to do this in ABC??

Thanks ...



Mon, 13 Oct 2003 05:15:34 GMT  
 SQL - adding child record from parent form
Hi all,


Quote:
> In a form (parent file) where the primary key is an autoincrement key >on

the SQL server, I have a browse for a child file.  If the user goes to >add
a child record without having first saved the parent record, the

Quote:
>autoincrement key remains zero and the child record isn't saved with the
>correct relational key value.

   I normally hide or disable the child controls until the parent record has
been saved.    Not the best solution but simple and it works.

   Also, if memory serves, the SuperInvoice third party template set had an
option for this task, but I can not say for sure since I do not use the
product.

 Dennis
"It is important to understand that bugs are not
things that happen to our programs without our cooperation."
Richard A. O'Keefe



Wed, 15 Oct 2003 22:12:10 GMT  
 SQL - adding child record from parent form
Arnor,

Quote:
>Remember that you need this also for all Memos & Blobs because they
>are not part of the record structure:)

Yes, that is true.  Thanks for the reminder.

John
John Dunn



Sat, 18 Oct 2003 01:45:30 GMT  
 SQL - adding child record from parent form
Braxton,

Here is an example of code I use to save the parent record before
adding a child record.  This is on the EVENT:Accepted embed of the
insert button:

Local Variables:

SaveRecord          LIKE(BEn:Record)

--------

DO ValidateFields    ! perform field validation

IF ValidationFailed THEN CYCLE.

OF ?InsertPSe
     ThisWindow.Update

     IF ThisWindow.Request = InsertRecord
        Access:BEn.Insert()
       SaveRecord = BEn:Record
       Access:BEn.RestoreBuffer(ThisWindow.Saved,True)
       BEn:Record  = SaveRecord
       ThisWindow.Request  = ChangeRecord
      ThisWindow.OriginalRequest = ChangeRecord
      WATCH(BEn)
      Access:BEn.Fetch(BEn:AcctNoKey)
      ThisWindow.Saved = Access:BEn.SaveBuffer()
      SaveRecord  = BEn:Record
      0{PROP:Text}  = 'Change Billing Entity'
   END ! if

John

On Sun, 29 Apr 2001 13:09:23 -0500, "Braxton DeGarmo"

Quote:

>Thanks, Dennis.  I've approached the problem this way in the past as well,
>but keep looking for a better solution.  Seems every time I ask this
>question on the NGs, no one has a good answer, if at all.  Guess no one has
>figured out how to do this with Clarion and SQL back ends<G>.

>====================================


>> Hi all,



>> > In a form (parent file) where the primary key is an autoincrement key
>>on
>> the SQL server, I have a browse for a child file.  If the user goes to
>>add
>> a child record without having first saved the parent record, the
>> >autoincrement key remains zero and the child record isn't saved with the
>> >correct relational key value.

>>    I normally hide or disable the child controls until the parent record
>has
>> been saved.    Not the best solution but simple and it works.

>>    Also, if memory serves, the SuperInvoice third party template set had
>an
>> option for this task, but I can not say for sure since I do not use the
>> product.

>>  Dennis
>> "It is important to understand that bugs are not
>> things that happen to our programs without our cooperation."
>> Richard A. O'Keefe

John Dunn



Fri, 17 Oct 2003 15:42:51 GMT  
 SQL - adding child record from parent form
Thanks, Dennis.  I've approached the problem this way in the past as well,
but keep looking for a better solution.  Seems every time I ask this
question on the NGs, no one has a good answer, if at all.  Guess no one has
figured out how to do this with Clarion and SQL back ends<G>.

====================================


Quote:
> Hi all,



> > In a form (parent file) where the primary key is an autoincrement key
>on
> the SQL server, I have a browse for a child file.  If the user goes to
>add
> a child record without having first saved the parent record, the
> >autoincrement key remains zero and the child record isn't saved with the
> >correct relational key value.

>    I normally hide or disable the child controls until the parent record
has
> been saved.    Not the best solution but simple and it works.

>    Also, if memory serves, the SuperInvoice third party template set had
an
> option for this task, but I can not say for sure since I do not use the
> product.

>  Dennis
> "It is important to understand that bugs are not
> things that happen to our programs without our cooperation."
> Richard A. O'Keefe



Fri, 17 Oct 2003 02:09:23 GMT  
 SQL - adding child record from parent form
John,

Thank you, thank you.  This is what I've been seeking.  I was close in my
own attempts, but your code shows me where/why mine failed.

Braxton
====================================

Quote:
> Braxton,

> Here is an example of code I use to save the parent record before
> adding a child record.  This is on the EVENT:Accepted embed of the
> insert button:

> Local Variables:

> SaveRecord          LIKE(BEn:Record)

> --------

> DO ValidateFields    ! perform field validation

> IF ValidationFailed THEN CYCLE.

> OF ?InsertPSe
>      ThisWindow.Update

>      IF ThisWindow.Request = InsertRecord
>         Access:BEn.Insert()
>        SaveRecord = BEn:Record
>        Access:BEn.RestoreBuffer(ThisWindow.Saved,True)
>        BEn:Record  = SaveRecord
>        ThisWindow.Request  = ChangeRecord
>       ThisWindow.OriginalRequest = ChangeRecord
>       WATCH(BEn)
>       Access:BEn.Fetch(BEn:AcctNoKey)
>       ThisWindow.Saved = Access:BEn.SaveBuffer()
>       SaveRecord  = BEn:Record
>       0{PROP:Text}  = 'Change Billing Entity'
>    END ! if

> John

> On Sun, 29 Apr 2001 13:09:23 -0500, "Braxton DeGarmo"

> >Thanks, Dennis.  I've approached the problem this way in the past as
well,
> >but keep looking for a better solution.  Seems every time I ask this
> >question on the NGs, no one has a good answer, if at all.  Guess no one
has
> >figured out how to do this with Clarion and SQL back ends<G>.

> >====================================


> >> Hi all,



> >> > In a form (parent file) where the primary key is an autoincrement key
> >>on
> >> the SQL server, I have a browse for a child file.  If the user goes to
> >>add
> >> a child record without having first saved the parent record, the
> >> >autoincrement key remains zero and the child record isn't saved with
the
> >> >correct relational key value.

> >>    I normally hide or disable the child controls until the parent
record
> >has
> >> been saved.    Not the best solution but simple and it works.

> >>    Also, if memory serves, the SuperInvoice third party template set
had
> >an
> >> option for this task, but I can not say for sure since I do not use the
> >> product.

> >>  Dennis
> >> "It is important to understand that bugs are not
> >> things that happen to our programs without our cooperation."
> >> Richard A. O'Keefe

> John Dunn




Fri, 17 Oct 2003 23:10:07 GMT  
 SQL - adding child record from parent form
Hi John, Braxton,



Quote:
>Local Variables:

>SaveRecord          LIKE(BEn:Record)

Remember that you need this also for all Memos & Blobs because they
are not part of the record structure:)

Best regards,



Sat, 18 Oct 2003 02:52:45 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Add Child Record Within New Parent Record form.

2. Adding child records for a newly inserted parent record (CW2003)

3. delete parent-child record without using form

4. Adding child clears parent record

5. Copying grand parent, parent, and child records

6. Adding Child Record to a Child file during Update

7. Parent form cleared when EIP child browse

8. Child browse in parent form

9. I have Update Form (parent file) with Browse List (child file)

10. Update of Parent Form from Child

11. CW4 Writing to a parent file from child file's update form

12. Scrolling form in a parent child situation

 

 
Powered by phpBB® Forum Software