getting the Field names of Crosstab query in VB code (1 Viewer)

gdanalakshmi

Registered User.
Local time
Today, 19:48
Joined
Nov 26, 2002
Messages
102
I am trying to feed a crosstab's query outpout into a listbox.

But my column count will differ according to the query result since it is a crosstab query.

How do i find the column name of the crosstab query in VBA??


For Example if my crosstab result is like the following with 5 columns.

Name TotalOfHelpDesk Newchurn Voice StandardCancel

Then my listbox should display all the 5 columns.
Suppose my query output is 6 columns, then i should display the 6 columns, But how do I know the field name like Name, NewChurn,Voice, StandardCancel etc. Is there any function to get the fieldname?
 

gdanalakshmi

Registered User.
Local time
Today, 19:48
Joined
Nov 26, 2002
Messages
102
I found the way. Thought it will be useful to someone... here is the code to do that...

Set db = CurrentDb()

Set qrd = db.QueryDefs("testunion_Crosstab")

Set rstSource = qrd.OpenRecordset(dbOpenDynaset, _
dbSeeChanges, _
dbOptimistic)

With rstSource
' Change the columncount of the listbox dynamically
For ii = 0 To .Fields.Count - 1
fldNames(ii) = .Fields(ii).Name
Next ii
End With
 

Users who are viewing this thread

Top Bottom