Hot Topic (More than 10 Replies) another subform qestion (Read 1992 times)
FlipGilbert
Full Member
***
Offline


Running Ver 2.6.4

Posts: 236
Location: Sandy Eggo
Joined: Mar 8th, 2005
another subform qestion
Mar 13th, 2015 at 5:52pm
Print Post Print Post  
I wrote a code that i can add a new customer on the fly to a customer database from my dispatch database using xresultsetcreatenewrecord.
Is it possible to do the same to a sub form in the customer database from the dispatch database also? or i'm i just getting..... GREEDY?
  

It's not what a man says that matters or how he says it, but what he does and how he does it.
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: another subform qestion
Reply #1 - Mar 15th, 2015 at 2:52pm
Print Post Print Post  
Yes Flip, that can be done and I use that very frequently in my program. The process is:

1. You create subform record just as you create normal record.

2. Open Parent Record (of course the Resultset)

3. You reparent the child record (Subform record) to Parent (Mainform record)

I have pasted important part of one of my codes to do that just to give you an idea that how it could be done.

Code
Select All
If @clientLocalValue ("Process") = "Success" and vDescription <> ""then  //only when processed properly - to avoid putting value in Document subform
						{



							vChildRSID = @XResultSetSearch(@FN, "Client!Documents", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Chart==")

							If vChildRSID > -1 then
								{
									xResultSetCreateNewRecord (vChildRSID)
									xResultSetValue (vChildRSID, "RecNumber", vRecNumber)
									xResultSetValue (vChildRSID, "DateAdded", vDateAdded)
									xResultSetValue (vChildRSID, "Chart", vChart)
									xResultSetValue (vChildRSID, "Description", vDescription)
									xResultSetValue (vChildRSID, "View", vView)
									xResultSetValue (vChildRSID, "FileName", vFileName)
									xResultSetValue (vChildRSID, "Key", vKey)
									//since it is processed from Index Database - to be reparent later either in Menu through button or Physical Form On Exit Event of DX2 when Record is New
									//xResultSetValue (vChildRSID, "Marker", 1)


									xResultSetClose (vChildRSID)

								}

							vParentRSID = @XResultSetSearch(@FN, "Client", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Chart=" + vChart)


								If @XResultSetLocked (vParentRSID) = 1 Then
									{
										@MSGBox ("Parent ResultSet is Locked", "The Document will not go to DocumentSubform", "Process it from Other Database")

									}




							If vParentRSID > -1 then
								{
									vRecordsFound = @XResultSetTotal (vParentRSID)

									If vRecordsFound = 1 then
										{
											//ClientLocalValue ("DocToBeReParented", "Yes")   // ReParenting will be either done in Menu or DX2 on  Exit Event of Physical when Record is New


											vChildRSID = @XResultSetSearch(@FN, "Client!Documents", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Chart=" + vChart, "!Key=" + vKey)

											If vChildRSID > -1 then
												{
													If @XResultSetTotal (vChildRSID) = 1 then
														{

											                               // xResultSetSort (vChildRSID, "DateAdded:1")  //Since this is just one record, sorting will not work
															xResultSetReparent (vParentRSID, "DocumentSubForm", vChildRSID)

															If @Error = 1 then
																{
																	WriteLN ("Reparent Failed")
																}
														}


													xResultSetClose (vChildRSID)
												}

										}

										Else if vRecordsFound = 0 then
										{
											WriteLN ("Chart " + vChart + " Does not exist in Client Database!!! Please Correct it" )
											vFailureIndicator = 1
										}
										Else if vRecordsFound > 1 then
										{

											WriteLN ("Chart " + vChart + " has Multiple Entries in Client Database!!! Please Correct it" )
											vFailureIndicator = 1
										}

									XResultSetClose (vParentRSID)


								}
							xResultSetClose (vChildRSID)       // for additional precaution - in case if it is not closed
							xResultSetClose (vParentRSID)		// for additional precaution - in case if it is not closed

						}
 

  
Back to top
 
IP Logged
 
FlipGilbert
Full Member
***
Offline


Running Ver 2.6.4

Posts: 236
Location: Sandy Eggo
Joined: Mar 8th, 2005
Re: another subform qestion
Reply #2 - Mar 17th, 2015 at 9:37pm
Print Post Print Post  
XResultSetReparent!! Thank you for your help

Still not re parenting.. I even double checked the field name argument like it says to in the book, all the other code works well. Do you see anything obvious?

Code
Select All
var vChildRSID as Int
var vParentRSID as Int

If (@FormResultSetTotal("Customers:(Update)") = -1)

	{
		If (Callstatus = "open")
			{
				vChildRSID = @XResultSetSearch(@FN, "Customers!Equipment", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!equipment_type==")
				If vChildRSID > -1
					{
						If @XResultSetTotal(vChildRSID) = 0
							{

								XResultSetCreateNewRecord(vChildRSID)
								XResultSetValue(vChildRSID, "Equipment_Type", Machine_Type)
								XResultSetValue(vChildRSID, "other_info", eqinfo2)
								XResultSetValue(vChildRSID, "Model_No", DModel)
								XResultSetValue(vChildRSID, "Serial_No", DSerial)
								XResultSetValue(vChildRSID, "Last_Updated_On", CallDate)
								XResultSetValue(vChildRSID, "Co_Name", CompanyName)
							}
					}
				xResultSetClose(vChildRSID)
				vParentRSID = @XResultSetSearch(@FN, "Customers", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!co_name=" + CompanyName)
	 			If vParentRSID > -1
					{
						vChildRSID = @XResultSetSearch(@FN, "Customers!Equipment", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Co_Name=" + CompanyName, "!Equipment_Type=" + Machine_Type)
						If vChildRSID > -1
							{
								If @XResultSetTotal(vChildRSID) = 1
									{
										xResultSetReparent(vParentRSID, "Equiplist", vChildRSID)
                                                                                @msgbox("","Makes it to here okay","")

									}
							}
						xResultSetClose(vChildRSID)
					}
				XResultSetClose(vParentRSID)

			}
	}
Else
	{
		@MsgBox("YOU are in Update Customers", "Please close out of it and try again", "")
	}
 



  

It's not what a man says that matters or how he says it, but what he does and how he does it.
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: another subform qestion
Reply #3 - Mar 17th, 2015 at 10:27pm
Print Post Print Post  
Is EquipList is the Subrecord field name? I believe the Subrecord Field name goes there.

xResultSetReparent(vParentRSID, "Equiplist", vChildRSID)
  
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: another subform qestion
Reply #4 - Mar 17th, 2015 at 10:38pm
Print Post Print Post  
The subform setting dialog box is important here. Make certain it is naturally linked. I am attaching here my subform setting dialog box.
  

Subform_Setting.jpg ( 76 KB | 82 Downloads )
Subform_Setting.jpg
Back to top
 
IP Logged
 
FlipGilbert
Full Member
***
Offline


Running Ver 2.6.4

Posts: 236
Location: Sandy Eggo
Joined: Mar 8th, 2005
Re: another subform qestion
Reply #5 - Mar 17th, 2015 at 11:35pm
Print Post Print Post  
yes,

#1
Display form "Equipment List"

#2
"Automatic (natural links)"

#3
""
#4
"Equiplist"

#5 "Tables"

I even tried it leaving the vChildRSID open and did the @msgbox("", vChildRSID,"") double checked spelling also.
funny thing is my popup box uses a key field "co_name" to populate so it shows up, just not the subform of the customer database. its just an orphan
  

It's not what a man says that matters or how he says it, but what he does and how he does it.
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: another subform qestion
Reply #6 - Mar 17th, 2015 at 11:55pm
Print Post Print Post  
Hi Flip,
vChildRSID = @XResultSetSearch(@FN, "Customers!Equipment", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Co_Name=" + CompanyName, "!Equipment_Type=" + Machine_Type)

With above code, you might be pulling out more than one subrecord. You want to have just the record you just created. Please check that. I would rather use something like SerialNumber or Key, that way you know that there cannot be more than one record and it is the record that you just created.  I do not think Equipment_Type is a unique field for you. May be with CompanyName and Equipment_Type may make it Unique sometimes. I could be wrong here as I do not know your database structure.
  
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: another subform qestion
Reply #7 - Mar 18th, 2015 at 12:49am
Print Post Print Post  
Computers works well with numbers. I create one unique number for chart or record that goes in both parent and child records. It is text field (String)

Code
Select All
If @Mode ( ) = 0 and Name <> "" and Record = "" then  //Name is the required field - This code  will create record in Attachment Database, so one can attach a file while addting the record
							//Record Number required before before subrecord is created
	{


		If @IsNew = 1 and Record = "" then
			{

				vRecordNumber = @TN (@GlobalValue ("RecordNumber")) + 1

							Globalvalue ("RecordNumber", @str (vRecordNumber))

							vNumberExtension = "00000" + @GlobalValue ("RecordNumber")
							vNumberExtension = @Right (vNumberExtension, 5)
							Record = vNumberExtension

			}


	}

 



This comes very handy if for any reasons parent and children gets separated... it has one to many relations and you can easily reparent them.

The other unique field only goes in the SubDatabase, I called that Key field. It is just used to choose the last child record created.

Code
Select All
vNextNumber = @ToNumber (@GlobalValue ("RecordLocator")) + 1
								//WriteLn ("This is Next Number " + vNextNumber)
								GlobalValue ("RecordLocator", vNextNumber)
								vNextNumber = @text (7 - @Len (vNextNumber), "0") + vNextNumber
								vKey = vNextNumber
 



Problem here could be, one ends up choosing multiple or none records either in child resultset or parent resultset. Using Numerical value (eventhough technically it is string) make it easier to deal with them to select one record each.
  
Back to top
 
IP Logged
 
FlipGilbert
Full Member
***
Offline


Running Ver 2.6.4

Posts: 236
Location: Sandy Eggo
Joined: Mar 8th, 2005
Re: another subform qestion
Reply #8 - Mar 18th, 2015 at 2:06am
Print Post Print Post  
Thank you Bharat
My machine_type field is a unique key field, it consists of both a letters and numbers about 25 characters.
Running tests on the code it is retrieving the correct single parent form and the correct single subform it's just not re parenting........?
  

It's not what a man says that matters or how he says it, but what he does and how he does it.
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: another subform qestion
Reply #9 - Mar 18th, 2015 at 3:44am
Print Post Print Post  
Looking at the creation of the child record, all of the values are coming directly from elements and not from variables. Where are you initiating this from?

Code
Select All
XResultSetCreateNewRecord(vChildRSID)
								XResultSetValue(vChildRSID, "Equipment_Type", Machine_Type)
								XResultSetValue(vChildRSID, "other_info", eqinfo2)
								XResultSetValue(vChildRSID, "Model_No", DModel)
								XResultSetValue(vChildRSID, "Serial_No", DSerial)
								XResultSetValue(vChildRSID, "Last_Updated_On", CallDate)
								XResultSetValue(vChildRSID, "Co_Name", CompanyName)
 



Machine_Type
DSerial
DModel
CallDate
CompanyName

All of the above seems to be elements of the form where you are initiating this code.. Is that so?

XResultSetValue ( ) command post the value.
  
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: another subform qestion
Reply #10 - Mar 18th, 2015 at 3:13pm
Print Post Print Post  
I had gone through the same path...
http://lantica.com/Forum4/cgi-bin/yabb2/YaBB.pl?num=1330520370/6#6

But there is other way if you have to make subrecord from the same database form.
  
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: another subform qestion
Reply #11 - Mar 18th, 2015 at 3:46pm
Print Post Print Post  
Since you are making the subform record from the same database form that the subform is attached to, you will have to use following method.

Code
Select All
					If @clientLocalValue ("Process") = "Success" and vDescription <> ""then  //only when processed properly - to avoid putting value in Document subform
						{


						If vDescription <> "" and @FormFieldValue ("Documents", "Description", 1) = "" then
							{


								//nn = @FormNewRecord ("Scripts2")
								//WriteLN ("vLoop = " + @str (vLoop))
								//WriteLN ("nn = " + @str (nn))
								FormresultsetCurrentPosition ("Documents", 1)

								FormFieldValue ("Documents", "RecNumber", 1, vRecNumber)
								FormFieldValue ("Documents", "DateAdded", 1, vDateAdded)
								FormFieldValue ("Documents", "Chart", 1, Chart)
								FormFieldValue ("Documents", "Description", 1, vDescription)
								FormFieldValue ("Documents", "View", 1, vView)
								FormFieldValue ("Documents", "FileName", 1, vFileName)
								FormFieldValue ("Documents", "Key", 1, vKey)
								FormFieldValue ("Documents", "Print", 1, @Chr (252) )






								FormCommit ("Documents")

							}
						Else if vDescription <> "" and @FormFieldValue ("Documents", "Description", 1) <> "" then
							{




								nn = @FormNewRecord ("Documents")
								//WriteLn ("The value on nn = " + @Str (nn) )




								//WriteLN ("vLoop = " + @str (vLoop))
								//WriteLN ("nn = " + @str (nn))

								FormFieldValue ("Documents", "RecNumber", nn, vRecNumber)
								FormFieldValue ("Documents", "DateAdded", nn, vDateAdded)
								FormFieldValue ("Documents", "Chart", nn, Chart)
								FormFieldValue ("Documents", "Description", nn, vDescription)
								FormFieldValue ("Documents", "View", nn, vView)
								FormFieldValue ("Documents", "FileName", nn, vFileName)
								FormFieldValue ("Documents", "Key", nn, vKey)
								FormFieldValue ("Documents", "Print", nn, @Chr (252) )

								Formcommit ("Documents")




							}

 



First it checks whether the first record is blanked or not. Logic is the first record in the subform always exists. If it is blank you just fill it up. Subsequent record you make and fill it up. 

I have gone through this frustrations in the past. But now it is clear. If you make subrecord from other database, you use XResultset command. If you make it from the same database form, you use @Formfieldvalue ( ). I am quite sure this should work for you.
  
Back to top
 
IP Logged
 
FlipGilbert
Full Member
***
Offline


Running Ver 2.6.4

Posts: 236
Location: Sandy Eggo
Joined: Mar 8th, 2005
Re: another subform qestion
Reply #12 - Mar 18th, 2015 at 8:21pm
Print Post Print Post  
I think I am starting to understand.

My command code is written in a 3rd database called "Dispatch" and it is parenting it to something...(unknown) as it does not show up as an orphan, and it is located in the "Customers" subform named "Equipment". If I take out the re parenting it will show up as orphan.
Either way it does not show up in the parent form "Customers".
  

It's not what a man says that matters or how he says it, but what he does and how he does it.
Back to top
 
IP Logged