I'm creating an MS Access report based on a dynamic SQL query (a stored procedure) that outputs fields based on the current date, this means that the fields it delivers when run change depending on the current date when the query is run.
I've created a vba script that dynamically changes the Access report's control sources using the same calculation that SQL server uses to output the fields (this seems to be working OK), however I now want to create some sum calculations based on the values of those dynamic controls but I don't seem to be able to use the control names in the calculation (rather than the control source).
E.G.
- There is currently a (dynamic) field output from my SQL query called "201606 P", along with static fields "Person" and "Project".
- MS Access report is opened.
- MS Access vba script does the same calculation as happens in the SQL query and changes the control named "Date1P" to have a control source of "201606 P".
- The report is grouped by person, and I want to calculate the sum of the "201606 P" field for each person.
- My sum 'unbound' textbox control has a control source of "=Sum([Date1P])", with Date1P being the NAME of a control I want to sum in the group, rather than being a field provided in the query.
- When opened Access presents a parameter box asking for the value of [Date1P].
Can I calculate one control using just the name of another control, rather than the control source for that control (which I can't know before the query is run)?
Should I just work around it and do more scripting to dynamically insert the control sources for the sum fields?