[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Creating an Excel Piviot Table with a SQL Parameter Query

Posted on 2001-07-05
4
Medium Priority
?
190 Views
Last Modified: 2007-12-19

Hello!

I am trying to create an excel pivot table which gets launched inside a VB application.  I think there is two roads I can go by:

1. I can build an SQL statement in VB with some date fields that the user can select, then pass that sql to the excel pivot table.  OR

2. I can build a parameter sql statement inside the Excel pivot table and pass the parameters from the VB app.  

Either way would work fine for me, but I can't get either of these options to work.  I need help, my deadline is approaching.  Anyone have any ideas.  If so can you SPELL them out, I clueless on this one.

Thanks!
0
Comment
Question by:JayQue
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 6256835
1) sounds to me to be the easiest. Where is the source data coming from? Is it an excel sheet or some external data source such as SQL server or MS access?
0
 

Author Comment

by:JayQue
ID: 6256880

An sql statement would be built from VB, it would be hardcoded inside the app.
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 300 total points
ID: 6256940
Ok, here is a starter, this uses a SQL server table as the source.

    With ActiveWorkbook.PivotCaches.Add(SourceType:=xlExternal)
        .Connection = Array(Array( _
        "ODBC;DRIVER=SQL Server;SERVER=<MYSERVERNAME>;APP=<MYAPPLICATION>;WSID=<MYWSID>;DATABASE=<MYDATABASE>;QueryLogFile=Yes;QueryLogTime=Yes;StatsLo" _
        ), Array("g_On=2;Trusted_Connection=Yes"))
        .CommandType = xlCmdSql
        .CommandText = Array( _
        "SELECT EmployeeAbsences.EmployeeNumber, EmployeeAbsences.Year, EmployeeAbsences.Code" & Chr(13) & "" & Chr(10) & "FROM <MYDATABASE>" _
        , ".dbo.EmployeeAbsences EmployeeAbsences")
        .CreatePivotTable TableDestination:=Range("A3"), TableName:= _
        "MyPivotTable"
    End With
    ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:=Array( _
        "EmployeeNumber", "Year")
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Code").Orientation = _
        xlDataField

Replace the bits in <...> with something that fits your scenario. Then obviously amend the sql statement and the fields and you should have the beginnings of the pivot table.
0
 

Author Comment

by:JayQue
ID: 6276600

Thanks For All Your Help.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question