Link to home
Start Free TrialLog in
Avatar of jarrodprice
jarrodprice

asked on

Creating a lookup field from multiple selections of a related field.

In table #1 there are 2 fields "name" and "code".  In table #2 there are the same 2 fields.  The name field in table 2 is a radio button value list of the name fields from table #1.  The code field in table#2 is a lookup of the code field from table #1.

For each name field in table#1, (red, blue, green, etc) there is a corresponding number in the code field.  In table #2, I can select more then one name field at once (red and green..etc).  If in table#1 red is "1" green is "2", the lookup result for the code field of table#2 should be "12", thus combining the codes from the selected name fields in table #1.

I am not sure how to achieve this.
Avatar of Member_2_908359
Member_2_908359
Flag of France image

it won't work this way because the looked up value is replacing the previous one, not appending it to the existing one (which you need)
to do this make it an auto-entered field/ calculated value instead of lookedup (do not replace existing value must not be checked)
table2:code = table2:code & table1:code
this way, everytime, you change the name in table2, a new code is appended.
Avatar of jarrodprice
jarrodprice

ASKER

For some reason, that does not work properly.  It seems to be that as soon as code "1" is selected, every other radio box selected adds another 1.  The same thing seems to happen with 2.  When I unselect a box, it also adds another 1.
Now I understand.  I said they were radio buttons, but what I meant was checkboxes.  It works fine when I switch to radio buttons, but you can only have 1 radio button selected, which does not work for me.  Is there a way to do this with checkboxes?
You can also do this with a calculation in table 2 such as:

If(PatternCount ( name;"Red")>0;1;"")&
If(PatternCount ( name;"Green")>0;2;"")&
If(PatternCount ( name;"Blue")>0;4;"")&
If(PatternCount ( name;"Yellow")>0;3;"")

But that assumes that the values won't change in Table 1. I also created a custom function that uses recursion but in order to use it you would have to be using Filemaker Advanced. You can't create Custom functions without it. If you do have FMPA 8 I called the function MultiCode(text) and its definition looks like this:

Let(
[
lines = ValueCount(Text);
CurrentItem = GetValue(Text; Lines);
item = LeftWords(CurrentItem;1) ;

result = Case(Lines>1; MultiCode(LeftValues ( Text;Lines-1)))

];
result & item
)

Where Text is the user's selection of names. the value list looks like:

01 Red
02 Green
03 Yellow
04 Blue

And the result looks like:
010304
if red, yellow and blue were selected. I put the values in with zeros to aid in sorting since value lists automatically sort alphabetically.

I can post a sample database if you wish. You don't need FMPA to use the file or custom function, just to create it.
If you could create a sample, that would be great.  I am having trouble visualizing.  I do have filmaker 8.5
ASKER CERTIFIED SOLUTION
Avatar of JoJohn2004
JoJohn2004

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Awesome.  Thank you!
My only question.  If I go with the Multicode, is their a way to sort the result lowest to highest like the calculation.  It isnt essential, but it would be nice.

humm, sorry for not following up, but I am living on european time...
and even if it closed, you may interested in my way for check boxes:
http://www.carina-tm.com/upload/colour_lookup.fp7
as it looks much simpler to me.
The results of multicode() are in the order the checkboxes are clicked on. It might be possible to sort the choices before the function runs with another function. I will try to look at it this afternoon.
Yes, that odes look much simplier.  Is there a reason why not to go with this as opposed to a custom command approach?
It is an elegant approach. One difference however is that the data in the name field will be the code, not the name. If you try to use that field in any other way that is not attached to the value list, you will not see the text, only the numbers.
> Is there a reason why not to go with this as opposed to a custom command approach
----------
why make it complex when it can be simple? and custom functions can be edited with the adv version only, something you don't always have at a customer's.
I use them when I have no other choice.

> you will not see the text, only the numbers.
--------
true, but you can still get the text from the related table if you know the number by linking the tables using the number field, so there is a workaround.

anyway make your choice now!
You will also be able to return a sorted result by using the custom function. I have included an example:

http://www.nantucketisle.com/ftp/pub/Samples/ValueLookup2.sitx
http://www.nantucketisle.com/ftp/pub/Samples/ValueLookup2.zip

the functions were found at Brian Dunning's site
http://www.briandunning.com/cf/290

and written by Theo Ros
Thank you both for the excellent help