Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Crosstab in Code

Status
Not open for further replies.

Rjc8513

Technical User
Feb 12, 2001
140
US
Okay, this is driving me crazy! I am trying to create a crosstab query using code. I keep getting the 'Syntax Error' message when trying to run this code:

dbs.CreateQueryDef "cqry- VOLUME", _
"TRANSFORM Sum([tbl VOLUME].[ACTL) AS [The Value]" _
& " SELECT [FINANCE NO], [OFFICE], [LINE]" _
& " FROM [tbl VOLUME] PIVOT [WEEK];"

Thanks for the help.

Richard...
 
Try this, I think you got the line continuation characters (& _) backwards.

dim strSQL
strSQL = "TRANSFORM Sum([tbl VOLUME].[ACTL) AS [The Value] " & _
"SELECT [FINANCE NO], [OFFICE], [LINE] " & _
"FROM [tbl VOLUME] PIVOT [WEEK];"

dbs.CreateQueryDef("cqry- VOLUME", strSQL)

Jim Lunde
compugeeks@hotmail.com
We all agree your theory is crazy, but is it crazy enough?
 
Thanks for the response but, it still didn't work. I'm still getting a syntax error. Below is my code altered to reflect your suggestions:

dim strSQL
strSQL = "TRANSFORM Sum([tbl VOLUME].[ACTL) AS [The Value] " & _
"SELECT [FINANCE NO], [OFFICE], [LINE] " & _
"FROM [tbl VOLUME] PIVOT [WEEK];"

dbs.CreateQueryDef "cqry- VOLUME", strSQL

Thanks.

Richard...
 
If this is a copy/paste, your error is here.....

strSQL = "TRANSFORM Sum([tbl VOLUME].[ACTL]) AS [The Value] " & _
"SELECT [FINANCE NO], [OFFICE], [LINE] " & _
"FROM [tbl VOLUME] PIVOT [WEEK];"

You were missing an end bracket.....also, it does not matter if you use & _ or _ &.....I personally prefer to use _ & because you can easily see that the line that starts with a & is continuation of the previous line....

Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need! [thumbsup2]

Robert L. Johnson III, A+, Network+, MCP
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Thanks Robert, but if I add that end bracket I then get an error message citing the TRANSFORM statement.

Without the end bracket I the error:
'Syntax error in query expression 'Sum([tbl VOLUME].[ACTL)...' .

With the end bracket added I get the error:
'Syntax error in 'TRANSFORM' statement.'

Richard...
 
That might be correct......

But if you get an error either way.....it will never be right without that end bracket....the end bracket is ending the name of a field....and if you don't supply it, the field is never ended....

Once you add that bracket, the error is now telling you there is a problem with the Transform....something totally different..... Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need! [thumbsup2]

Robert L. Johnson III, A+, Network+, MCP
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
The underlying syntax error results becauset your code is missing a GROUP BY clause, necessary when using the TRANSFORM statement.
 
raskew,

that did the trick! thanks for the help.

thanks to all others, too.

Richard...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top