Solved

Function as Field Name in Access

Posted on 2003-10-22
9
155 Views
Last Modified: 2010-05-03
I have a query that I would like to put a function as a fieldname such as

select start_Date as Date() from table

The problem is access does not ssem to allow functions to replace field names. Is there a way of getting around this?
0
Comment
Question by:sesurb
  • 5
  • 4
9 Comments
 
LVL 5

Expert Comment

by:JCinDE
ID: 9600934
Okay I need clarification:

Do you want to have a field named 'start_Date' that contains today's date?

  select Date() as start_Date from table

Do you want to have a field named 'Date' that contains the value in start_date?

  select start_Date as [Date] from table

Do you want to have a field named 'Date()' that contains the value in start_date?

  select start_Date as [Date()] from table
0
 
LVL 5

Expert Comment

by:JCinDE
ID: 9600947
Above, I use [ and ] to enclose a field name that Access normally recognizes as a special keyword. The [ and ] force Access to treat it as a field name.
0
 
LVL 2

Author Comment

by:sesurb
ID: 9601127
The solution
select start_Date as [Date()] from table
is what I want but when I do this Access outputs the fiels as a string "date()" when I actually want it to be "10/22/2003" or whatever the current date is.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 5

Expert Comment

by:JCinDE
ID: 9601185
Okay so what you want is my first suggestion. A field named 'start_Date' containing the day's date:

  select Date() as start_Date from table

0
 
LVL 5

Expert Comment

by:JCinDE
ID: 9601241
What is in the field named 'start_Date'?

If what's in there is a string that you want to convert to a date, do this:

  select CDate(start_Date) as start_Date from table
0
 
LVL 2

Author Comment

by:sesurb
ID: 9601551
The field contains non-pertinent information. What is happening is that records are categorized by month and the data is already there but we need to change some column names to there corresponding month but that month changes depending on the data so if I can just get an actual dynamic date as the column header then I can manipulate to meet my needs but I am having trouble getting the date as the column header.
0
 
LVL 2

Author Comment

by:sesurb
ID: 9601561
And it is the last slection that I need not the first.

 select start_Date as [Date()] from table
0
 
LVL 5

Accepted Solution

by:
JCinDE earned 100 total points
ID: 9601830
oh, you want today's date as the column header?

Well you can try doing a crosstab query with MonthName(Month([start_Date]),False) as a Column Heading

But otherwise, I don't know of any way to dynamically change the column heading names within a query.
0
 
LVL 2

Author Comment

by:sesurb
ID: 9602236
I think the crosstab query might work or at least the basic concept of the crosstab query. I will let you know the outcome
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

770 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