Results 1 to 2 of 2
Thread: concatenating field name (2000)
2006-07-06, 14:34 #1
- Join Date
- Nov 2002
- Mt. Olive, North Carolina, USA
- Thanked 0 Times in 0 Posts
concatenating field name (2000)
I am trying to select field names in a query based on an unbound control on a form. The fields in tblUCOST have names like std07, std06, std05 etc. The form name is frmStdNewYr and the control name is nstdyr.
I have tried:
SELECT tblUCOST."std" & [forms].[frmstdnewyr].[nstdyr], tblUCOST."std" & ([forms].[frmstdnewyr].[nstdyr] - 1) FROM tblUCOST;
but I get a invalid use of . or ! or ().
Is it possible to accomplish what I am trying to do?
2006-07-06, 15:59 #2
- Join Date
- Mar 2002
- Thanked 30 Times in 30 Posts
Re: concatenating field name (2000)
You cannot do this in the SQL view of a stored query - the field names must be fixed, they cannot be variable. You can, however, assemble an SQL string in VBA code:
Dim strSQL As String
strSQL = "SELECT std" & [Forms]![frmstdnewyr]![nstdyr] & ", std" & ([Forms]![frmstdnewyr]![nstdyr] - 1) & "FROM tblUCOST"
You can use this string to open a DAO or ADO recordset or to assign it as the SQL text of a stored query.