dbTalk Databases Forums  

Using DAO to access the querydefs collection to document fields ina query def

comp.databases.ms-access comp.databases.ms-access


Discuss Using DAO to access the querydefs collection to document fields ina query def in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Bob Alston
 
Posts: n/a

Default Using DAO to access the querydefs collection to document fields ina query def - 02-02-2011 , 10:21 PM






I am trying to traverse the querydefs collection, to list every field in
the query. so far so good. However, some of my queries have calculated
fields and I would like to access the definition of the calculation
field but do not know how or where it is stored.

If fo example I define a new field in a query


CalEndDate: IIF(not isnull([Enddate]), [Enddate], #12/31/2999#)

I would like to be able to find this definition in the querydef and
include it in my report.

How do I go about this?

Examples?

Yes, I have spent hours reading, searching to no joy.

thanks

Bob

Reply With Quote
  #2  
Old   
Phil
 
Posts: n/a

Default Re: Using DAO to access the querydefs collection to document fields in a query def - 02-03-2011 , 03:18 AM






On 03/02/2011 04:21:12, Bob Alston wrote:
Quote:
I am trying to traverse the querydefs collection, to list every field in
the query. so far so good. However, some of my queries have calculated
fields and I would like to access the definition of the calculation
field but do not know how or where it is stored.

If fo example I define a new field in a query


CalEndDate: IIF(not isnull([Enddate]), [Enddate], #12/31/2999#)

I would like to be able to find this definition in the querydef and
include it in my report.

How do I go about this?

Examples?

Yes, I have spent hours reading, searching to no joy.

thanks

Bob

Have you had a look at the MySysQueries Table (normally hidden System
Object)? Phil

Reply With Quote
  #3  
Old   
Phil
 
Posts: n/a

Default Re: Using DAO to access the querydefs collection to document fields in a query def - 02-03-2011 , 10:06 AM



On 03/02/2011 09:18:08, "Phil" wrote:
Quote:
On 03/02/2011 04:21:12, Bob Alston wrote:
I am trying to traverse the querydefs collection, to list every field in
the query. so far so good. However, some of my queries have calculated
fields and I would like to access the definition of the calculation
field but do not know how or where it is stored.

If fo example I define a new field in a query


CalEndDate: IIF(not isnull([Enddate]), [Enddate], #12/31/2999#)

I would like to be able to find this definition in the querydef and
include it in my report.

How do I go about this?

Examples?

Yes, I have spent hours reading, searching to no joy.

thanks

Bob


Have you had a look at the MySysQueries Table (normally hidden System
Object)? Phil

This may get you started

SELECT MSysObjects.Name, MSysObjects.Type, MSysQueries.*
FROM MSysQueries INNER JOIN MSysObjects ON MSysQueries.ObjectId =
MSysObjects.Id WHERE (((MSysObjects.Name) Not Like "~*") AND
((MSysObjects.Type)=5) AND ((MSysQueries.Expression) Is Not Null));

Queries are type 5, so you don't want forms Type -32768, Reports Type -32764,
Modules type -32761, Tables Type 1 or 6 and other types
SQL statements for combo noxes, list boxes etc. start with a ~, so you may
not want these. Gather you're not interested in queries with no expressions,
so I have eliminated them

Phil

Reply With Quote
  #4  
Old   
James A. Fortune
 
Posts: n/a

Default Re: Using DAO to access the querydefs collection to document fieldsin a query def - 02-03-2011 , 02:35 PM



On Feb 2, 11:21*pm, Bob Alston <bobalst... (AT) yahoo (DOT) com> wrote:
Quote:
I am trying to traverse the querydefs collection, to list every field in
the query. *so far so good. *However, some of my queries have calculated
fields and I would like to access the definition of the calculation
field but do not know how or where it is stored.

If fo example I define a new field in a query

CalEndDate: *IIF(not isnull([Enddate]), [Enddate], #12/31/2999#)

I would like to be able to find this definition in the querydef and
include it in my report.

How do I go about this?

Examples?

Yes, I have spent hours reading, searching to no joy.

thanks

Bob
When parsing the SQL from the SQL property of the QueryDef, note that
the 'AS' keyword used to alias the field name can also be used to
alias table names. Before the 'AS' keyword you might go back to the
first comma or space unless square brackets (or the single quote
equivalents used by Lyle Fairfield) are encountered. Maybe see if the
parsed field name equates to a table to decide between field and table
aliases. Perhaps consider having your parsing cover the alternate
syntax used by Jamie Collins to reference tables in other databases.
What do you want your reporting to do if you have subqueries? It
seems there are possibly many proverbial flies in the ointment.

James A. Fortune
CDMAPoster (AT) FortuneJames (DOT) com

Reply With Quote
  #5  
Old   
Bob Alston
 
Posts: n/a

Default Re: Using DAO to access the querydefs collection to document fieldsin a query def - 02-03-2011 , 02:51 PM



On 2/3/2011 2:35 PM, James A. Fortune wrote:
Quote:
On Feb 2, 11:21 pm, Bob Alston<bobalst... (AT) yahoo (DOT) com> wrote:
I am trying to traverse the querydefs collection, to list every field in
the query. so far so good. However, some of my queries have calculated
fields and I would like to access the definition of the calculation
field but do not know how or where it is stored.

If fo example I define a new field in a query

CalEndDate: IIF(not isnull([Enddate]), [Enddate], #12/31/2999#)

I would like to be able to find this definition in the querydef and
include it in my report.

How do I go about this?

Examples?

Yes, I have spent hours reading, searching to no joy.

thanks

Bob

When parsing the SQL from the SQL property of the QueryDef, note that
the 'AS' keyword used to alias the field name can also be used to
alias table names. Before the 'AS' keyword you might go back to the
first comma or space unless square brackets (or the single quote
equivalents used by Lyle Fairfield) are encountered. Maybe see if the
parsed field name equates to a table to decide between field and table
aliases. Perhaps consider having your parsing cover the alternate
syntax used by Jamie Collins to reference tables in other databases.
What do you want your reporting to do if you have subqueries? It
seems there are possibly many proverbial flies in the ointment.

James A. Fortune
CDMAPoster (AT) FortuneJames (DOT) com
I was hoping to get the data that defines a calculated variable in the
query, from accessing the querydef via DAO and NOT trying to parse the
SQL syntax. I have already gotten several pieces of data from the
querydef. This is just one piece I can't seem to get.

Bob

Reply With Quote
  #6  
Old   
James A. Fortune
 
Posts: n/a

Default Re: Using DAO to access the querydefs collection to document fieldsin a query def - 02-07-2011 , 12:51 PM



On Feb 3, 3:51*pm, Bob Alston <bobalst... (AT) yahoo (DOT) com> wrote:
Quote:
On 2/3/2011 2:35 PM, James A. Fortune wrote:

On Feb 2, 11:21 pm, Bob Alston<bobalst... (AT) yahoo (DOT) com> *wrote:
I am trying to traverse the querydefs collection, to list every field in
the query. *so far so good. *However, some of my queries have calculated
fields and I would like to access the definition of the calculation
field but do not know how or where it is stored.

If fo example I define a new field in a query

CalEndDate: *IIF(not isnull([Enddate]), [Enddate], #12/31/2999#)

I would like to be able to find this definition in the querydef and
include it in my report.

How do I go about this?

Examples?

Yes, I have spent hours reading, searching to no joy.

thanks

Bob

When parsing the SQL from the SQL property of the QueryDef, note that
the 'AS' keyword used to alias the field name can also be used to
alias table names. *Before the 'AS' keyword you might go back to the
first comma or space unless square brackets (or the single quote
equivalents used by Lyle Fairfield) are encountered. *Maybe see if the
parsed field name equates to a table to decide between field and table
aliases. *Perhaps consider having your parsing cover the alternate
syntax used by Jamie Collins to reference tables in other databases.
What do you want your reporting to do if you have subqueries? *It
seems there are possibly many proverbial flies in the ointment.

James A. Fortune
CDMAPos... (AT) FortuneJames (DOT) com

I was hoping to get the data that defines a calculated variable in the
query, from accessing the querydef via DAO and NOT trying to parse the
SQL syntax. *I have already gotten several pieces of data from the
querydef. *This is just one piece I can't seem to get.

Bob
Bob,

It might be possible to get an answer by accessing the querydef
collection itself, but a way to do that eludes me presently. Let us
know if you happen upon a solution. Do you also identify query
parameter fields?

James A. Fortune
CDMAPoster (AT) FortuneJames (DOT) com

Reply With Quote
  #7  
Old   
BobAlston
 
Posts: n/a

Default Re: Using DAO to access the querydefs collection to document fieldsin a query def - 03-18-2011 , 01:17 PM



On 2/3/2011 2:51 PM, Bob Alston wrote:
Quote:
On 2/3/2011 2:35 PM, James A. Fortune wrote:
On Feb 2, 11:21 pm, Bob Alston<bobalst... (AT) yahoo (DOT) com> wrote:
I am trying to traverse the querydefs collection, to list every field in
the query. so far so good. However, some of my queries have calculated
fields and I would like to access the definition of the calculation
field but do not know how or where it is stored.

If fo example I define a new field in a query

CalEndDate: IIF(not isnull([Enddate]), [Enddate], #12/31/2999#)

I would like to be able to find this definition in the querydef and
include it in my report.

How do I go about this?

Examples?

Yes, I have spent hours reading, searching to no joy.

thanks

Bob

When parsing the SQL from the SQL property of the QueryDef, note that
the 'AS' keyword used to alias the field name can also be used to
alias table names. Before the 'AS' keyword you might go back to the
first comma or space unless square brackets (or the single quote
equivalents used by Lyle Fairfield) are encountered. Maybe see if the
parsed field name equates to a table to decide between field and table
aliases. Perhaps consider having your parsing cover the alternate
syntax used by Jamie Collins to reference tables in other databases.
What do you want your reporting to do if you have subqueries? It
seems there are possibly many proverbial flies in the ointment.

James A. Fortune
CDMAPoster (AT) FortuneJames (DOT) com
I was hoping to get the data that defines a calculated variable in the
query, from accessing the querydef via DAO and NOT trying to parse the
SQL syntax. I have already gotten several pieces of data from the
querydef. This is just one piece I can't seem to get.

Bob
I was able to do so via Msysqueries and Msysobjects.

I Started with a table of queries and their fields, which I obtained
from DAO code and the queries object.

I then ran a query to link to Msys objects matching the queryname to
Name in Msysobjects. I saved the data from my original table and the
ID field from Msysobjects. I saved that query.

I then used the query saved above in a new query that matched the field
name from my original table to Name1 in Msysqueries and matched the ID
number from the first query to the ID number in Msysqueries.

Bob

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.