I have the following VBA which updates the command text in my data connection in excel.
Sub ClaimLine_Macro()
Dim strsql As String
strsql = "Select a.* from claim a "
strsql = strsql & Worksheets("SQL_ClaimLine").Range("claim1")
strsql = strsql & Worksheets("SQL_ClaimLine").Range("claim2")
strsql = strsql & Worksheets("SQL_ClaimLine").Range("claim3")
With ActiveWorkbook.Connections("ClaimLineExtract").ODBCConnection
.BackgroundQuery = True
.CommandText = strsql
End With
ActiveWorkbook.Connections("ClaimLineExtract").Refresh
End Sub
If I run the VBA above I get the error Run-time error 1004 application-defined or object defined error.
What's interesting is if I comment out
strsql = strsql & Worksheets("SQL_ClaimLine").Range("claim3")
The VBA works! I am not sure what is causing the error.
Further more, if I run the VBA without claim3 and copy and paste the SQL in to TOAD, I get one really long text string.
When I run it with claim3, it now wraps the text string at character 1,023 on every line. I believe this is causing the issue. Is there any way around the wrapping at 1,023 characters?
The ranges in the VBA (Claim1, claim2, and claim3) each reference a single cell that contains a concatenated block of 1,000 claims. The cells have a UDF formula that places them into the correct syntax while appending "or a.claim " at the end when needed. Claim1 is hardcoded to say "Where a.claim " in the beginning.
I have been trouble shooting to see if it is a specific claim but what I found is a little weird. Each range has 1,000 claims in it, regardless of which range I change, if I reduce the total number of claims to 2,580 the VBA will work with no error(If I increase to 2,581 the VBA errors). This means there are 32,698 characters in the strSQL.