I have a table that contains data that is updated annually and keeps previous year data as well to reference - back 5 years.
So, to keep data in proper perspective, I created fields (as Current Year, Year-1, Year-2, Year-3, etc.) to store and reference data values.
I created a query to find and display the correct year information regardless of the current year. I then reference the Current Year query to show the correct year(s) to use.
However, my customer actually wants to see year values in the queries I am displaying. I know I can create a form with fields labeled with correct year values. HOWEVER, a form can only be 21 inches wide and the amount of data I need to display exceeds that length by several inches and I am trying to provide a product on a single page instead of breaking it up into several pages; if possible.
Is there a way I can programatically rename query fields from "Curr Yr Data" to "2015 Data" or "Cur Yr vs Year-1 Data" to "2015 vs 2014 Data"?
I researched for days and cannot come up with a process to do this progromatically. I don't want to manually make changes in query or table names every year. :banghead:
I thought I might be able to use the VBA ALTER TABLE function but cannot seen to add a concatenation function to the string for a new name also: "
CODE
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set dbs = CurrentDb
Set tdf = dbs.TableDefs("tmptbl_NewQueryDump")
Set fld = tdf.Fields("Unplanned Turnover (Current - Year-1)")
fld.Name = "Unplanned Turnover (" & [qrySelect_MarketYear].[Market Year] & " - " & [qrySelect_MarketYear-1].[MarketYear] & ")"
dbs.Close
Set dbs = Nothing
Set fld = Nothing
Set tdf = Nothing
MsgBox "Changed"
#CODE
I keep getting a "cannot find field name" error message. It finds the original field name but cannot resolve the new field name to change the table field name as coded. Simple field name changes work but concatenated changes do not.
Any suggestions would be GREATLY appreciated.
Thanks in advance for your time and assistance.
So, to keep data in proper perspective, I created fields (as Current Year, Year-1, Year-2, Year-3, etc.) to store and reference data values.
I created a query to find and display the correct year information regardless of the current year. I then reference the Current Year query to show the correct year(s) to use.
However, my customer actually wants to see year values in the queries I am displaying. I know I can create a form with fields labeled with correct year values. HOWEVER, a form can only be 21 inches wide and the amount of data I need to display exceeds that length by several inches and I am trying to provide a product on a single page instead of breaking it up into several pages; if possible.
Is there a way I can programatically rename query fields from "Curr Yr Data" to "2015 Data" or "Cur Yr vs Year-1 Data" to "2015 vs 2014 Data"?
I researched for days and cannot come up with a process to do this progromatically. I don't want to manually make changes in query or table names every year. :banghead:
I thought I might be able to use the VBA ALTER TABLE function but cannot seen to add a concatenation function to the string for a new name also: "
CODE
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set dbs = CurrentDb
Set tdf = dbs.TableDefs("tmptbl_NewQueryDump")
Set fld = tdf.Fields("Unplanned Turnover (Current - Year-1)")
fld.Name = "Unplanned Turnover (" & [qrySelect_MarketYear].[Market Year] & " - " & [qrySelect_MarketYear-1].[MarketYear] & ")"
dbs.Close
Set dbs = Nothing
Set fld = Nothing
Set tdf = Nothing
MsgBox "Changed"
#CODE
I keep getting a "cannot find field name" error message. It finds the original field name but cannot resolve the new field name to change the table field name as coded. Simple field name changes work but concatenated changes do not.
Any suggestions would be GREATLY appreciated.
Thanks in advance for your time and assistance.