[Table].[Field] Substitute Variable

M

Mike C

I'm trying to substitute a variable for a field name. For example, I have a
table with columns labeled 1,2,3,4,5....12. I have a combo box on a form
named Dashboard with the months of the year and the stored value is 1-12. I'm
trying to get a query to read
.Form!Dashboard!MonthID rather than
hardcode
.[1], for example. Any thougths? Thanks!
 
K

Klatuu

Your field naming is terrible.
There is no such reference as this in Access
.Form!Dashboard!MonthID
It would be
Forms!Dashboard!MonthID

A query can't really return variable fields as you are thinking.

What are you trying to accomplish with the query. I am sure there is a way.
If what you are trying to do is return a value from the MonthID selected in
the combo from the column that corresponds to that month, and all other
columns should be null, you can create Calculated fields in your query and
use an IIf for each field to determine what to return. for example

Jan: IIf([Forms]![Dashboard]![MonthID] = 1, [1], Null)
Next column
Feb: IIf([Forms]![Dashboard]![MonthID] = 2, [2], Null)
....
Dec: IIf([Forms]![Dashboard]![MonthID] = 12, [12], Null)

If this is not what you are after, post back with more detail and we can
work it out.
 

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

Top