Reputation: 165
I need to create a Excel 2010 macro, which changes the SQL Command text of a Excel Connection. I'm working with a SQL Server, if it matters.
How could I do this? I've found several links online, but none of them have worked.
The most recent code I used:
Dim comText As String
comText = "select top 10000 [activitypointer0.subject] as subject , [activitypointer0.activityid] as activityid , [activitypointer0.instancetypecodename] as instancetypecodename , [activitypointer0.scheduledend] as scheduledend , [activitypointer0.createdbyname] as createdbyname , [activitypointer0.activitytypecodename] as activitytypecodename , [a_9cdbdceab5ee4a8db875050d455757bd.name] as [a_9cdbdceab5ee4a8db875050d455757bd.name]"
comText = comText & " from FilteredActivityPointer as [activitypointer0] left outer join FilteredAccount as [a_9cdbdceab5ee4a8db875050d455757bd] on ([activitypointer0.regardingobjectid] = [a_9cdbdceab5ee4a8db875050d455757bd.accountid])"
comText = comText & " where ([activitypointer0.activitytypecode] = 4201 and ([activitypointer0.ownerid] in (N'{69CB3CDE-0998-E011-916A-00155D000607}' , N'{D8D40800-B798-E011-916A-00155D000607}' , N'{7ECB3CDE-0998-E011-916A-00155D000607}' , N'{70CB3CDE-0998-E011-916A-00155D000607}')) and [activitypointer0.statecode] = 1 and [activitypointer0.scheduledendutc] >= '20111231 22:00:00' and [activitypointer0.scheduledendutc] < '20120131 22:00:00' )"
comText = comText & " order by [activitypointer0.subject] asc , [activitypointer0.activityid] asc"
With ActiveWorkbook.Connections("conCRM").ODBCConnection
.commandText = comText
End With
ActiveWorkbook.Connections("conCRM").Refresh
This is giving me an error about column names.
Upvotes: 0
Views: 1767
Reputation: 8225
Maybe you should be using column names like [activitypointer0].[subject]
instead of [activitypointer0.subject]
(and others like it) if the error you get is only "complaining" about column names.
Upvotes: 2