Normal Topic passing variables from form to subform (Read 1013 times)
FSGROUP
Full Member
***
Offline


No personal text

Posts: 179
Location: Edmonton, Alberta, Canada
Joined: Jan 14th, 2004
passing variables from form to subform
Jan 29th, 2004 at 4:55pm
Print Post Print Post  
How does one go about doing this?

I have a Clients form with a Children subform. I'd like to be able to insert the Client ID from "Clients" into the "Children" ID  field when a user chooses to add a new child for a client.

I tried using global vars, setting it in Clients when a record was opened and then retrieving it when performing an add in Children, but it seems the code for Children runs before that of Clients, so that the ID is never correct.

Perplexed,
  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: passing variables from form to subform
Reply #1 - Jan 29th, 2004 at 5:05pm
Print Post Print Post  
FormFieldValue will allow you to set an LE in the child form from the parent. In Gems:

FormFieldValue("Gems", "Origin", 1, "Canada")

will set the origin field to "Canada" on the Gems subform in the first instance of the subform.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
FSGROUP
Full Member
***
Offline


No personal text

Posts: 179
Location: Edmonton, Alberta, Canada
Joined: Jan 14th, 2004
Re: passing variables from form to subform
Reply #2 - Jan 29th, 2004 at 5:52pm
Print Post Print Post  
FormFieldValue is static however.  My dilemma is that I could be adding a 6th child for the 10th client in the DB.

I keep getting an exception error which shuts down Designer.  This is the code I've written:

Clients:Shockedn Form Entry:
GlobalValue("curr_id", ID)  // set global var to client's ID

Children:Shockedn Element Entry:
writeln("Client ID is" + @GlobalValue("curr_id")) 


It seems any programming for a subform causes an error when I access the subforms from the main form(even if it's a simple writeln("Hi")). Why oh why?
  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: passing variables from form to subform
Reply #3 - Jan 29th, 2004 at 6:40pm
Print Post Print Post  
Quote:
FormFieldValue is static however.  My dilemma is that I could be adding a 6th child for the 10th client in the DB.


I'm not sure what you mean by "static" - the "instance" argument specifies which child to change.

FormFieldValue("Gems", "Origin", 6, "Panama")

Sets the origin LE in the sixth Gems subform under the current form.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: passing variables from form to subform
Reply #4 - Jan 29th, 2004 at 6:40pm
Print Post Print Post  
Quote:
FormFieldValue will allow you to set an LE in the child form from the parent. In Gems:

FormFieldValue("Gems", "Origin", 1, "Canada")

will set the origin field to "Canada" on the Gems subform in the first instance of the subform.


I am not sure if this is a question a statement or just a lot of rambling but this topic brings many issues to a head. What ever this is it is as much a design question as it is a programming Sesame question.  ???

Following FSGROUPS question, and figuring it is leading down the road a lot of us have discussed amongst ourselves the question equates to:

We have a form that contains client specific info. Say an element is called CUSNUMBER. Cusnumber is set by Sbasic logic using @number to set it to a unique number.

We want to have a child subform that is say invoices  and we would like to have many invoices for this customer. If we use Natural links we can go to the subform enter data and press f10  for the next occurrence over and over again.

It seems like a nice clean and elegant method to track activity of that customer.

If we are not using Natural links we would need to have a key. Say the CUSNUMBER.

using the logic in your example FormFieldValue("mydatabase", "CUSNUMBER", 1, CUSNUMBER)

it will add the cusnumber to cusnumber element in the first instance of the subform  I can probably use Sbasic to count the amount of  child records and return that to the logic replacing the 1 with what ever number I am up to that needs the Cusnumber added. The problem here is we would have to create the child first then update with key information.

When I look at the final result I have a child record with a matching key. From old habits and the desire to be able to work with the data from separate databases outside of the whole application we feel it is necessary to have the key. But what would be the downside to using natural links letting Sesame do its internal record keeping and still adding my key just for data manipulation outside the application.

It would seem to me that if this database is used from scratch I would get the best of both worlds. If I import existing data I might have a problem with this theory.

So if there is no downside to using natural links and I still want a matching key would a good method be to after using Sesames Natural links to create the child have a command button that when pressed updates the Customer number element?

I hope this is somewhat clear as to my question and my intended use.

Thanks
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
FSGROUP
Full Member
***
Offline


No personal text

Posts: 179
Location: Edmonton, Alberta, Canada
Joined: Jan 14th, 2004
Re: passing variables from form to subform
Reply #5 - Jan 29th, 2004 at 7:19pm
Print Post Print Post  
first of all, what i meant by "static" is that you'd have to know which record it is you wanted to set the value to. I'd like to be able to set/retrieve values from any given record/subrecord.

I am having enough troubles trying to run simple lines of code in subforms from the main form.  I can't seem to figure out why the code runs fine when just the subform is opened, but not when I click on the subform from the main form. gah! I am at a standstill as to passing vars back and forth from subform to form(or vice versa)

As for BobScott's question on natural links, the downside I find is when generating a report from the subform and attempting to retrieve the customer's address, phone #(and the like) from the main form.  Having a *key* allows this lookup.

I suppose a command button to update the Cust No in the subform is a solution, but I mean "Why?!".  Shouldn't there be an easier way to do this?

Sorry for the blathering. I am so accustomed to programming in SQL and Oracle that the lack of functionality in Sesame fries my mind Embarrassed




  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: passing variables from form to subform
Reply #6 - Jan 29th, 2004 at 7:49pm
Print Post Print Post  
Quote:
first of all, what i meant by "static" is that you'd have to know which record it is you wanted to set the value to. I'd like to be able to set/retrieve values from any given record/subrecord.


@FormResultSetCurrentPosition will tell you the current subform instance. Allowing you to use FormFieldValue on "any given record/subrecord".
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged