Essentially I would like to run a simple select query that gets the sum of a column of values and prints the results in the immediate window (debugger).
The following is an example of my query:
SELECT Sum([Quantity]*[Total]) As Total FROM MyTable
The following is my code so far:
Dim strSQL As String
strSQL = "SELECT Sum([Quantity]*[Total]) As Total FROM MyTable"
DoCmd.RunSQL strSQL
Debug.Print strSQL
How can I execute that query and grab the results of the SUM to Print?
SELECT queries are not 'run', they are opened. Run is for action SQL - DELETE, INSERT, UPDATE.
Options:
Dim rs as DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT Sum([Quantity]*[Total]) As Tot FROM MyTable"
Debug.Print rs!Tot
Debug.Print DSum("Quantity*Total", "MyTable")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.