I know this is an old beast but none of my reading, or various attempts, has set me on the right path.
In the code below sTable is passed in from the calling sub but is not recognised by the SQL statement.
Replacing the variable with a string, "Collection" in this case causes the SQL to run.
I have tried replacing all, or part, of the HAVING clause with a WHERE clause, and moving it under the FROM clause, with the same result.
How do I fix this?
I could write two SQL strings but this seems a bit much for the sake of one word.
The variable would contain either "Collection" or "Parks".
This code does not work with the variable in the HAVING clause.
This code does work with the variable replaced with a string.
In the code below sTable is passed in from the calling sub but is not recognised by the SQL statement.
Replacing the variable with a string, "Collection" in this case causes the SQL to run.
I have tried replacing all, or part, of the HAVING clause with a WHERE clause, and moving it under the FROM clause, with the same result.
How do I fix this?
I could write two SQL strings but this seems a bit much for the sake of one word.
The variable would contain either "Collection" or "Parks".
This code does not work with the variable in the HAVING clause.
Code:
Public Function setCounted(sTable As String)
DoCmd.SetWarnings False
DoCmd.RunSQL "delete * from Counted"
sQry = "INSERT INTO counted ( Family, Infra, Box, Collection ) " & _
"SELECT Boxes.Family, Boxes.Infra, Boxes.boxno, Boxes.Collection " & _
"FROM Boxes " & _
"GROUP BY Boxes.Family, Boxes.Infra, Boxes.boxno, Boxes.Collection " & _
"HAVING (((Boxes.boxno)>0) and ((instr([Boxes].[Collection], sTable))> '0'));"
DoCmd.RunSQL sQry
DoCmd.SetWarnings True
End Function
This code does work with the variable replaced with a string.
Code:
Public Function setCounted(sTable As String)
DoCmd.SetWarnings False
DoCmd.RunSQL "delete * from Counted"
sQry = "INSERT INTO counted ( Family, Infra, Box, Collection ) " & _
"SELECT Boxes.Family, Boxes.Infra, Boxes.boxno, Boxes.Collection " & _
"FROM Boxes " & _
"GROUP BY Boxes.Family, Boxes.Infra, Boxes.boxno, Boxes.Collection " & _
"HAVING (((Boxes.boxno)>0) and ((instr([Boxes].[Collection], 'Collection'))> '0'));"
DoCmd.RunSQL sQry
DoCmd.SetWarnings True
End Function