Normal Topic Copying form data to subform problem (Read 1014 times)
tcgeo
Full Member
***
Offline



Posts: 278
Location: Traverse City, Michigan
Joined: May 13th, 2008
Copying form data to subform problem
Jun 9th, 2008 at 1:18pm
Print Post Print Post  
I’ve been trying to mass update using the following code to copy Stock# data from the Main form to a new record in the Subform called Details. There’s actually five other data elements that are copied along with Stock# at the same time,  I didn’t think you’d want to see the code for all of them.

var vstk1 as string
var nn as string

If @FormFieldValue("Details", "Stock#", 0) <> "" Then
                 {
                       nn = @FormNewRecord("Details")
                 }
                 Else
                 {
                       nn = 1
                 }
           
     vstk1 = @formfieldvalue("Main","Stock#",0)

     FormFieldValue("Details", "StockNo", nn, vstk1)


There is already 1 row of information in the subform. When I run mass update a window pops up and says; “Executing a mass update on 1 record.”.  It copies the information correctly but it randomly (no pattern that I can find) creates two entries of the same thing instead of just one.  If there are two rows of data in the subform, the popup says; “Executing a mass update on 2 records.” When I press continue it again copies the information correctly but this time it sometimes creates two or four entries of the same thing instead of just one.

Have I missed a vital part of the code to make it copy only one row of data instead of duplicates?

Also, I’ve had to use a macro to mass update all records, there’s 2600 of them. Is there code available that will do this instead?

Any help would be appreciated.
  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Copying form data to subform problem
Reply #1 - Jun 9th, 2008 at 1:56pm
Print Post Print Post  
It looks to me like you are running the mass update on the subrecords instead of on the main records.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
tcgeo
Full Member
***
Offline



Posts: 278
Location: Traverse City, Michigan
Joined: May 13th, 2008
Re: Copying form data to subform problem
Reply #2 - Jun 9th, 2008 at 2:23pm
Print Post Print Post  
You are correct. I originally attempted to run this from the main form but I couldn’t get it to place the data in a new record on the subform unless I ran it from the subform. I just tested it again, running it from the main form instead of the subform. It copies the data over the existing first row of data on the subform. What do I need to change so that the data will be placed into a new record on the subform?
  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Copying form data to subform problem
Reply #3 - Jun 9th, 2008 at 2:24pm
Print Post Print Post  
tcgeo wrote on Jun 9th, 2008 at 2:23pm:
You are correct. I originally attempted to run this from the main form but I couldn’t get it to place the data in a new record on the subform unless I ran it from the subform. I just tested it again, running it from the main form instead of the subform. It copies the data over the existing first row of data on the subform. What do I need to change so that the data will be placed into a new record on the subform?

Which version of Sesame are you using?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
tcgeo
Full Member
***
Offline



Posts: 278
Location: Traverse City, Michigan
Joined: May 13th, 2008
Re: Copying form data to subform problem
Reply #4 - Jun 9th, 2008 at 2:29pm
Print Post Print Post  
Sesame Personal 2.0.6
  
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: Copying form data to subform problem
Reply #5 - Jun 9th, 2008 at 2:51pm
Print Post Print Post  
Try

Code
Select All
var vstk1 as string
var nn as string

		     If @FormResultSetTotal("Details") > 0 Then
		     {
			     nn = @FormNewRecord("Details")
		     }
		     Else
		     {
			     nn = 1
		     }
		     vstk1 = @FormFieldValue("Main", "Stock#", 0)
		     FormFieldValue("Details", "StockNo", nn, vstk1)
 



Let me know if it works for you,
-Ray
  

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



Posts: 278
Location: Traverse City, Michigan
Joined: May 13th, 2008
Re: Copying form data to subform problem
Reply #6 - Jun 9th, 2008 at 3:05pm
Print Post Print Post  
That did the trick!

Thanks very much for your help.
  
Back to top
IP Logged
 
tcgeo
Full Member
***
Offline



Posts: 278
Location: Traverse City, Michigan
Joined: May 13th, 2008
Re: Copying form data to subform problem
Reply #7 - Jun 9th, 2008 at 3:27pm
Print Post Print Post  
Again I appreciate your time and help. Can you give me some insight as to what “If @FormResultSetTotal("Details") > 0” is saying in order for “@FormNewRecord” to execute? 

In looking at the definition and examples in the Programming Guide I’m quite sure I never would have thought to use this.

Thanks again,

Brandon
  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Copying form data to subform problem
Reply #8 - Jun 9th, 2008 at 3:47pm
Print Post Print Post  
tcgeo wrote on Jun 9th, 2008 at 3:27pm:
Again I appreciate your time and help. Can you give me some insight as to what “If @FormResultSetTotal("Details") > 0” is saying in order for “@FormNewRecord” to execute?

In 2.x, if @FormResultSetTotal returns zero, then there are no existing subrecords and the first row should be used since it is a new blank record waiting for you to type something.  Otherwise, there are already existing records and we should make a new one instead of using the first row.

This is slightly different from 1.x and some of the examples may still reflect the older behavior.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
tcgeo
Full Member
***
Offline



Posts: 278
Location: Traverse City, Michigan
Joined: May 13th, 2008
Re: Copying form data to subform problem
Reply #9 - Jun 9th, 2008 at 4:10pm
Print Post Print Post  
Thanks for the explanation. I understand it now.

Thanks to both of you for your help, you’ve saved me a lot of time.

Brandon
  
Back to top
IP Logged