
Normalizing a flat table w/VBA
Greetings, all -
I have a table created using an Access add-in utility (FMS' Total Access
Statistics). The TAS scenario, when run, calculates correlation
coefficients (r values) and generates an output table of values in a
nonnormalized "matrix" form. Here're some sample data to illustrate
(mind the linewrap):
Datafield Apples Oranges Pears Tangerines
Apples 1.0000 0.1234 0.9876 0.2345
Oranges 0.1234 1.0000 0.5678 0.9988
Pears 0.9876 0.5678 1.0000 0.3456
Tangerines 0.2345 0.9988 0.3456 1.0000
I need to stack these data in a tall-skinny form in order to look at
each comparison and run additional analyses on the results. I am
presently using a "normalizing Union query," which looks something like
this in SQL:
SELECT DataField as Fruit1, "Apples" AS Fruit2, [Apples] AS RValue FROM
MyTable WHERE[DataField]<>"Apples"
UNION
SELECT DataField as Fruit1, "Oranges" AS Fruit2, [Oranges] AS RValue
FROM MyTable WHERE [DataField]<>"Oranges"
UNION
SELECT...yada yada yada...
This returns a recordset which resembles the following:
Fruit1 Fruit2 RValue
Apples Oranges 0.1234
Apples Pears 0.9876
Apples Tangerines 0.2345
Oranges Apples 0.1234
Oranges Pears 0.5678
...and so on.
But this "normalizing Union query" requires me to hard-code the name of
each fruit. Is there any way to programmatically rearrange this
recordset in the slightly-more-normalized form shown above? Any help
would be very much appreciated.
TIA,
LeAnne
PS. Using Access 97, so any sample code needs to be DAO. Thanks!