Solved

Function as Field Name in Access

Posted on 2003-10-22
9
153 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 5

Expert Comment

by:JCinDE
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 5

Expert Comment

by:JCinDE
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

728 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

14 Experts available now in Live!

Get 1:1 Help Now