Use a custom function to help. Here is one which returns only unique values from a list.
With that in your arsenal, create a new calculation field in table A which is:
UniqueValues( List( tableB::code ) )
the description paints a general picture but there are enough moving parts to this, posting a file would be a big help in eyeballing where you are having problems.
First, there should not be any duplicates in the child table (Table B) to begin with. Then you could simply use the List() function to collect them without looping.
If you cannot avoid duplicates, you could still define a value list using values from Table B::Code, showing only related values starting from Table A. Then use the ValueListItems() function to retrieve the values.
As reelsteve noted, we don't have an accurate enough description of your script to tell what's wrong with it.
BTW, if you are using version 12, you can also use ExecuteSQL() to get a list of distinct values only.
Message was edited by: Michael Horak