I have an SQL SELECT query in a cell (image). I am attempting to use VBA to use the string in my cell as my string for an SQL query, but it reads only part of the string. In the cell, the query (without quotes) is 685 chars long. In the variable (at run time), the query is (with quotes) 185 chars long. Here is the query in the cell:
SELECT Contacts.[Last Name],
Contacts.[First Name],
Contacts.[Maricom E-Mail],
Contacts.[Project, Org, Team]
FROM Contacts
WHERE (((Contacts.[Project, Org, Team])=""Proj - MDM"")
AND ((Contacts.[Active?])=Yes))
OR (((Contacts.[Project, Org, Team])=""Team%"")
AND ((Contacts.[Active?])=Yes))
OR (((Contacts.[Project, Org, Team])=""Orgs - CM"")
AND ((Contacts.[Active?])=Yes))
OR (((Contacts.[Project, Org, Team])=""Orgs - Document Team"")
AND ((Contacts.[Active?])=Yes))
OR (((Contacts.[Project, Org, Team])=""Orgs - Process Engineering"")
AND ((Contacts.[Active?])=Yes))
OR (((Contacts.[Project, Org, Team])=""Orgs - QA"")
AND ((Contacts.[Active?])=Yes))
ORDER BY Contacts.[Last Name];
Here is the code I use to read the cell (I used "dim myQuery as string" earlier in the code, and the cell is formatted as text):
myQuery = Range("Project1Query").Value
Here is the query in the variable that has been declared as a string:
"SELECT Contacts.[Last Name],
Contacts.[First Name],
Contacts.[Maricom E-Mail],
Contacts.[Project, Org, Team]
FROM Contacts
WHERE (((Contacts.[Project, Org, Team])=""Proj - MDM"") AND "
The variable is then used in the following request for data:
ReviewersData.Open myQuery, ReviewersConn, adOpenStatic, adLockOptimistic
Any thoughts as to how 500 characters got cut off?
Debug.Print sqlStrit gives me the whole string.Debug.Print Len(sqlStr)outputs 685 indeed.