Dblookup and unique

I am trying to automatically fill in address fields based on a company name which is generated from a button which has the following formula:

List1 := @Unique(@DbColumn("":"NoCache";"85256f4e:006706e3 "; "Company Lookup"; 1));
Choice := @Prompt([OKCANCELLIST]; "Customer";"Select the Customer"; List1;

Then (and I will only use 1 address field to save space) I want to fill in the address field. So , this follows the above:

FIELD address := @Unique(@DbLookup("" : "NoCache"; "" ; "Company Lookup"; Choice; 2));
@If(@IsError(address); ""; address);

The problem is that it is still returning 3 or 4 of the same addresses. So, I guess @Unique is not the correct command to use?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Andrea ErcolinoCommented:
List1 := @Unique(@DbColumn("":"NoCache";"85256f4e:006706e3"; "Company Lookup"; 1));

Choice := @Prompt([OKCANCELLIST]; "Customer";"Select the Customer"; ""; List1 );
@If( Choice = ""; @Return( "" ); "" );

FIELD address := @DbLookup("" : "NoCache"; "" ; "Company Lookup"; Choice; 2);
@If(@IsError(address); ""; address);
Bozzie4IT ArchitectCommented:
Several problems in your code :

You don't catch errors in dblookups (that can occur sometimes), your error checking for the address is incorrect, and your @prompt can return multiple values (correct ?).
Your button code should look like this :

res := @DbColumn("":"NoCache";"85256f4e:006706e3 "; "Company Lookup"; 1);
List1 := @if(@iserror(res);"Error getting companies";@trim(@Unique(res)));
Choice := @Prompt([OKCANCELLIST]; "Customer";"Select the Customer"; @subset(List1;1);List1);
@if(Choice = "";@return(""); Choice = null; @return("");"");
res2 := @DbLookup("" : "NoCache"; "" ; "Company Lookup"; Choice; 2);
FIELD address := @if(@iserror(res2);"More Errors";@trim(@unique(res2)));""



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
schmad01Author Commented:
That's the ticket!  Thanks alot!
Andrea ErcolinoCommented:
Bozzie4> @if(Choice = "";@return(""); Choice = null; @return("");"");
<<Choice = null>> ? :-)

I agree with points to Bozzie... because I forgot the first error check and thought the formula was executing in a computed field!

However I don't think the prompt can return multiple values without [OkCancelListMult]...
So <<@trim(@unique(res2))>> could be simply <<res2>>. And I think <<@trim(@unique(res))>> could be simply <<@unique(res)>> because it's very uncommon that a "Company Lookup" view lists empty companies (and if it does, should be considered an oversight)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.