Normal Topic Creating a new record using @XResultSetSubSet (Read 1116 times)
Calibrate1
Member
*
Offline



Posts: 38
Location: Dayton, OH
Joined: Jun 28th, 2006
Creating a new record using @XResultSetSubSet
Mar 10th, 2009 at 8:49pm
Print Post Print Post  
I am using programming to notify the user to accomplish a set task.  Once they are notified to perform the task, I have it asking for the user to state the date it was completed.  I need this date posted to a subrecord of another form inside the same application.  

I have this working when there is an initial record in the subform, but not when I need to create the first record in the subform.  Here is a snippet of the programming I am trying to use.


[code]vToday = @Month(@Date) + "/" + @DOM(@Date) + "/" + @Year(@Date)
     If vTotalSurvey <> 0
     {
           XResultSetCreateNewRecord(vRSID_Client_Child)
     }
     XResultSetValue(vRSID_Client_Child, "Last Survey Sent", vToday)
     XResultSetReparent(vRSID_Client_Parent, "SurveyData", vRSID_Client_Child)[/code]

Do I have the programming incorrect to establish a first record in a subform, or do I need to have an inital subrecord first for the @XResultSetSubSet / XResultSetValue to work?

Thanks for the help!
Christy
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Creating a new record using @XResultSetSubSet
Reply #1 - Mar 10th, 2009 at 9:21pm
Print Post Print Post  
Can we see the rest of this code, Christy? I can't see enough from this bit to get the big picture.
  

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



Posts: 38
Location: Dayton, OH
Joined: Jun 28th, 2006
Re: Creating a new record using @XResultSetSubSet
Reply #2 - Mar 11th, 2009 at 12:53pm
Print Post Print Post  
Code
Select All
// Get Result set for client database in order to get the SurveyData Subform records
vRSID_Client_Parent = @XResultSetSearch(@FN, "Client", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Client Number=" + Client Number)
If vRSID_Client_Parent > -1
{
	vRSID_Client_Child = @XResultSetSubSet(vRSID_Client_Parent, "SurveyData")
	If vRSID_Client_Child > -1
	{
		// Get the number of records and if there is not any no survey was sent
		vTotalSurvey = @XResultSetTotal(vRSID_Client_Child)
		If vTotalSurvey = 0
		{
			vSurveySent = 0
		}
		Else	// Get the last date that a survey was sent to see if another survey should be sent
		{
			XResultSetCurrentPosition(vRSID_Client_Child, vTotalSurvey)
			vSurveySent = @XResultSetValue(vRSID_Client_Child, "Last Survey Sent")
		}
		vSurveyDays = @Date - @TD(vSurveySent)
		If vSurveyDays >= 300
		{
			If vShipVia = "On-Site"		// Notify which survey should be sent
			{
				@MSGBOX("Please send ON-SITE survey with certificates of calibration.", "", "")
			}
			Else
			{
				@MSGBOX("Please send IN-HOUSE survey with certificates of calibration.", "", "")
			}
			vSurvey = @ASKUSER("Did you send the survey today?", "", "")	// If Yes - Post to the subform SurveyData
			If vSurvey = TRUE
			{
				vToday = @Month(@Date) + "/" + @DOM(@Date) + "/" + @Year(@Date)
				If vTotalSurvey <> 0
				{
					XResultSetCreateNewRecord(vRSID_Client_Child)
				}
				XResultSetValue(vRSID_Client_Child, "Last Survey Sent", vToday)
				XResultSetReparent(vRSID_Client_Parent, "SurveyData", vRSID_Client_Child)
				FormCommit("SurveyData")
				FormCommit("Client")
			}
		}
	}
}

XResultSetClose(vRSID_Client_Parent)
XResultSetClose(vRSID_Client_Child)
 



Here is more of the code.  It seems to work perfectly if there is an at least one record in the subform.  It just seems to do nothing when I am trying to create the first subform record that is naturally related to the form parent's record.
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Creating a new record using @XResultSetSubSet
Reply #3 - Mar 11th, 2009 at 3:39pm
Print Post Print Post  
We've done some testing here and are able to add a new record to the subset and reparent it even if there is not a subrecord already present.

I notice two things in your code. First, you are closing resultsets you may not have successfully opened. This does not appear to be causing your problem, but it would be a good idea to fix it. You want something like this:

Code
Select All
If vRSID_Client_Parent > -1
{
	vRSID_Client_Child = @XResultSetSubSet(vRSID_Client_Parent, "SurveyData")
	If vRSID_Client_Child > -1
	{
		XResultSetClose(vRSID_Client_Child)
	}
	XResultSetClose(vRSID_Client_Parent)
}
 



At this point, I'm thinking that the problem is the two FormCommits. Having Form commands and XResultSet commands operating on the same records at the same time is usually a red flag. If the records you are affecting are not visible in a subform on the current form, then you shouldn't need the FormCommits. If they are, then you should be using commands like FormFieldValue instead of XResultSet commands. I suggest you try commenting out the FormCommits and see if that fixes the issue.
  

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



Posts: 38
Location: Dayton, OH
Joined: Jun 28th, 2006
Re: Creating a new record using @XResultSetSubSet
Reply #4 - Mar 11th, 2009 at 4:34pm
Print Post Print Post  
I did fix the XResultSetClose() commands.  Thank you for that, I never did think much about where I needed to put them, and just put them at the end of the programming area, just incase I needed something from the result set.

I commented out the FormCommit commands as the subform I need to post to is not visible at the time of posting.  Unfortunately, It still isn't working.  I had only put them in during debugging as just something to try and see if that might make it work.  

I wonder if where the issue is if that if there is not records, should I use the XResultSetCreateNewRecord() command and then use the XResultSetValue()?
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Creating a new record using @XResultSetSubSet
Reply #5 - Mar 11th, 2009 at 5:31pm
Print Post Print Post  
We looked at your code again and I think Cow spotted it. It's looks like a logical error.

This bit here:
Code
Select All
	If vTotalSurvey <> 0
	{
		XResultSetCreateNewRecord(vRSID_Client_Child)
	}
 



The above says to only make a new record if the total number of records is not zero. Therefore, if there is not already at least one child record, no new record gets made. Fix the logic to reflect the condition you actually want and you should be good to go.
  

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



Posts: 38
Location: Dayton, OH
Joined: Jun 28th, 2006
Re: Creating a new record using @XResultSetSubSet
Reply #6 - Mar 11th, 2009 at 5:48pm
Print Post Print Post  
Okay, I must still be doing something wrong cause I can't get it to work.  Here is my current programming

Code
Select All
vSurvey = @ASKUSER("Did you send the survey today?", "", "")	// If Yes - Post to the subform SurveyData
If vSurvey = TRUE
{
	vToday = @Month(@Date) + "/" + @DOM(@Date) + "/" + @Year(@Date)
	XResultSetCreateNewRecord(vRSID_Client_Child)
	XResultSetValue(vRSID_Client_Child, "Last Survey Sent", vToday)
	XResultSetReparent(vRSID_Client_Parent, "SurveyData", vRSID_Client_Child)
}
 



So if they click on yes that the survey was sent, that it will format today's date, create a new subrecord (whether others do or do not exist), post today's date to the subform field in the other database and reparent it to the natural parent record.  

Where am I going wrong?

Thanks everyone
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Creating a new record using @XResultSetSubSet
Reply #7 - Mar 11th, 2009 at 6:02pm
Print Post Print Post  
Did the logic change alter the behavior at all? Or do you still have something that works if there are existing subrecords and does not work if there are not existing subrecords?
  

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



Posts: 38
Location: Dayton, OH
Joined: Jun 28th, 2006
Re: Creating a new record using @XResultSetSubSet
Reply #8 - Mar 11th, 2009 at 7:53pm
Print Post Print Post  
Nope, I have the same behavior.  Works perfectly as long as there is already at least one record.

The only thing that I can think of now is that maybe I need to upgrade our version from 2.0.6 to 2.1.0.  And see if maybe it might work then.
  
Back to top
 
IP Logged
 
Calibrate1
Member
*
Offline



Posts: 38
Location: Dayton, OH
Joined: Jun 28th, 2006
Re: Creating a new record using @XResultSetSubSet
Reply #9 - Mar 11th, 2009 at 9:41pm
Print Post Print Post  
I have finished upgrading to 2.1

It works now!  Thank you for all your help though
  
Back to top
 
IP Logged