I really don't know of a method to return only the fields in a row of data
that are not null and then in the next row return a different set of fields
where the data is not null.
You might be satisfied with an output of fields like the following (slashes
are breaks between fields)
PK Field / 0 / 1 / 2
Rec 1 / FieldA: 1 / FieldB: 82 / blank
Rec 2 / FieldB: 22 / Blank / Blank
Rec 3 / FieldA: 1 / FieldB: 82 / FieldC: Lessons Learned
Rec 4 / FieldA: 1 / FieldC: Lessons Learned / Blank
IF so, you could try something like the following (4 field table example):
SELECT PrimaryKeyField, FieldA as FldVal, "FieldA" as FldName, 1 As ColNumber
FROM SomeTable
WHERE FieldA is Not Null
UNION ALL
SELECT PrimaryKeyField, FieldB, "FieldB",2
FROM SomeTable
WHERE FieldB is Not Null
UNION ALL
SELECT PrimaryKeyField, FieldC, "FieldC",3
FROM SomeTable
WHERE FieldC is Not Null
Order By PrimaryKeyField, fldName
Using a UNION QUERY like the above would allow you to get a vertical
representation of the data you seem to want.
Turning that into a horizontal layout could be a challenge involving a ranking
query and then a crosstab query.
SELECT Q1.PrimaryKeyField, Q1.fldName, Q1.fldVal
, Count(Q2.PrimaryKeyField) as Rank
FROM qUnion as Q1 LEFT JOIN qUnion as Q2
ON Q1.PrimaryKeyField = Q2.PrimaryKeyField
AND Q1.ColNumber < Q2.ColNumber
GROUP BY Q1.PrimaryKeyField, Q1.fldName, Q1.fldVal
Now use that saved ranking query in a Crosstab query
TRANSFORM First(FldName & ":" & fldVal) as Result
SELECT PrimaryKeyField
FROM qRankedValues
GROUP BY PrimaryKeyField
PIVOT Rank
Good luck. With any fairly large set of data this is likely to be slow since
there will be no indexes available in the 2nd and 3rd query to help speed
things up.
As a matter of fact, it might be wise to use the UNION query to populate a
table with indexes on the fields to increase the speed up the process.
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County