I have an SQL generated ADO recordset that is returning a different value than an Access query with the SAME SQL statement. I know that the Access query results are right - for some reason the ADO recordset isn't. Here is my code:
Dim rsTotals As ADODB.Recordset
Dim sSql as String
sSql = "SELECT Sum(ext_variance) AS ext_variance_total "
sSql = sSql & "FROM variance_wdo "
sSql = sSql & "WHERE month Between #" & sDateFrom & "# And #" & sDateTo & "#"
Set rsTotals = CreateObject("ADODB.Recordset"
rsTotals.Open sSql, con, 1
lblReportDollarTotal.Caption = Format(rsTotals!ext_variance_total, "Currency"
As you can see, I'm calculating a sum. I've stopped the code after the SQL statement is generated, copied the value of sSql in the debug window, and pasted it into an Access query. When I do this and run the query, I get the correct value ($161,505.23). However, if I let the code open the recordset, I get the wrong value ($136,109.28) returned.
The "variance_wdo" query I'm pulling data from is a union, if that makes a difference.
Has anybody else had a problem with this? Thanks.
jender624
Dim rsTotals As ADODB.Recordset
Dim sSql as String
sSql = "SELECT Sum(ext_variance) AS ext_variance_total "
sSql = sSql & "FROM variance_wdo "
sSql = sSql & "WHERE month Between #" & sDateFrom & "# And #" & sDateTo & "#"
Set rsTotals = CreateObject("ADODB.Recordset"
rsTotals.Open sSql, con, 1
lblReportDollarTotal.Caption = Format(rsTotals!ext_variance_total, "Currency"
As you can see, I'm calculating a sum. I've stopped the code after the SQL statement is generated, copied the value of sSql in the debug window, and pasted it into an Access query. When I do this and run the query, I get the correct value ($161,505.23). However, if I let the code open the recordset, I get the wrong value ($136,109.28) returned.
The "variance_wdo" query I'm pulling data from is a union, if that makes a difference.
Has anybody else had a problem with this? Thanks.
jender624