PC Review


Reply
Thread Tools Rate Thread

Create a pivottable from a recordset?

 
 
Rubble
Guest
Posts: n/a
 
      3rd Oct 2008
Hi --

I am trying to create a pivot table from a dynamic query - so I create the
query in VBA and then want to create a pivot table with that query. What I
am trying to do is to first create the pivotcache. I am pretty lost on this
one - I can create a cache with Excel data, but am having a hard time
creating it from a recordset.

Any ideas?

Thank you -

 
Reply With Quote
 
 
 
 
Héctor Miguel
Guest
Posts: n/a
 
      4th Oct 2008
hi, !

> I am trying to create a pivot table from a dynamic query
> - so I create the query in VBA and then want to create a pivot table with that query.
> What I am trying to do is to first create the pivotcache.
> I am pretty lost on this one
> - I can create a cache with Excel data, but am having a hard time creating it from a recordset.
> Any ideas?


- set and open your connection-object
- set your recordset-object
- build the query-string
- open the recordset-object with your connection and query-string
- set / add your pivot-cache (sourcetype should be external)
- set your pivot-cache recordset as your opened recordset-object
- set your pivot-table (pivot-cache and destination)
- add (according your needs) the pivot-fields (rowfields, pagefields, pivotfields, ...)
- arrange the orientation (datafields, columnfields, ...), position, function, number format, etc..
- close your objects (recordset and connection)
- it's done !

hard to provide an "useful" example wothout your "real source data/needs/query/..." -???-

hth,
hector.


 
Reply With Quote
 
Rubble
Guest
Posts: n/a
 
      4th Oct 2008
Thank you for the response . . .

I was able to get to the point where I need to set my pivot-table - I think
there is something wrong with my destination -- this is from setting the
cache, loading the cache and setting my pivot . . .

Set jCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlExternal)
Set jCache.Recordset = jRecordset
Set jPivot = jCache.CreatePivotTable(tabledestination:=jSheet.Cells(2,
2), tablename:="AssetRoll")

I know there is something wrong with when I set the pivot-table becaues it
left the tabledestination w/o the caps. jPivot is defined as a pivottable,
jCache is defined as a pivotcache.

Is there something simple I am missing?

Thank you . . .

"Héctor Miguel" wrote:

> hi, !
>
> > I am trying to create a pivot table from a dynamic query
> > - so I create the query in VBA and then want to create a pivot table with that query.
> > What I am trying to do is to first create the pivotcache.
> > I am pretty lost on this one
> > - I can create a cache with Excel data, but am having a hard time creating it from a recordset.
> > Any ideas?

>
> - set and open your connection-object
> - set your recordset-object
> - build the query-string
> - open the recordset-object with your connection and query-string
> - set / add your pivot-cache (sourcetype should be external)
> - set your pivot-cache recordset as your opened recordset-object
> - set your pivot-table (pivot-cache and destination)
> - add (according your needs) the pivot-fields (rowfields, pagefields, pivotfields, ...)
> - arrange the orientation (datafields, columnfields, ...), position, function, number format, etc..
> - close your objects (recordset and connection)
> - it's done !
>
> hard to provide an "useful" example wothout your "real source data/needs/query/..." -???-
>
> hth,
> hector.
>
>
>

 
Reply With Quote
 
Héctor Miguel
Guest
Posts: n/a
 
      4th Oct 2008
hi, !

your code is working just fine (for me), the only "pending actions" (if your code ends like this one)
is finish the pivot-table layout (it means, place each fields where it belongs to) so,
if you do not finish by code, you will have to (or let the user) finish in the GUI

- activate the pivot-table (select any cell within your PT area)
(be sure the PT toolbar shows-up and there will be available all of your button/fields)
- place each button/field where it is needed (which one/s as rowfields, datafields, columnfields, pagefields)
- change (if necessary) the function (count, sum, other...), numberformat, ... for the datafields

if any doubts (or further information)... would you please comment ?
hth,
hector.

__ OP __
> I was able to get to the point where I need to set my pivot-table
> - I think there is something wrong with my destination
> - this is from setting the cache, loading the cache and setting my pivot . . .
>
> Set jCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlExternal)
> Set jCache.Recordset = jRecordset
> Set jPivot = jCache.CreatePivotTable(tabledestination:=jSheet.Cells(2, 2), tablename:="AssetRoll")
>
> I know there is something wrong with when I set the pivot-table becaues it left the tabledestination w/o the caps.
> jPivot is defined as a pivottable, jCache is defined as a pivotcache.
>
> Is there something simple I am missing?


__ previous __
>>> I am trying to create a pivot table from a dynamic query
>>> - so I create the query in VBA and then want to create a pivot table with that query.
>>> What I am trying to do is to first create the pivotcache.
>>> I am pretty lost on this one
>>> - I can create a cache with Excel data, but am having a hard time creating it from a recordset.
>>> Any ideas?

>>
>> - set and open your connection-object
>> - set your recordset-object
>> - build the query-string
>> - open the recordset-object with your connection and query-string
>> - set / add your pivot-cache (sourcetype should be external)
>> - set your pivot-cache recordset as your opened recordset-object
>> - set your pivot-table (pivot-cache and destination)
>> - add (according your needs) the pivot-fields (rowfields, pagefields, pivotfields, ...)
>> - arrange the orientation (datafields, columnfields, ...), position, function, number format, etc..
>> - close your objects (recordset and connection)
>> - it's done !
>>
>> hard to provide an "useful" example wothout your "real source data/needs/query/..." -???-



 
Reply With Quote
 
Rubble
Guest
Posts: n/a
 
      4th Oct 2008
Thank you again for your response. My code actually stops at the set pivot
line - do I need to pick up some references to run those commands? Or is
this because I am on Vista or 2007?

Thanks again --

Jim

"Héctor Miguel" wrote:

> hi, !
>
> your code is working just fine (for me), the only "pending actions" (if your code ends like this one)
> is finish the pivot-table layout (it means, place each fields where it belongs to) so,
> if you do not finish by code, you will have to (or let the user) finish in the GUI
>
> - activate the pivot-table (select any cell within your PT area)
> (be sure the PT toolbar shows-up and there will be available all of your button/fields)
> - place each button/field where it is needed (which one/s as rowfields, datafields, columnfields, pagefields)
> - change (if necessary) the function (count, sum, other...), numberformat, ... for the datafields
>
> if any doubts (or further information)... would you please comment ?
> hth,
> hector.
>
> __ OP __
> > I was able to get to the point where I need to set my pivot-table
> > - I think there is something wrong with my destination
> > - this is from setting the cache, loading the cache and setting my pivot . . .
> >
> > Set jCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlExternal)
> > Set jCache.Recordset = jRecordset
> > Set jPivot = jCache.CreatePivotTable(tabledestination:=jSheet.Cells(2, 2), tablename:="AssetRoll")
> >
> > I know there is something wrong with when I set the pivot-table becaues it left the tabledestination w/o the caps.
> > jPivot is defined as a pivottable, jCache is defined as a pivotcache.
> >
> > Is there something simple I am missing?

>
> __ previous __
> >>> I am trying to create a pivot table from a dynamic query
> >>> - so I create the query in VBA and then want to create a pivot table with that query.
> >>> What I am trying to do is to first create the pivotcache.
> >>> I am pretty lost on this one
> >>> - I can create a cache with Excel data, but am having a hard time creating it from a recordset.
> >>> Any ideas?
> >>
> >> - set and open your connection-object
> >> - set your recordset-object
> >> - build the query-string
> >> - open the recordset-object with your connection and query-string
> >> - set / add your pivot-cache (sourcetype should be external)
> >> - set your pivot-cache recordset as your opened recordset-object
> >> - set your pivot-table (pivot-cache and destination)
> >> - add (according your needs) the pivot-fields (rowfields, pagefields, pivotfields, ...)
> >> - arrange the orientation (datafields, columnfields, ...), position, function, number format, etc..
> >> - close your objects (recordset and connection)
> >> - it's done !
> >>
> >> hard to provide an "useful" example wothout your "real source data/needs/query/..." -???-

>
>
>

 
Reply With Quote
 
Héctor Miguel
Guest
Posts: n/a
 
      4th Oct 2008
hi, Jim !

> ... My code actually stops at the set pivot line
> - do I need to pick up some references to run those commands?
> Or is this because I am on Vista or 2007?


I have no win-vista, but testing on xl-2007 stil works (for me) ending on set pivot table line -?-
(no additional references, other than required for the connection/recordset objects)

after that, I "have to" finish the PT layout on the GUI (as previoulsy stated):

- activate the pivot-table (select any cell within your PT area)
- be sure the PT toolbar (pane in xl2007) shows-up and there will be available all of your button/fields
- place each button/field where it is needed (which one/s as rowfields, datafields, columnfields, pagefields)
- change (if necessary) the function (count, sum, other...), numberformat, ... for the datafields

hth,
hector.

__ previous __
>> your code is working just fine (for me), the only "pending actions" (if your code ends like this one)
>> is finish the pivot-table layout (it means, place each fields where it belongs to) so,
>> if you do not finish by code, you will have to (or let the user) finish in the GUI
>>
>> - activate the pivot-table (select any cell within your PT area)
>> (be sure the PT toolbar shows-up and there will be available all of your button/fields)
>> - place each button/field where it is needed (which one/s as rowfields, datafields, columnfields, pagefields)
>> - change (if necessary) the function (count, sum, other...), numberformat, ... for the datafields
>>
>> if any doubts (or further information)... would you please comment ?
>> hth,
>> hector.
>>
>> __ OP __
>>> I was able to get to the point where I need to set my pivot-table
>>> - I think there is something wrong with my destination
>>> - this is from setting the cache, loading the cache and setting my pivot . . .
>>>
>>> Set jCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlExternal)
>>> Set jCache.Recordset = jRecordset
>>> Set jPivot = jCache.CreatePivotTable(tabledestination:=jSheet.Cells(2, 2), tablename:="AssetRoll")
>>>
>>> I know there is something wrong with when I set the pivot-table becaues it left the tabledestination w/o the caps.
>>> jPivot is defined as a pivottable, jCache is defined as a pivotcache.
>>>
>>> Is there something simple I am missing?

>>
>> __ previous __
>>>>> I am trying to create a pivot table from a dynamic query
>>>>> - so I create the query in VBA and then want to create a pivot table with that query.
>>>>> What I am trying to do is to first create the pivotcache.
>>>>> I am pretty lost on this one
>>>>> - I can create a cache with Excel data, but am having a hard time creating it from a recordset.
>>>>> Any ideas?
>>>>
>>>> - set and open your connection-object
>>>> - set your recordset-object
>> >> - build the query-string
>>>> - open the recordset-object with your connection and query-string
>>>> - set / add your pivot-cache (sourcetype should be external)
>>>> - set your pivot-cache recordset as your opened recordset-object
>>>> - set your pivot-table (pivot-cache and destination)
>>>> - add (according your needs) the pivot-fields (rowfields, pagefields, pivotfields, ...)
>>>> - arrange the orientation (datafields, columnfields, ...), position, function, number format, etc..
>>>> - close your objects (recordset and connection)
>>>> - it's done !
>>>>
>>>> hard to provide an "useful" example wothout your "real source data/needs/query/..." -???-



 
Reply With Quote
 
Rubble
Guest
Posts: n/a
 
      7th Oct 2008
Thank you -- I appreciate the help.

"Héctor Miguel" wrote:

> hi, Jim !
>
> > ... My code actually stops at the set pivot line
> > - do I need to pick up some references to run those commands?
> > Or is this because I am on Vista or 2007?

>
> I have no win-vista, but testing on xl-2007 stil works (for me) ending on set pivot table line -?-
> (no additional references, other than required for the connection/recordset objects)
>
> after that, I "have to" finish the PT layout on the GUI (as previoulsy stated):
>
> - activate the pivot-table (select any cell within your PT area)
> - be sure the PT toolbar (pane in xl2007) shows-up and there will be available all of your button/fields
> - place each button/field where it is needed (which one/s as rowfields, datafields, columnfields, pagefields)
> - change (if necessary) the function (count, sum, other...), numberformat, ... for the datafields
>
> hth,
> hector.
>
> __ previous __
> >> your code is working just fine (for me), the only "pending actions" (if your code ends like this one)
> >> is finish the pivot-table layout (it means, place each fields where it belongs to) so,
> >> if you do not finish by code, you will have to (or let the user) finish in the GUI
> >>
> >> - activate the pivot-table (select any cell within your PT area)
> >> (be sure the PT toolbar shows-up and there will be available all of your button/fields)
> >> - place each button/field where it is needed (which one/s as rowfields, datafields, columnfields, pagefields)
> >> - change (if necessary) the function (count, sum, other...), numberformat, ... for the datafields
> >>
> >> if any doubts (or further information)... would you please comment ?
> >> hth,
> >> hector.
> >>
> >> __ OP __
> >>> I was able to get to the point where I need to set my pivot-table
> >>> - I think there is something wrong with my destination
> >>> - this is from setting the cache, loading the cache and setting my pivot . . .
> >>>
> >>> Set jCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlExternal)
> >>> Set jCache.Recordset = jRecordset
> >>> Set jPivot = jCache.CreatePivotTable(tabledestination:=jSheet.Cells(2, 2), tablename:="AssetRoll")
> >>>
> >>> I know there is something wrong with when I set the pivot-table becaues it left the tabledestination w/o the caps.
> >>> jPivot is defined as a pivottable, jCache is defined as a pivotcache.
> >>>
> >>> Is there something simple I am missing?
> >>
> >> __ previous __
> >>>>> I am trying to create a pivot table from a dynamic query
> >>>>> - so I create the query in VBA and then want to create a pivot table with that query.
> >>>>> What I am trying to do is to first create the pivotcache.
> >>>>> I am pretty lost on this one
> >>>>> - I can create a cache with Excel data, but am having a hard time creating it from a recordset.
> >>>>> Any ideas?
> >>>>
> >>>> - set and open your connection-object
> >>>> - set your recordset-object
> >> >> - build the query-string
> >>>> - open the recordset-object with your connection and query-string
> >>>> - set / add your pivot-cache (sourcetype should be external)
> >>>> - set your pivot-cache recordset as your opened recordset-object
> >>>> - set your pivot-table (pivot-cache and destination)
> >>>> - add (according your needs) the pivot-fields (rowfields, pagefields, pivotfields, ...)
> >>>> - arrange the orientation (datafields, columnfields, ...), position, function, number format, etc..
> >>>> - close your objects (recordset and connection)
> >>>> - it's done !
> >>>>
> >>>> hard to provide an "useful" example wothout your "real source data/needs/query/..." -???-

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem creating PivotTable from ADO recordset using VBA WharfRat5ddf18 Microsoft Excel Programming 0 18th Apr 2008 06:43 PM
PivotTable from a ADODB.Recordset ? mark Microsoft Excel Programming 7 6th Dec 2007 06:08 PM
Create a Pivottable in a macro =?Utf-8?B?TWljaGFlbA==?= Microsoft Excel Misc 8 15th Mar 2007 02:41 PM
Could create a new recordset based an exist recordset via SQL directly Jason Jiang Microsoft Access 13 21st Apr 2006 03:25 AM
How to create a Pivottable from Textfile =?Utf-8?B?RnJhbmsgTQ==?= Microsoft Excel Programming 0 23rd Sep 2005 11:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:31 AM.