rename a column in Access 2000 query, utising a variable from a form

Posted on 2006-05-18
Last Modified: 2012-08-13
It is quite simple to rename a column in Access 2000 via doing the following in access: Newname:fieldname

However does anyone know how to rename  the field utilsing a variable.

Ie:  There is a form with a text box control, it is called DateTo30June

In the query there is a parameter set: Form!formname!DateTo30June

When I run the query, I would like to do somthing similar:

Field1    Field2     Field3     DateTo30June:Field4

Where by, once query is run The column name of field 4 is the variable: DateTo30June

Is this possible,
Question by:doyle007
    1 Comment
    LVL 58

    Accepted Solution

    Hello doyle007

    The names of the fields is part of the "structural" portion of the query, and not the "data" portion. It does not allow variables or references to form controls.

    You will need to rewrite your query from code. Imagine you have this query qryMyTest:

        Select Field1, Field2, Field3 As Something From tblSomeTable

    And you want to replace "something" with the current value of DateTo30June. You could have a button on your form with something like this:

        CurrentDb.QueryDefs("qryMyTest").SQL _
            = "Select Field1, Field2, Field3 As " & Me.DateTo30June _
            & " From tblSomeTable"

    When you then open the query, it will have the new name (provided it follows SQL naming conventions, naturally)


    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
    A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
    In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
    Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now