Hi
I have a section of VBA code that generates my SQL query, but when I try to use the query it errors.
I have seen found that the query is being split into 1024 character blocks by Access and therefore not providing correct syntax for the query to work.
Is there anything that I can do to work around this?
The SQL query is generated using the code below:
[tt]
For Each x In table_list
sql = "SELECT DISTINCT Product FROM " & x(0) & ";"
query_name = "query_" & x(0)
Set qry = db.CreateQueryDef(query_name, sql)
Set rs = qry.OpenRecordset
qry.Close
datalist_query_sql = "SELECT [CHTest1].Area, [CHTest1].Employee, [CHTest1].[LM ID Number], [CHTest1].Name, [CHTest1].Address, [CHTest1].[Address 2], [CHTest1].Town, [CHTest1].Postcode, [CHTest1].[Phone Number], [CHTest1].Category, [CHTest1].Profile, [CHTest1].Type, [CHTest1].Owner, [CHTest1].Operator, [CHTest1].MFT, [CHTest1].Fascia, [CHTest1].MF, [CHTest1].[Serve Size], [CHTest1].[Free Pour], [CHTest2].[SeventyMl], [CHTest1].LastSurveyDate,"
While Not rs.EOF
str_replace = Trim(Replace(rs.Fields(0).Value, ".", "_"))
datalist_query_sql = datalist_query_sql & " [" & x(0) & "_crosstab].[" & str_replace & _
"] AS [" & x(1) & str_replace & "],"
rs.MoveNext
Wend
Next
[/tt]
I would really appreciate any help
Thank
I have a section of VBA code that generates my SQL query, but when I try to use the query it errors.
I have seen found that the query is being split into 1024 character blocks by Access and therefore not providing correct syntax for the query to work.
Is there anything that I can do to work around this?
The SQL query is generated using the code below:
[tt]
For Each x In table_list
sql = "SELECT DISTINCT Product FROM " & x(0) & ";"
query_name = "query_" & x(0)
Set qry = db.CreateQueryDef(query_name, sql)
Set rs = qry.OpenRecordset
qry.Close
datalist_query_sql = "SELECT [CHTest1].Area, [CHTest1].Employee, [CHTest1].[LM ID Number], [CHTest1].Name, [CHTest1].Address, [CHTest1].[Address 2], [CHTest1].Town, [CHTest1].Postcode, [CHTest1].[Phone Number], [CHTest1].Category, [CHTest1].Profile, [CHTest1].Type, [CHTest1].Owner, [CHTest1].Operator, [CHTest1].MFT, [CHTest1].Fascia, [CHTest1].MF, [CHTest1].[Serve Size], [CHTest1].[Free Pour], [CHTest2].[SeventyMl], [CHTest1].LastSurveyDate,"
While Not rs.EOF
str_replace = Trim(Replace(rs.Fields(0).Value, ".", "_"))
datalist_query_sql = datalist_query_sql & " [" & x(0) & "_crosstab].[" & str_replace & _
"] AS [" & x(1) & str_replace & "],"
rs.MoveNext
Wend
Next
[/tt]
I would really appreciate any help
Thank