OK so I am trying to create a SQL string where the name of table is a variable. I can do this with no problem... my problem is that I am also trying to create a special field within to make a path...
So the path would look something like [Path] & [some_field] & "\" as New_Path...
The only problem is it doesn't work
I have used the ASCII Chr(34), chr(38) and even chr(92)...
But somehow, with extra double quotes, the singular ampersand (that need to be part of the SQL statment) and a back slash on the end (which needs to be in quotes within the statement)... VBA interprets any compbination of ASCII characters incorrectly... It either thinks I am trying to " & \ " or " & ""\"" "
I even tried using a string Variable to set it up... but no combination of double quotes and/or ASCII characters is working.
This code:
Comes out like so:
"SELECT ITEM.PARENT, [temp_TOA_J04].[PATH] & [ITEM].[PARENT] &""\"" AS PATH, [temp_TOA_J04].LV, [ITEM].QUANTITY FROM temp_TOA_J04 INNER JOIN ITEM ON [temp_TOA_J04].[CHILD] = ITEM.PARENT WHERE ((([temp_TOA_J04].[LV])= 1 ));"
Notice the extra double quotes around the backslash.
If you removed the Chr(34) then it comes out with no double quotes at all.
I think this combination just may not be doable...?
So the path would look something like [Path] & [some_field] & "\" as New_Path...
The only problem is it doesn't work
I have used the ASCII Chr(34), chr(38) and even chr(92)...
But somehow, with extra double quotes, the singular ampersand (that need to be part of the SQL statment) and a back slash on the end (which needs to be in quotes within the statement)... VBA interprets any compbination of ASCII characters incorrectly... It either thinks I am trying to " & \ " or " & ""\"" "
I even tried using a string Variable to set it up... but no combination of double quotes and/or ASCII characters is working.
This code:
Code:
strString = " " & Chr(38) & Chr(34) & Chr(92) & Chr(34) & " "
strSQL = "SELECT ITEM.PARENT, [temp_" & strOneTOA_Name & "].[PATH] & [ITEM].[PARENT]" & strString & " AS PATH, " & _
"[temp_" & strOneTOA_Name & "].LV, [ITEM].QUANTITY FROM temp_TOA_J04 INNER JOIN ITEM ON [temp_" & strOneTOA_Name & "].[CHILD] = ITEM.PARENT WHERE " & _
"((([temp_" & strOneTOA_Name & "].[LV])= " & iLevel & " ));"
Comes out like so:
"SELECT ITEM.PARENT, [temp_TOA_J04].[PATH] & [ITEM].[PARENT] &""\"" AS PATH, [temp_TOA_J04].LV, [ITEM].QUANTITY FROM temp_TOA_J04 INNER JOIN ITEM ON [temp_TOA_J04].[CHILD] = ITEM.PARENT WHERE ((([temp_TOA_J04].[LV])= 1 ));"
Notice the extra double quotes around the backslash.
If you removed the Chr(34) then it comes out with no double quotes at all.
I think this combination just may not be doable...?