Normal Topic Delete Subform Records (Read 823 times)
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Delete Subform Records
Jun 9th, 2009 at 5:23pm
Print Post Print Post  
Scripts2 is TableView Subform. What I want to do is - Delete all the subform records.

Code
Select All
If Use_EST = 0 then
	 {
		   While(@FormResultSetTotal("Scripts2") > 1)
			{
				FormDeleteRecord("Scripts2", 1)
			}
			WriteLN ( "While Loop is complteted")
			 FormDeleteRecord("Scripts2", 1)
	  }
 



The above code is fired from Main form CheckBox on Element Immediate Change. It Deletes all the subform records and then computer freezes. Only way to get out of this is to kill the Sesame using ctrl-alt-del.  

What am I doing wrong?
  
Back to top
 
IP Logged
 
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
Re: Delete Subform Records
Reply #1 - Jun 9th, 2009 at 6:23pm
Print Post Print Post  
Perhepsyou need a Formcommit("Scripts2").

If Use_EST = 0 then
     {
             While(@FormResultSetTotal("Scripts2") > 1)
                {
                      FormDeleteRecord("Scripts2", 1)
                            Formcommit("Scripts2")
                }
                WriteLN ( "While Loop is complteted")
                 FormDeleteRecord("Scripts2", 1)
      }
  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Delete Subform Records
Reply #2 - Jun 9th, 2009 at 8:01pm
Print Post Print Post  
Thanks Amor for reply. Even that would not work.
Well, the following code works. I believe the value of @FormResultsetTotal ( ) is not reduced in the earlier code.

Code
Select All
n = @FormResultSetTotal ("Scripts2")

			While n > 1
			{
				FormDeleteRecord("Scripts2", 1)
				n = n - 1
			}
			//WriteLN ( "While Loop is complteted")
			 FormDeleteRecord("Scripts2", 1)
 



Still there is a problem with that one last (or the first record) which cannot be deleted using code just as one cannot make that record using FormNewRecord ( ).

I guess I will have to blank the values using FormFieldValue ( ) code!
  
Back to top
 
IP Logged
 
Ben
Lantica Support
*****
Offline



Posts: 218
Joined: Apr 7th, 2005
Re: Delete Subform Records
Reply #3 - Jun 9th, 2009 at 8:57pm
Print Post Print Post  
Try using the programming below.

Code
Select All
var vCount as Int
If Use_EST = 0 then
     {
	    vCount = @FormResultSetTotal("Scripts2")
	    While(vCount > 1)
	    {
		FormDeleteRecord("Scripts2", 1)
		FormCommit("Scripts2")
		vCount = @FormResultSetTotal("Scripts2")
	    }
	    FormDeleteRecord("Scripts2", 1)
	  FormCommit("Scripts2")
	  FormCommit("")
     }
	 

  
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Delete Subform Records
Reply #4 - Jun 9th, 2009 at 9:00pm
Print Post Print Post  
Thanks Ben.
  
Back to top
 
IP Logged