By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,705 Members | 1,845 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,705 IT Pros & Developers. It's quick & easy.

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

100+
P: 176
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
Share this Question
Share on Google+
1 Reply


ADezii
Expert 5K+
P: 8,619
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

Post your reply

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