View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
John Michl[_2_] John Michl[_2_] is offline
external usenet poster
 
Posts: 27
Default Source Data Code Cleanup Help

I'm writing some code to create pivot tables from an SQL database that was
created several years ago. Unfortunately, the person that created the
database used table names and field names with lots of spaces in them. For
starters, I have no opportunity to change the names. I've recorded the
macro below to create the pivot and select the source data. However, I'd
like to clean it up a bit for two reasons:
1) Make it easier to read so that field names are split on multiply lines
and
2) Add variables for the server and database names so I can use an input box
to change these at the start. (The server in the example is
"JMICHL_03\SQL2000" and the database is "POSData".

My problem is that when I try to edit the code below I can't seem to get the
the quotes in proper places so as to not generate errors. In addition, I
can't seem to figure out how to put a variable into this string that would
substitute a new server or database name. Could someone edit the code below
enough to give me an idea of where the quotes should be?

If it isn't obvious 'Customer Period / Type' is a table within the
database.

Thanks! - John

ActiveSheet.PivotTableWizard SourceType:=xlExternal,
SourceData:=Array( _
"SELECT ""Customer Period / Type"".""Sales Organization ID"",
""Customer Period / Type"".""Period ID"", ""Customer Period /
Type"".""Customer Type"", ""Customer Period / Type"".""Current Sales Org
Decile"", ""Customer Period / Type"".""Prior " _
, _
"Revenue Centile""" & Chr(13) & "" & Chr(10) & "FROM
""POSData"".dbo.""Customer Period / Type"" ""Customer Period / Type"",
""POSData"".dbo.""Sales Organizations"" ""Sales Organizations""" & Chr(13) &
"" & Chr(10) & "WHERE ""Sales Organizations"".ID = ""C" _
, "ustomer Period / Type"".""Sales Organization ID"""),
Connection:=Array( _
Array( _
"ODBC;DRIVER=SQL
Server;SERVER=JMICHL_03\SQL2000;UID=JMichl;APP=Mic rosoft Office
XP;WSID=JMICHL_03;DATABASE=POSData;Trusted_" _
), Array("Connection=Yes"))