string field name

  • Thread starter Thread starter judith
  • Start date Start date
J

judith

how do i refer to a dynamic field name please. I have fields month1, month2,
etc and only want to print the value for the current month
Something like

=val("[month" & [monthVal] & "]")

Thanks
 
One method:

Don't bind the control (txtShowCurrent) to anything (set its source to blank).

In the section containing the control you should be able to use VBA to assign
the value.

Me.txtShowCurrent = Me.Controls("Month" & Month(Date())

This solution would require you to have 12 non-visible controls on your report
in the relevant section bound to each of the 12 month fields.

Another option might be to use the DLookup function to get the value you want
from the report's record source. That depends on how your query is set up.
DLookup("Month" & Month(Date()),"SomeQueryOrTable")
This might require using the additional argument of DLookup to filter the result.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 
Back
Top