I'm working with a table with a field for each month of the year. (can't be
changed)
Why can't it be changed? It's WRONG. It simply is. This is a good spreadsheet
but it is *not* correct design for a table!
Is there a Year field? How can you tell whether [January] refers to January
2008, or 2009, or 1737?
I need to query data for last month and I would like to be able to
prompt for a field. Does anyone have some code that would allow me to do
this?
You can't use parameters to select a field. You'll need to either build a SQL
string based on the value of a form control, or restucture the data. You can
do so temporarily and dynamically using a UNION query. This needs to be built
in the SQL window (not the query grid). You can "unravel" the data with a
query like
SELECT this, that, "January" AS TheMonth, [January] AS TheValue
FROM yourtable
UNION ALL
SELECT this, that, "February" AS TheMonth, [February] AS TheValue
FROM yourtable
UNION ALL
SELECT this, that, "March" AS TheMonth, [March] AS TheValue
FROM yourtable
UNION ALL
< etc >
You can then base a parameter query with a criterion of "February" on the
field TheMonth and look for the value for that month in [TheValue].