Cross tab query issue when i try to get the cross tab in excle using vba

lokeshsu

Board Regular
Joined
Mar 11, 2010
Messages
178
Hi All,
i have this cross tab query and it works fine in the access and i am trying to pull the data in the excel using the below vba code and i am getting an error message runtime error 3709. need help in fixing the issue
Code:
Sub ApplyCrossTab()
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim Myworkbook As String
Dim SQL As String
Dim i As Integer
'Set con = New Connection
'Set rs = New Recordset
'Identify the workbook you are referencing
    Myworkbook = Application.ThisWorkbook.FullName
'Open connection to the workbook
'Set con = New ADODB.Connection
con.ConnectionString = Connection
con.Provider = "Microsoft.ACE.OLEDB.12.0;"
con.Open "C:\lokesh bkp\Project\Forecasting\VzT.accdb"
'Build SQL Statement
    SQL = "TRANSFORM Sum(Query1.Val) AS SumOfVal " & _
          "SELECT Query1.Skill, Segment.RE " & _
          "FROM Query1 LEFT JOIN Segment ON Query1.Skill = Segment.Skill " & _
          "GROUP BY Query1.Skill, Segment.RE " & _
          "PIVOT Format([Date],""mmm-yy"");"
 MsgBox SQL
'Load the Query into a Recordset
    rs.Open SQL
'Place the Recordset onto Sheet2
    With ActiveWorkbook.Sheets("MTD Data").Range("A1")
    .CopyFromRecordset rs
    End With
'Place the Recordset onto Sheet2
   With Sheets("MTD Data")
    .Range("A1").CopyFromRecordset rs
    'Add column heading names
    For i = 1 To rs.Fields.Count
    .Cells(1, i).Value = rs.Fields(i - 1).Name
    Next i
   End With
End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,224,598
Messages
6,179,822
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top