ADO Recordset Fails.....Query Too Big?

Boggle

New Member
Joined
Apr 28, 2011
Messages
1
Hello,

I have this bit of code which is supposed to pull 6 lines of data, but it fails. Any thoughts as to why? The code keeps breaking execution. (I've tried both DAO and ADO, below is the ADO)

Thanks,
B

Option Explicit
Sub OpenDB()
'Dim db As ADODB.Database
'Dim ws As ADODB.Workspace
Dim rst As ADODB.Recordset
Dim conn As ADODB.Connection
Dim ConnectionString As String
Dim Querystring As String
Dim strSQL As String
Dim luserName As String
Dim lpassword As String
Dim account As String
Dim startDt As String
Dim endDt As String
Dim strSQL_2 As String
Dim strSQL_3 As String
Dim strSQL_4 As String
Dim strSQL_5 As String


luserName = Range("userName")
lpassword = Range("password")
account = Range("account")
startDt = CStr(Format(Range("start").Value, "d-mmm-yyyy"))
endDt = CStr(Format(Range("end").Value, "d-mmm-yyyy"))

strSQL = "with " & _
"accounts as ( " & _

6 Lines Here

" ), " & _
"" & _
"dates as ( " & _

5 Lines Here

" ) , " & _
" " & _
"AT as ( " & _

5 Lines Here

" ), " & _
"" & _
"SR as ( "

strSQL_2 = strSQL & "

4 Lines

" ) , " & _
" " & _
"AR as ( " & _

6 Lines

" ), " & _
"" & _
" " & _
"P as ( " & _

8 Lines

" ), "
strSQL_3 = strSQL_2 & "close_price as ( " & _

10 Lines

), " & _
" " & _
"FVP as ( " & _

9 Lines

" ), " & _
"" & _
"OP as ( "

strSQL_4 = strSQL_3 &

14 Lines

" )," & _
" " & _
"MV as ( " & _

12 Lines

strSQL_5 = strSQL_4 &

Final Select and 15 Lines

The above query is about 10 tables (made using "with as", 3999 characters and returns 8 lines of data in PL/SQL in about 20 seconds.

Set conn = New ADODB.Connection

conn.Open "Data Source="name";UID=" & luserName & ";PWD=" & lpassword & ""

Set rst = New ADODB.Recordset

rst.Open strSQL_5, conn

Sheets("Data").Select

Cells(2, 1).CopyFromRecordset rst
rst.Close
conn.Close

End Sub

Why does such a large query fail? Changing the timeout only crashes Excel. Thanks for the help.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,579
Messages
5,770,969
Members
425,653
Latest member
UNSING

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
Top