none
Addressing fields in tables RRS feed

  • Question

  • I have 12 fields that I wish to suffix, whereby I can use the same code to store information based on a suffix value. 

    i.e. Month1, Month2............Month12

    is it possible to address the required field by quoting Monthx? using some form of indexing.

    I am aware that arrays can be used within code but fail to see how the same methodology can be used to name fields within tables.

    Saturday, February 17, 2018 3:26 PM

All replies

  • i.e. Month1, Month2............Month12

    is it possible to address the required field by quoting Monthx? using some form of indexing.

    Hi R.M.A.

    If you have the table-object in a variable, e.g. cur_table, then you can address the fields as:

        For x = 1 to 12
            cur_table("Month" & x) = ...
        Next

    Personally, I never write directly in tables, but always by way of a form.

    Imb.


    • Edited by Imb-hb Saturday, February 17, 2018 3:43 PM
    Saturday, February 17, 2018 3:42 PM
  • I suggest you don’t really want to do that. Instead, make the “suffix” into a column. Much simpler, and more inline with the relational model.


    peter n roth - http://PNR1.com, Maybe some useful stuff

    Saturday, February 17, 2018 4:46 PM
  • By having multiple columns, one for each month, you are 'encoding data as column headings'.  A fundamental principle of the database relational model is the Information Principle (Codd's Rule #1). This requires that all data be stored as values at column positions in rows in tables, and in no other way.

    The correct way to model this is to decompose the table so that  each value is stored in a single column in multiple rows in a related table which also contains a foreign key column referencing the primary key of the referenced  table, and a column identifying the month to which the value applies.

    Ken Sheridan, Stafford, England

    Sunday, February 18, 2018 1:30 PM