Setting a field source using code

  • Thread starter Thread starter JimP
  • Start date Start date
J

JimP

I have a field in a query named Field1 (e.g.). Can I use code to set the
source for the field?

e.g. The following works in the query grid, but I would like to create a
function to do the same.

Field1: Choose(Id, Source1, Source2,,,,,n)
 
JimP,

Just out of curiosity, why? What is your goal compared to how it works now?
I have a field in a query named Field1 (e.g.). Can I use code to set the
source for the field?

I could be wrong, but I think the only way to do that would to delete and
recreate (or edit) via code. It is possible, but would need you to post the
SQL statement of your query in order to help you more.
e.g. The following works in the query grid, but I would like to create a
function to do the same.

Field1: Choose(Id, Source1, Source2,,,,,n)

Is "Id" a field in the table?

CHOOSE() is already a built-in function. Why would you want to create
user-defined function (UDF) that will do the same thing as a built-in
function?

Just taking a guess, but it sounds like you are trying to look up a value
(Source1, Source2,,,,,n) based on another field in your table (Id). IMO,
the best way to do this would be to have a separate lookup table. In this
lookup table, there would be 2 fields/columns. The first column would be
called ID and it would be the exact same data type as the "Id" column in the
main table. The values stored in this column would be the same values
stored in the "Id" column of your main table, but unique values only (also
could have more or less unique values than are in the main table) The
second column would be Description (or Category or what ever suits your
need). The data type of this column would probably be Text, but can be what
ever you need it to be. Then I would add this lookup table to your query,
create a join on the ID column in this lookup table and the Id column in
your main table, set the type of join accordingly, then add the
Description/Category/(what have you) from the lookup table to your query.
When the query runs, It will automatically return the Description (etc...)
that corresponds to the Id in the main table (as long as you have a record
in the lookup table where the ID matches the Id from the main table).

HTH,

Conan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top