P
Philippe Cand
Hello,
Excel 2003. With SQL Server 2000 I was able to create an oledb connection
and populate a spreadsheet (not a pivot table) from a cube using MDX.
In SQL 2005, I cannot seem to find the correct syntax. The MDX works fine
from SQL2005 query analyser but either I do not find the correct connection
string or I do not open the oledb connection the right way. I copy bellow an
example of what I try to do. I have searched here and there however I do not
find anything about this.
The code bellow does not return any error, it just soes not return any data.
Thanks to let me know where I can find information or how I could do that
with AS 2005.
Philippe.
Dim OlapMenu as String, Query as String,
OlapMenu = _
"Provider=MSOLAP;Integrated Security=SSPI;Persist Security
Info=False;Location=datamart.onsemi.com;Initial Catalog= ST_Crawl"
Query = "SELECT {} ON 0, [Customers].[Region].[Region].Members ON 1 FROM
[ST_Crawl]"
Call ado(OlapMenu, Query, "A3")
Private Sub ado(Connection As String, Query As String, destination As String)
Dim cnnConnect As ADODB.Connection
Dim rstRecordset As ADODB.Recordset
Set cnnConnect = New ADODB.Connection
cnnConnect.Open Connection
Set rstRecordset = New ADODB.Recordset
rstRecordset.Open _
Source:=Query, _
ActiveConnection:=cnnConnect, _
CursorType:=adOpenDynamic, _
LockType:=adLockReadOnly, _
Options:=adCmdText
With ActiveSheet.QueryTables.Add( _
Connection:=rstRecordset, _
destination:=Range(destination))
.FieldNames = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = False
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
cnnConnect.Close
Set cnnConnect = Nothing
Set rstRecordset = Nothing
End Sub
Excel 2003. With SQL Server 2000 I was able to create an oledb connection
and populate a spreadsheet (not a pivot table) from a cube using MDX.
In SQL 2005, I cannot seem to find the correct syntax. The MDX works fine
from SQL2005 query analyser but either I do not find the correct connection
string or I do not open the oledb connection the right way. I copy bellow an
example of what I try to do. I have searched here and there however I do not
find anything about this.
The code bellow does not return any error, it just soes not return any data.
Thanks to let me know where I can find information or how I could do that
with AS 2005.
Philippe.
Dim OlapMenu as String, Query as String,
OlapMenu = _
"Provider=MSOLAP;Integrated Security=SSPI;Persist Security
Info=False;Location=datamart.onsemi.com;Initial Catalog= ST_Crawl"
Query = "SELECT {} ON 0, [Customers].[Region].[Region].Members ON 1 FROM
[ST_Crawl]"
Call ado(OlapMenu, Query, "A3")
Private Sub ado(Connection As String, Query As String, destination As String)
Dim cnnConnect As ADODB.Connection
Dim rstRecordset As ADODB.Recordset
Set cnnConnect = New ADODB.Connection
cnnConnect.Open Connection
Set rstRecordset = New ADODB.Recordset
rstRecordset.Open _
Source:=Query, _
ActiveConnection:=cnnConnect, _
CursorType:=adOpenDynamic, _
LockType:=adLockReadOnly, _
Options:=adCmdText
With ActiveSheet.QueryTables.Add( _
Connection:=rstRecordset, _
destination:=Range(destination))
.FieldNames = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = False
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
cnnConnect.Close
Set cnnConnect = Nothing
Set rstRecordset = Nothing
End Sub