CrossTab Query

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joe-Paul

    CrossTab Query

    Hi:

    I'm using a "CrossTab" Query to retrieve data. When I get it back, I want
    to print the column Headers along the first row of the grid. How to I get
    the names of the column Headers? The names of the columns will be dynamic;
    i.e., I am listing facilities and getting total transports provided for each
    facility. I am returning the Name of the Facility (or it's designator) as
    Column headers and want that in the first row...with the totals in the
    second row. Is there a way to use visual basic and get the names of the
    columns in the Crosstab...and then put each one in a field in the first row?

    Your advice would be appreicated.

    JP



  • Steve Gerrard

    #2
    Re: CrossTab Query


    "Joe-Paul" <HarvestWind@co mcast.net> wrote in message
    news:SYqdnbahdv oR2N3ZnZ2dnUVZ_ umdnZ2d@comcast .com...[color=blue]
    > Hi:
    >
    > I'm using a "CrossTab" Query to retrieve data. When I get it back, I want
    > to print the column Headers along the first row of the grid. How to I get
    > the names of the column Headers?[/color]

    Any recordset, regardless of what sort of query you use to get it, will include
    a Fields collection.
    So something like this will get you the information you need:

    Dim oRS As Recordset
    Dim oFld As Field

    ' get data into oRS...

    ' The number of columns is.oRS.Fields.C ount.
    Debug.Print "columns needed: " & oRS.Fields.Coun t

    For Each oFld In oRS.Fields
    ' do something here with each field name
    Debug.Print oFld.Name
    Next oFld

    Now you can play with setting up the grid and labelling the column headers...


    Comment

    • Joe-Paul

      #3
      Re: CrossTab Query

      Great, Steve... Thanks a million.

      JP
      "Steve Gerrard" <mynamehere@com cast.net> wrote in message
      news:I5ednY9o0p yvh9zZRVn-rQ@comcast.com. ..[color=blue]
      >
      > "Joe-Paul" <HarvestWind@co mcast.net> wrote in message
      > news:SYqdnbahdv oR2N3ZnZ2dnUVZ_ umdnZ2d@comcast .com...[color=green]
      >> Hi:
      >>
      >> I'm using a "CrossTab" Query to retrieve data. When I get it back, I
      >> want
      >> to print the column Headers along the first row of the grid. How to I
      >> get
      >> the names of the column Headers?[/color]
      >
      > Any recordset, regardless of what sort of query you use to get it, will
      > include a Fields collection.
      > So something like this will get you the information you need:
      >
      > Dim oRS As Recordset
      > Dim oFld As Field
      >
      > ' get data into oRS...
      >
      > ' The number of columns is.oRS.Fields.C ount.
      > Debug.Print "columns needed: " & oRS.Fields.Coun t
      >
      > For Each oFld In oRS.Fields
      > ' do something here with each field name
      > Debug.Print oFld.Name
      > Next oFld
      >
      > Now you can play with setting up the grid and labelling the column
      > headers...
      >
      >[/color]


      Comment

      Working...