What exactly do you mean by 'execute' in this context, Leo? Generally
speaking, in code, one executes an action query, and opens a recordset on a
select query. A cross-tab query is a form of select query, and I don't have
any difficulty opening a recordset on a cross-tab query ...
Public Sub TestTransform()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
'SQL copied from Quarterly Orders By Product query in Northwind ...
strSQL = "TRANSFORM Sum(CCur([Order
Details].UnitPrice*[Quantity]*(1-[Discount])/100)*100) AS " & _
"ProductAmount SELECT Products.ProductName, Orders.CustomerID,
Year([OrderDate]) AS OrderYear " & _
"FROM Products INNER JOIN (Orders INNER JOIN [Order Details] ON
Orders.OrderID = " & _
"[Order Details].OrderID) ON Products.ProductID = [Order
Details].ProductID WHERE (((Orders.OrderDate) " & _
"Between #1/1/1997# And #12/31/1997#)) GROUP BY
Products.ProductName, Orders.CustomerID, Year([OrderDate]) " & _
"PIVOT 'Qtr ' & DatePart('q',[OrderDate],1,0) In ('Qtr 1','Qtr
2','Qtr 3','Qtr 4');"
Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)
Do Until rst.EOF
Debug.Print rst.Fields(0)
rst.MoveNext
Loop
rst.Close
End Sub
--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com
The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
Leo said:
Hi Doug -
Sorry for the delay in response. I've been out of the country for the past
week.
Anyway, I can't do your below suggestion because I am unable to execute
SQL
in my vba(.mdb) environment. This is due to the 'Transform' part of the
statement that VBA give me a "expected select...." error (i.e. it doesn't
recognize the 'Transform' part of the statement)
If I could execute Transform in my vba (.mdb), then it would be alot
easier
for me to manipulate the code..
However, i am stuck with the openquery function..