Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    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?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 28 Times in 28 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts