using datapigs bacon bit i've found the following code (thanks by the way)
this is working great by it is there a way to import the result of a CROSSTAB qry instead of a select.
here is my query
i'm pretty lost on this one.
Thanks
Tuk
Code:
Sub RunParameterQuery()
'cn.Provider = "Microsoft OLE DB Provider for ODBC Drivers"
'Step 1: Declare your variables
Dim MyDatabase As DAO.Database
Dim MyQueryDef As DAO.QueryDef
Dim Myrecordset As DAO.Recordset
Dim i As Integer
'Step 2: Identify the database and query
Set MyDatabase = DBEngine.OpenDatabase _
("S:\Dept-Operational Analytics\BI\BI SECURE\DataWarehouse\Databases\IVR\IVR.accdb")
Set MyQueryDef = MyDatabase.QueryDefs("qry_HighLevel_Crosstab_Monthly")
'Step 3: Define the Parameters
With MyQueryDef
.Parameters("[Enter Source]") = Range("D3").Value
.Parameters("[Enter App]") = Range("D4").Value
End With
'Step 4: Open the query
Set Myrecordset = MyQueryDef.OpenRecordset
'Step 5: Clear previous contents
Sheets("Sheet2").Select
ActiveSheet.Range("A6:K10000").ClearContents
'Step 6: Copy the recordset to Excel
ActiveSheet.Range("A7").CopyFromRecordset Myrecordset
'Step 7: Add column heading names to the spreadsheet
For i = 1 To Myrecordset.Fields.Count
ActiveSheet.Cells(6, i).Value = Myrecordset.Fields(i - 1).Name
Next i
MsgBox "Your Query has been Run"
End Sub
this is working great by it is there a way to import the result of a CROSSTAB qry instead of a select.
here is my query
Code:
strSQL = "SELECT tbl_qry_IVR_Monthly_Summary.MonthYearMM, tbl_qry_IVR_Monthly_Summary.Source, tbl_qry_IVR_Monthly_Summary.[IVR App Name], IIf([CALL_END_REASON] Is Null,""zBlank"",[CALL_END_REASON]) AS Metric, Sum(tbl_qry_IVR_Monthly_Summary.SumOfCountOfDT2) AS SumOfSumOfCountOfDT2 " & vbCrLf & _
"FROM tbl_qry_IVR_Monthly_Summary " & vbCrLf & _
"WHERE (((tbl_qry_IVR_Monthly_Summary.Source)=[Enter Source] And (tbl_qry_IVR_Monthly_Summary.Source) Is Not Null) AND ((tbl_qry_IVR_Monthly_Summary.[IVR App Name])=[Enter App])) OR (((tbl_qry_IVR_Monthly_Summary.[IVR App Name])=[Enter App]) AND (([Enter Source]) Is Null)) OR (((tbl_qry_IVR_Monthly_Summary.Source)=[Enter Source]) AND (([Enter App]) Is Null)) OR ((([Enter Source]) Is Null) AND (([Enter App]) Is Null)) " & vbCrLf & _
"GROUP BY tbl_qry_IVR_Monthly_Summary.MonthYearMM, tbl_qry_IVR_Monthly_Summary.Source, tbl_qry_IVR_Monthly_Summary.[IVR App Name], IIf([CALL_END_REASON] Is Null,""zBlank"",[CALL_END_REASON]);"
i'm pretty lost on this one.
Thanks
Tuk