SQL Command in .CommandText

Paella1

Active Member
Joined
Mar 10, 2005
Messages
382
I am using a procedure to generate a list/table using an ODBC link and an SQL query. I do this a lot, generally with no problem.

However in this instance my SQL query is very long, and generates a Type Mismatch error at the .CommandText = Array(sql) line below:

Code:
    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
        "ODBC;DRIVER=SQL Server;SERVER=myServer;UID=myUserName;PWD=myPassword;APP=Microsoft Office 2010;WSID=myWSID" Destination:=Range("$B$1")).QueryTable
        .CommandText = Array(sql)
        .Refresh BackgroundQuery:=False
    End With

I have found that this method will work when the string is up to 255 characters long, but as soon as the string length hits 256 characters a Type mismatch error occurs.

Is there a way around this?
 
I said it would be a few days and it was five months, but I just got back to it now and it works a treat. Thanks Colin.
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,214,591
Messages
6,120,426
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top