473,387 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Is it possible to generate the alias name for a row in query from function?

176 100+
Hi all.

I need to create a query so that the one of the row name aliases will be generated from a function (for graph purposes). Is there a way to do it?

Thanks.
Dec 26 '07 #1
1 1244
ADezii
8,834 Expert 8TB
Hi all.

I need to create a query so that the one of the row name aliases will be generated from a function (for graph purposes). Is there a way to do it?

Thanks.
Yes there is:
  1. Create a Public Function that will return a String value, this value will be the Alias for a specific Field(s). In the demo, I created a Function named fGenerateAlias() which will return a String value that will be the Name of the first Table in your Database. This Table Name will be the Alias for a [LastName] Field in an Employees Table. Here is the simple Function below:
    Expand|Select|Wrap|Line Numbers
    1. Public Function fGenerateAlias() As String
    2.   fGenerateAlias = CurrentDb.TableDefs(0).Name
    3. End Function
  2. The following code below will create a Query named qryTestAlias. The Query will return only the First and Last Name Fields from the Employees Table. The [LastName] Field will be Aliased with the Name of the first Table in your Database.
    Expand|Select|Wrap|Line Numbers
    1. On Error Resume Next
    2. Dim qdfTest As DAO.QueryDef, strSQL As String
    3.  
    4. CurrentDb.QueryDefs.Delete "qryTestAlias"
    5.  
    6. strSQL = "Select [FirstName], [LastName] As '" & fGenerateAlias() & "' From Employees;"
    7.  
    8. Set qdfTest = CurrentDb.CreateQueryDef("qryTestAlias", strSQL)
  3. Any other questions, please do not hesitate to ask.
Dec 27 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Andrew | last post by:
With command-line interface ( 3.23.37, UNIX Socket ) all is well with column aliasing. However, column aliases disappear in Excel, over ODBC, when there are multiple (joined) tables in the query. ...
12
by: M Wells | last post by:
Hi All, I have a table that holds pregenerated member IDs. This table is used to assign an available member id to web site visitors who choose to register with the site So, conceptually the...
5
by: malcolm | last post by:
Example, suppose you have these 2 tables (NOTE: My example is totally different, but I'm simply trying to setup the a simpler version, so excuse the bad design; not the point here) CarsSold {...
14
by: John | last post by:
Hi all, I am doing the change from having worked in Oracle for a long time to MS SQL server and am frustrated with a couple of simple SQL stmt's. Or at least they have always been easy. The...
5
by: Chris Ochs | last post by:
It doesn't currently seem possible to switch between different users using SET SESSION AUTHORIZATION. If I log in as the superuser and switch to another user that works, but if I then switch to a...
3
by: Rodríguez Rodríguez, Pere | last post by:
Hello, I think I have found a query problem when the query has an alias for a table and use alias item and table name. I ilustrate the problem with a simple table and query. prr=# create...
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
2
by: Woodies_46 | last post by:
Can someone tell me if this is close and if it can be done IF ctl.control Source in CurrentDb.Querydefs("Maps and Plans Query") then Wherestr = Wherestr & "(((" & "." & ")" & "=" & "" " &...
6
by: Parasyke | last post by:
Thanks in advance! I have an un-secured database that I can see which computer name is logged-on but not the user. I have an error module that can get the user name. It writes to an error file. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.