Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Pivot Table from MS Access Database

Hello -
This is probably an SQL question. I would like to make the code below (from
J-Walch book) more useful for my needs. The code creates a pivot table by
querying an access database. The change I would like to implement is that I
do not want the whole content of the table brought into excel, but just
selected data belonging to a specific field identified by a variable. This
can be accomplished by changing the * in the code below to a variable (for
instance the value of sheet(2).Range("A1")) How can I do that?

Below is the code. Where you find the * is where I would like to enter the
variable.

Thank you!

Sub CreatePivotTableFromDB()
Dim PTCache As PivotCache
Dim PT As PivotTable

On Error Resume Next
Application.DisplayAlerts = False
Sheets("PivotSheet").Delete
On Error GoTo 0

Set PTCache = ActiveWorkbook.PivotCaches.Add _
(SourceType:=xlExternal)


DBFile = ThisWorkbook.Path & "\Mydata.mdb"


ConString = "ODBC;DSN=MS Access Database;DBQ=" & DBFile


QueryString = "SELECT * FROM `" & ThisWorkbook.Path & _
"\MYDATA`.MyTable MyTable"


With PTCache
.Connection = ConString
.CommandText = QueryString
End With


Worksheets.Add
ActiveSheet.Name = "PivotSheet"


Set PT = PTCache.CreatePivotTable( _
TableDestination:=Sheets("PivotSheet").Range("A1") , _
TableName:="Payroll for Kreg Project")


With PT

.PivotFields("Dst Acct Unit").Orientation = xlRowField
.PivotFields("Distribution Amount").Orientation = xlDataField

End With
End Sub




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 698
Default Pivot Table from MS Access Database

Try this:

QueryString = "SELECT * " _
& "FROM `" & ThisWorkbook.Path & "\MYDATA`.MyTable MyTable " _
& "WHERE MyTable.MyField = " & Sheet(2).Range("A1").Value

Is that something you can work with?
***********
Regards,
Ron

XL2002, WinXP


"Filo" wrote:

Hello -
This is probably an SQL question. I would like to make the code below (from
J-Walch book) more useful for my needs. The code creates a pivot table by
querying an access database. The change I would like to implement is that I
do not want the whole content of the table brought into excel, but just
selected data belonging to a specific field identified by a variable. This
can be accomplished by changing the * in the code below to a variable (for
instance the value of sheet(2).Range("A1")) How can I do that?

Below is the code. Where you find the * is where I would like to enter the
variable.

Thank you!

Sub CreatePivotTableFromDB()
Dim PTCache As PivotCache
Dim PT As PivotTable

On Error Resume Next
Application.DisplayAlerts = False
Sheets("PivotSheet").Delete
On Error GoTo 0

Set PTCache = ActiveWorkbook.PivotCaches.Add _
(SourceType:=xlExternal)


DBFile = ThisWorkbook.Path & "\Mydata.mdb"


ConString = "ODBC;DSN=MS Access Database;DBQ=" & DBFile


QueryString = "SELECT * FROM `" & ThisWorkbook.Path & _
"\MYDATA`.MyTable MyTable"


With PTCache
.Connection = ConString
.CommandText = QueryString
End With


Worksheets.Add
ActiveSheet.Name = "PivotSheet"


Set PT = PTCache.CreatePivotTable( _
TableDestination:=Sheets("PivotSheet").Range("A1") , _
TableName:="Payroll for Kreg Project")


With PT

.PivotFields("Dst Acct Unit").Orientation = xlRowField
.PivotFields("Distribution Amount").Orientation = xlDataField

End With
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Pivot Table from MS Access Database

Awesome. Thank you!

"Ron Coderre" wrote:

Try this:

QueryString = "SELECT * " _
& "FROM `" & ThisWorkbook.Path & "\MYDATA`.MyTable MyTable " _
& "WHERE MyTable.MyField = " & Sheet(2).Range("A1").Value

Is that something you can work with?
***********
Regards,
Ron

XL2002, WinXP


"Filo" wrote:

Hello -
This is probably an SQL question. I would like to make the code below (from
J-Walch book) more useful for my needs. The code creates a pivot table by
querying an access database. The change I would like to implement is that I
do not want the whole content of the table brought into excel, but just
selected data belonging to a specific field identified by a variable. This
can be accomplished by changing the * in the code below to a variable (for
instance the value of sheet(2).Range("A1")) How can I do that?

Below is the code. Where you find the * is where I would like to enter the
variable.

Thank you!

Sub CreatePivotTableFromDB()
Dim PTCache As PivotCache
Dim PT As PivotTable

On Error Resume Next
Application.DisplayAlerts = False
Sheets("PivotSheet").Delete
On Error GoTo 0

Set PTCache = ActiveWorkbook.PivotCaches.Add _
(SourceType:=xlExternal)


DBFile = ThisWorkbook.Path & "\Mydata.mdb"


ConString = "ODBC;DSN=MS Access Database;DBQ=" & DBFile


QueryString = "SELECT * FROM `" & ThisWorkbook.Path & _
"\MYDATA`.MyTable MyTable"


With PTCache
.Connection = ConString
.CommandText = QueryString
End With


Worksheets.Add
ActiveSheet.Name = "PivotSheet"


Set PT = PTCache.CreatePivotTable( _
TableDestination:=Sheets("PivotSheet").Range("A1") , _
TableName:="Payroll for Kreg Project")


With PT

.PivotFields("Dst Acct Unit").Orientation = xlRowField
.PivotFields("Distribution Amount").Orientation = xlDataField

End With
End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 698
Default Pivot Table from MS Access Database

You're very welcome....I'm glad I could help.


***********
Regards,
Ron

XL2002, WinXP


"Filo" wrote:

Awesome. Thank you!

"Ron Coderre" wrote:

Try this:

QueryString = "SELECT * " _
& "FROM `" & ThisWorkbook.Path & "\MYDATA`.MyTable MyTable " _
& "WHERE MyTable.MyField = " & Sheet(2).Range("A1").Value

Is that something you can work with?
***********
Regards,
Ron

XL2002, WinXP


"Filo" wrote:

Hello -
This is probably an SQL question. I would like to make the code below (from
J-Walch book) more useful for my needs. The code creates a pivot table by
querying an access database. The change I would like to implement is that I
do not want the whole content of the table brought into excel, but just
selected data belonging to a specific field identified by a variable. This
can be accomplished by changing the * in the code below to a variable (for
instance the value of sheet(2).Range("A1")) How can I do that?

Below is the code. Where you find the * is where I would like to enter the
variable.

Thank you!

Sub CreatePivotTableFromDB()
Dim PTCache As PivotCache
Dim PT As PivotTable

On Error Resume Next
Application.DisplayAlerts = False
Sheets("PivotSheet").Delete
On Error GoTo 0

Set PTCache = ActiveWorkbook.PivotCaches.Add _
(SourceType:=xlExternal)


DBFile = ThisWorkbook.Path & "\Mydata.mdb"


ConString = "ODBC;DSN=MS Access Database;DBQ=" & DBFile


QueryString = "SELECT * FROM `" & ThisWorkbook.Path & _
"\MYDATA`.MyTable MyTable"


With PTCache
.Connection = ConString
.CommandText = QueryString
End With


Worksheets.Add
ActiveSheet.Name = "PivotSheet"


Set PT = PTCache.CreatePivotTable( _
TableDestination:=Sheets("PivotSheet").Range("A1") , _
TableName:="Payroll for Kreg Project")


With PT

.PivotFields("Dst Acct Unit").Orientation = xlRowField
.PivotFields("Distribution Amount").Orientation = xlDataField

End With
End Sub




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Limit using pivot table with Access database? peb Excel Discussion (Misc queries) 1 July 14th 09 10:12 PM
Excel Pivot Table connected to an Access Database Data Source Alex Zimmerhaven Excel Discussion (Misc queries) 2 June 10th 08 03:04 AM
Creating pivot table from Access database Cam Excel Discussion (Misc queries) 1 March 19th 08 06:28 PM
Create Pivot from access database by VBA ST Excel Discussion (Misc queries) 0 July 26th 06 04:31 AM
Pivot Table against an Access Database Richard Excel Discussion (Misc queries) 1 February 27th 05 03:42 AM


All times are GMT +1. The time now is 02:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"