Question : Long SQL String is Wrapping and Not Running in Access VBA

Hello EE,

Using Access 2007 I'm building a "long" sql string portion to write into a field (type = memo).  The code for the long string is below.  I've also pasted the results of the string.

If I paste the results into a queries' SQL view the string has a return within the Field38DataTitle.  If I remove that return it runs fine.  How do I stop that return from occurring or is there another way to write this SQL string.

The purpose is to use this field in another VBA function as part of the Insert Into statement.

Thanks,
LVBarnes
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
Private Function HeaderSqlStrUpdt()

    Dim strSQL As String
    strSQL = "Update tblImportCustSchemaFlat "
    strSQL = strSQL & "Set SqlHeader = Field01DataTitle & ', ' & Field02DataTitle & ', ' & Field03DataTitle & ', ' & "
    strSQL = strSQL & "Field04DataTitle & ', ' & Field05DataTitle & ', ' & Field06DataTitle & ', ' & Field07DataTitle & ', ' & "
    strSQL = strSQL & "Field08DataTitle & ', ' & Field09DataTitle & ', ' & Field10DataTitle & ', ' & Field11DataTitle & ', ' & "
    strSQL = strSQL & "Field12DataTitle & ', ' & Field13DataTitle & ', ' & Field14DataTitle & ', ' & Field15DataTitle & ', ' & "
    strSQL = strSQL & "Field16DataTitle & ', ' & Field17DataTitle & ', ' & Field18DataTitle & ', ' & Field19DataTitle & ', ' & "
    strSQL = strSQL & "Field20DataTitle & ', ' & Field21DataTitle & ', ' & Field22DataTitle & ', ' & Field23DataTitle & ', ' & "
    strSQL = strSQL & "Field24DataTitle & ', ' & Field25DataTitle & ', ' & Field26DataTitle & ', ' & Field27DataTitle & ', ' & "
    strSQL = strSQL & "Field28DataTitle & ', ' & Field29DataTitle & ', ' & Field30DataTitle & ', ' & Field31DataTitle & ', ' & "
    strSQL = strSQL & "Field32DataTitle & ', ' & Field33DataTitle & ', ' & Field34DataTitle & ', ' & Field35DataTitle & ', ' & "
    strSQL = strSQL & "Field36DataTitle & ', ' & Field37DataTitle & ', ' & Field38DataTitle & ', ' & Field39DataTitle & ', ' & "
    strSQL = strSQL & "Field40DataTitle & ', ' & Field41DataTitle & ', ' & Field42DataTitle & ', ' & Field43DataTitle & ', ' & "
    strSQL = strSQL & "Field44DataTitle & ', ' & Field45DataTitle & ', ' & Field46DataTitle & ', ' & Field47DataTitle & ', ' & "
    strSQL = strSQL & "Field48DataTitle & ', ' & Field49DataTitle & ', ' & Field50DataTitle "
    strSQL = strSQL & "WHERE (tblImportCustSchemaFlat.DefaultCustNbr=[Forms]![frmImportSchemaCheck]![DefaultCustNbr]) AND (tblImportCustSchemaFlat.ClaimTypeDesc=[Forms]![frmImportSchemaCheck]![txtClaimTypeDesc]);"
    
'Debug.Print strSQL

    CurrentProject.Connection.Execute strSQL

'Debug.Print "strSQL ran"
    
End Function

Here is what it returns in the immediate window.  Notice the break within Field38.  This will run in a SQL query if I remove this break.
Update tblImportCustSchemaFlat Set SqlHeader = Field01DataTitle & ', ' & Field02DataTitle & ', ' & Field03DataTitle & ', ' & Field04DataTitle & ', ' & Field05DataTitle & ', ' & Field06DataTitle & ', ' & Field07DataTitle & ', ' & Field08DataTitle & ', ' & Field09DataTitle & ', ' & Field10DataTitle & ', ' & Field11DataTitle & ', ' & Field12DataTitle & ', ' & Field13DataTitle & ', ' & Field14DataTitle & ', ' & Field15DataTitle & ', ' & Field16DataTitle & ', ' & Field17DataTitle & ', ' & Field18DataTitle & ', ' & Field19DataTitle & ', ' & Field20DataTitle & ', ' & Field21DataTitle & ', ' & Field22DataTitle & ', ' & Field23DataTitle & ', ' & Field24DataTitle & ', ' & Field25DataTitle & ', ' & Field26DataTitle & ', ' & Field27DataTitle & ', ' & Field28DataTitle & ', ' & Field29DataTitle & ', ' & Field30DataTitle & ', ' & Field31DataTitle & ', ' & Field32DataTitle & ', ' & Field33DataTitle & ', ' & Field34DataTitle & ', ' & Field35DataTitle & ', ' & Field36DataTitle & ', ' & Field37DataTitle & ', ' & Field38DataTit
le & ', ' & Field39DataTitle & ', ' & Field40DataTitle & ', ' & Field41DataTitle & ', ' & Field42DataTitle & ', ' & Field43DataTitle & ', ' & Field44DataTitle & ', ' & Field45DataTitle & ', ' & Field46DataTitle & ', ' & Field47DataTitle & ', ' & Field48DataTitle & ', ' & Field49DataTitle & ', ' & Field50DataTitle WHERE (tblImportCustSchemaFlat.DefaultCustNbr=[Forms]![frmImportSchemaCheck]![DefaultCustNbr]) AND (tblImportCustSchemaFlat.ClaimTypeDesc=[Forms]![frmImportSchemaCheck]![txtClaimTypeDesc]);

Answer : Long SQL String is Wrapping and Not Running in Access VBA

change this part

    strSQL = strSQL & "WHERE (tblImportCustSchemaFlat.DefaultCustNbr=[Forms]![frmImportSchemaCheck]![DefaultCustNbr]) AND (tblImportCustSchemaFlat.ClaimTypeDesc=[Forms]![frmImportSchemaCheck]![txtClaimTypeDesc]);"

to

    strSQL = strSQL & "WHERE tblImportCustSchemaFlat.DefaultCustNbr=" & [Forms]![frmImportSchemaCheck]![DefaultCustNbr] & " AND tblImportCustSchemaFlat.ClaimTypeDesc='" & [Forms]![frmImportSchemaCheck]![txtClaimTypeDesc] &"'"


if DefaultCustNbr is Text data type


    strSQL = strSQL & "WHERE tblImportCustSchemaFlat.DefaultCustNbr='" & [Forms]![frmImportSchemaCheck]![DefaultCustNbr] & "' AND tblImportCustSchemaFlat.ClaimTypeDesc='" & [Forms]![frmImportSchemaCheck]![txtClaimTypeDesc] &"'"
Random Solutions  
 
programming4us programming4us