[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 460
  • Last Modified:

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

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,
0
doyle007
Asked:
doyle007
1 Solution
 
harfangCommented:
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)

Cheers!
(°v°)
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Tackle projects and never again get stuck behind a technical roadblock.
Join Now