+ Reply to Thread
Results 1 to 2 of 2

VBA SQL connection issue

Hybrid View

  1. #1
    Registered User
    Join Date
    06-29-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    2

    VBA SQL connection issue

    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

  2. #2
    Registered User
    Join Date
    06-29-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: VBA SQL connection issue

    dump...anyone?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1