I have some vba come which creates a new querytable. Here is the function
Sub GetReplicaSQLQuery(ByRef TableName As String, ByRef SQLQuery As String, ByRef ExcelSheet As String)
Sheets(ExcelSheet).Cells.Clear
With Sheets(ExcelSheet).ListObjects.Add( _
SourceType:=0, _
Source:=Array("OLEDB;Provider=SQLOLEDB.1;" _
, "Integrated Security=SSPI;" _
, "Persist Security Info=True;" _
, "Data Source=uk-db3\replica;" _
, "Use Procedure for Prepare=1;" _
, "Auto Translate=True;" _
, "Packet Size=4096;" _
, "Use Encryption for Data=False;" _
, "Tag with column collation when possible=False;"), _
Destination:=Range(ExcelSheet & "!$B$1") _
).QueryTable
.CommandType = xlCmdSql
.CommandText = SQLQuery
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = TableName
.Refresh BackgroundQuery:=False
End With
End Sub
the SQLquery needs to get HUGE...the above code works fine when its not too big, but I need to look up info on thousands of customers so my query get huge...then the code fails with the error "Application-defined or object-defined error"
The char length on the query which trigger the error is c40,000 chars
I know the sql query itself is fine.
Any ideas why i cant get this to work?
I tried wrapping SQLQuery in array() and also array("" & SQLQuery & "")...didnt work
thanks everyone
Bookmarks