Normal Topic @FormNewRecord for subform difficulty (Read 481 times)
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
@FormNewRecord for subform difficulty
Mar 21st, 2012 at 7:18pm
Print Post Print Post  
I'm stumped.  Upon saving parent Orders, trying to loop through subform SOLines, FormDeleteRecord if the subform record is "spacer", then @FormNewRecord and populate the new "spacer" record with data, then save.   Code will delete correctly, but when it gets to FormNewRecord, it doesn't create a new record, it steps on the last good record.  For example, I pull up a sales order with 3 subrecords, one of which is a 'spacer' record and the code will delete, then add a new 'spacer' record.  So the writeln's should be
vStot = 3 (three original records)
vStot = 2 (the total after deleting the spacer record)
vNSOR = 3 (the total after @FormNewRecord)
vStot = 3.  (the total after the code is finished populating the 'new' record).

But what I get is:

vStot = 3 (three original records)
vStot = 2 (the total after deleting the spacer record)
vNSOR = 3 (the total after @FormNewRecord)
vStot = 2 (problem:  this should be "3", but the @FormNewRecord didn't "take", and so the programming pulls up the last exiting good subform record (record #2) and steps on it.)

What am I doing wrong?

     If (vClientMailToDifferent <> "") and (vInvoiceEmailAddress <> "") // and (vSpace <> "Y") // variables obtained from RSdni XResultSetSearch above
          {

           FormCommit("SOLines")
           FormCommit("")

        vStot = @FormResultSetTotal("SOLines")

writeln("vStot = " + vStot)

           vLoopS = 1
           For vLoopS = 1 to vStot
                
                 vIS = 0
                 vIS = @FormFieldValue("SOLines", "ItemNum", vLoopS)
                 If vIS = "SPACER"
                   {
                       WarningLevel(0)
                       FormDeleteRecord("SOLines", vLoopS)
                       WarningLevel(1)
                       vStot = vStot - 1
                   }
                 vLoopS = vLoopS + 1
                 
           Next

           FormCommit("SOLines")
           FormCommit("")


           FormNotifyForm("SOLines", -7)
              vStot = @FormResultSetTotal("SOLines")

writeln("vStot = " + vStot)

           vNSOR = @FormNewRecord("SOLines")

writeln("vNSOR = " + vNSOR)

           FormCommit("SOLines")
           FormCommit("")
           vStot = @FormResultSetTotal("SOLines")

writeln("vStot = " + vStot)
           
           FormFieldValue("SOLines", "ItemNum", vStot, "SPACER")
           FormFieldValue("SOLines", "ItemCat", vStot, "DESC")

           FormFieldValue("SOLines", "SONum", vStot, "vSONum")
           FormFieldValue("SOLines", "PorM", vStot, "M")
           FormFieldValue("SOLines", "Posted", vStot, "P")
           FormCommit("SOLines")
           FormCommit("")

       }

// ////////////// end of the Spacer SOLines section
  

Larry
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: @FormNewRecord for subform difficulty
Reply #1 - Mar 21st, 2012 at 8:38pm
Print Post Print Post  
Hello,

Try:

Code
Select All
     If (vClientMailToDifferent <> "") and (vInvoiceEmailAddress <> "") // and (vSpace <> "Y") // variables obtained from RSdni XResultSetSearch above
          {

           FormCommit("SOLines")
           FormCommit("")

        vStot = @FormResultSetTotal("SOLines")

writeln("vStot = " + vStot)

           vLoopS = 1
           For vLoopS = 1 to vStot
               
                 vIS = 0
                 vIS = @FormFieldValue("SOLines", "ItemNum", vLoopS)
                 If vIS = "SPACER"
                   {
                       WarningLevel(0)
                       FormDeleteRecord("SOLines", vLoopS)
                       WarningLevel(1)
                       vStot = vStot - 1
                   }
                 vLoopS = vLoopS + 1
                
           Next

           FormCommit("SOLines")
           FormCommit("")


           FormNotifyForm("SOLines", -7)
              vStot = @FormResultSetTotal("SOLines")

writeln("vStot = " + vStot)

           vNSOR = @FormNewRecord("SOLines")

writeln("vNSOR = " + vNSOR)
           FormResultSetCurrentPosition("SOLines", vNSOR)
           FormFieldValue("SOLines", "ItemNum", 0, "SPACER")
           FormFieldValue("SOLines", "ItemCat", 0, "DESC")

           FormFieldValue("SOLines", "SONum", 0, "vSONum")
           FormFieldValue("SOLines", "PorM", 0, "M")
           FormFieldValue("SOLines", "Posted", 0, "P")
           FormCommit("SOLines")
           FormCommit("")
           FormNotifyForm("SOLines", 7)

           vStot = @FormResultSetTotal("SOLines")
writeln("vStot = " + vStot)

       } 



Also I am not sure on your database but you may want
Code
Select All
FormFieldValue("SOLines", "SONum", 0, "vSONum") 


to be
Code
Select All
FormFieldValue("SOLines", "SONum", 0, vSONum) 


unless you actually wanna store the literal string 'vSONum'.

The problem you are running into is trying to do a FormCommit on a blank record. Sesame does not save blank records, so you have to fill it in and then save it.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: @FormNewRecord for subform difficulty
Reply #2 - Mar 22nd, 2012 at 12:27am
Print Post Print Post  
Ahhh, Thanks, Ray.


I was so frazzled when I posted the SOS I was a basket of monkeys.

I stumbled onto the following about 4pm today, after taking a two hour break, during which I resisted the temptation to begin drinking heavily.  Now that I've got something that works, I'll go back in and polish and study what you've suggested (I was hoping I could get in here and post my clumsy fix before anyone had seen my original post - darn it!).

// ////////////// the below section adds a spacer SOLines record for clients that want an email invoice

     If (vClientMailToDifferent <> "") and (vInvoiceEmailAddress <> "") // and (vSpace <> "Y") // variables obtained from RSdni XResultSetSearch above
          {

           FormNotifyForm("SOLines", -7)
           FormNotifyForm("SOLines", -6)
           FormNotifyForm("SOLines", -1)
           FormNotifyForm("SOLines", -5)
           FormNotifyForm("SOLines", -4)

           FormCommit("SOLines")
           FormCommit("")

              vStot = @FormResultSetTotal("SOLines")

writeln("vStot = " + vStot)
           
           vLoopS = 1
           For vLoopS = 1 to vStot
                 
                
                 vIS = 0
                 vIS = @FormFieldValue("SOLines", "ItemNum", vLoopS)
writeln("vIS = " + vIS)
                 If vIS = "SPACER"
                   {
                       WarningLevel(0)
                       FormDeleteRecord("SOLines", vLoopS)
                       WarningLevel(1)
                   }                  
           Next

           FormCommit("SOLines")
           FormCommit("")

              vStot = @FormResultSetTotal("SOLines")

writeln("vStot = " + vStot)

           vNSOR = @FormNewRecord("SOLines")
           FormFieldValue("SOLines", "ItemNum", vNSOR, "SPACER")
           FormFieldValue("SOLines", "ItemCat", vNSOR, "DESC")

           FormFieldValue("SOLines", "SONum", vNSOR, vSONum)
           FormFieldValue("SOLines", "PorM", vNSOR, "M")
           FormFieldValue("SOLines", "Posted", vNSOR, "P")


writeln("vNSOR = " + vNSOR)

           //FormCommit("SOLines")
           FormCommit("Orders")
           ForceRedraw()
           vStot = @FormResultSetTotal("SOLines")

writeln("vStot = " + vStot)
           

       }

// ////////////// end of the Spacer SOLines section
  

Larry
Back to top
IP Logged