As a test, I broke up my big query into 4 smaller PT queries and tried to concatenate them (see below). Note: I was wrong. Including spaces, the SQL is about 8,000 characters.
I realize that I probably should just put all 8,000 characters into a big string in VBA and go from there, but that is a lot of code to put quotes and line continuation symbols on, so I tried it this way just to see if I could concatenate the 4 strings. I commented the line where it failed.
This is the error.
When I debug.print, I find that the first 6,000 characters are gone.
Code:
Private Sub Test_3()
Const cstr_QuerySection_1 As String = "PT_Test_1"
Const cstr_QuerySection_2 As String = "PT_Test_2"
Const cstr_QuerySection_3 As String = "PT_Test_3"
Const cstr_QuerySection_4 As String = "PT_Test_4"
Dim db As DAO.Database
Dim qdf1 As DAO.QueryDef
Dim qdf2 As DAO.QueryDef
Dim qdf3 As DAO.QueryDef
Dim qdf4 As DAO.QueryDef
Dim qdfMaster As DAO.QueryDef
Dim strSQL1 As String
Dim strSQL2 As String
Dim strSQL3 As String
Dim strSQL4 As String
Dim strBigSQL As String
Set db = CurrentDb
Set qdf1 = db.QueryDefs(cstr_QuerySection_1)
Set qdf2 = db.QueryDefs(cstr_QuerySection_2)
Set qdf3 = db.QueryDefs(cstr_QuerySection_3)
Set qdf4 = db.QueryDefs(cstr_QuerySection_4)
strSQL1 = qdf1.SQL
strSQL2 = qdf2.SQL
strSQL3 = qdf3.SQL
strSQL4 = qdf4.SQL
strBigSQL = strSQL1 & strSQL2 & strSQL3 & strSQL4
Set qdfMaster = db.CreateQueryDef("tmpQdf", strBigSQL) -- *** FAILS here; strBiqSql is truncated. ***
qdfMaster.Execute
Note, when I take the original query (all 4 parts together) and open it as follows, it runs fine:
Code:
DoCmd.OpenQuery "<orig>" ' where <orig> is the original saved query (with 8,000 chars)
End Sub