Normal Topic Total Records - Programming (Read 1325 times)
actiontech
Full Member
***
Offline



Posts: 173
Joined: Apr 10th, 2016
Total Records - Programming
Feb 7th, 2018 at 6:24pm
Print Post Print Post  
Hello, I'm trying to display the total records in a field in a subform. I essentially want these fields to mirror the ones at the top left of the Sesame Database Manager GUI that shows the current record (left side) and the total number of records (rightside) I have no trouble displaying the current record using @ResultSetCurrentPosition(). However, my problem lies in using @FormResultSetTotal("form"). Here is my code:

(Universal Event)

Code
Select All
var vTotal as Int

vTotal = @FormResultSetTotal("Work")

FormFieldValue(@Layout + ":(Update)", "Total_Jobs", 0, vTotal) 



What happens is that this field Total_Jobs always seems 1 record behind the actual account. For example, at the top it might show 4 total records but down at the bottom it shows 3. But when I click my previous record button:

(Universal Event)

Code
Select All
var vPos as Int

	If (@Mode() = 0) Or (@Mode() = 1)
	{
		vPos = @ResultSetCurrentPosition()
		vPos = vPos - 1
		If vPos > 0
		{
			ResultSetCurrentPosition(vPos)
		}
	}

@Play("Click")
 



It will sometimes correct itself and show the proper amount of records. I'm really stumped on this. I've tried adding "+1" to force it to correct itself but that in itself was buggy and not correct all the time. I've tried using different variations of the @ResultSetTotal() command and I've even tried many of the different various events to run it on. (e.g. On Form Change, On Form Entry, etc.) All to no avail. Am I missing something here or is the @ResultSetTotal() running too soon, like before the new record is actually created, thus it's information is not up to date? Not sure, but I thought I'd throw it out there, to see if I might get some feedback. Thank you for your time.
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Total Records - Programming
Reply #1 - Feb 8th, 2018 at 9:52pm
Print Post Print Post  
First things first: Stop using the Universal Event. I can't stress this enough. Code placed in it is going to run WAY WAY WAY more often than needed and will slow down the end user when they are navigating and entering data.

In your post it seems like the count is off on newly created and unsaved subrecords. Since the newly created record has not been committed it's not really in the ResultSet to be counted towards the total.

I believe all you need is the following code in the On Form Entry Event:
Code
Select All
	Cur_Jobs = @ResultSetCurrentPosition()
	If @IsNew Then
	{
		Total_Jobs = @ResultSetCurrentPosition()
	}
	Else
	{
		Total_Jobs = @ResultSetTotal()
	} 



-Ray
  

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



Posts: 173
Joined: Apr 10th, 2016
Re: Total Records - Programming
Reply #2 - Feb 9th, 2018 at 3:05pm
Print Post Print Post  
Thank you. I had to modify it to:

(Universal Event)

Code
Select All
If (@Mode() = 1)
{
	Current_Job = @ResultSetCurrentPosition()
	If @IsNew Then
	{
		Total_Jobs = @ResultSetCurrentPosition()
	}
	Else
	{
		Total_Jobs = @ResultSetTotal()
	}
}
 



And now runs fine. Didn't want to run it on Universal Event, but couldn't seem to get it to work instantaneously any other way. Doesn't seem to slow it down too much for now, but I'll probably change it to another event timing in the future if I can get it to work another way. Thanks again.


  
Back to top
 
IP Logged