vba - Get Column name from a query table -


with normal tables, can access column name using

select column_name information_schema_columns table_name = '" & tbl & "' " 

and works...

but during execution of vba code need retrieve columns name not tables, table resulting after query, how can in vba?

dim qry querydef dim mrgtbls querydef dim t1 string dim t2 string dim sqljoin string 

...

set mrgtbls = currentdb.createquerydef(qry.name, sqljoin) 

... , later on want create query such as

select column_name information_schema_columns table_name = 'mrgt'  

which returns nothing since table mrgt not in information_schema_columns, unlike other tables.

to column names querydef, can use fields collection:

dim firstcolumnname string firstcolumnname = mrgtbls.fields(0).name 

alternatively can use pure sql , msysobjects , msysqueries system tables. see here details structure of table.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -