I am trying to dynamically update the rowsource of a chart within access.
To achieve this I moved the original rowsource sql of the chart which is:
And replaced it with the rowsource being a query called "qryPareto"
I update the qryPareto using QueryDefs which should allow me to input different sql in to qryPareto and the chart will update accordingly.
However, When I try and insert the above sql I get the following error:
Syntax Error (missing operator)in query expression 'DSum("[SumOfCostFig]]","tblParetoRai sing","[SumOfCostFig]>=" & [TotalCost] &")/DSum("[SumOfCostFig]","tblParetoRai sing") AS CPct FROM tblParetoRaisin g;'.
I have checked the sql I have already doubled up on " where needed:
But I still get the same error. Any ideas?
The code I use to update is below:
To achieve this I moved the original rowsource sql of the chart which is:
Code:
SELECT tblParetoRaising.NCType, tblParetoRaising.SumOfCostFig AS TotalCost, DSum("[SumOfCostFig]","tblParetoRaising","[SumOfCostFig]>=" & [TotalCost] & "")/DSum("[SumOfCostFig]","tblParetoRaising") AS CPct FROM tblParetoRaising;
I update the qryPareto using QueryDefs which should allow me to input different sql in to qryPareto and the chart will update accordingly.
However, When I try and insert the above sql I get the following error:
Syntax Error (missing operator)in query expression 'DSum("[SumOfCostFig]]","tblParetoRai sing","[SumOfCostFig]>=" & [TotalCost] &")/DSum("[SumOfCostFig]","tblParetoRai sing") AS CPct FROM tblParetoRaisin g;'.
I have checked the sql I have already doubled up on " where needed:
Code:
rowsource1 = "SELECT tblParetoRaising.NCType, tblParetoRaising.SumOfCostFig AS TotalCost, DSum(""[SumOfCostFig]"",""tblParetoRaising"",""[SumOfCostFig]>="" & [TotalCost] & "")/DSum(""[SumOfCostFig]"",""tblParetoRaising"") AS CPct FROM tblParetoRaising;"
The code I use to update is below:
Code:
Dim dbs As Database
Dim ParetoQuery As QueryDef
Dim sqlstring As String
Dim sqlstring2 As String
Dim rowsource1 As String
Set dbs = CurrentDb
Set ParetoQuery = dbs.QueryDefs("qryPareto")
rowsource1 = "SELECT tblParetoRaising.NCType, tblParetoRaising.SumOfCostFig AS TotalCost, DSum(""[SumOfCostFig]"",""tblParetoRaising"",""[SumOfCostFig]>="" & [TotalCost] & "")/DSum(""[SumOfCostFig]"",""tblParetoRaising"") AS CPct FROM tblParetoRaising;"
ParetoQuery.SQL = rowsource1
dbs.QueryDefs.Refresh
Me.grpPareto1.Requery
Set ParetoQuery = Nothing
Set dbs = Nothing
Exit Sub
Comment