Creating ADO recordset of totals qry

G

Gibson

I use the following code to open an ADO recordset of a totals query. I then
try to take the total for field TotA and put it into a variable, intTot1. I
receive an error message telling me the field (SumOfTotA)is not found in the
collection. Am I referencing it incorrectly? or possibly totals queries
can't be used as a ADO recordset? I know the value does exist in the query.

Thanks.

Set rsQry = New ADODB.Recordset
rsQry.Open SQLStmnt, CurrentProject.Connection, adOpenKeyset,
adLockOptimistic

If Not rsQry.EOF Then
intTot1 = rsQry![SumOfTotA]
End If
 
D

Dirk Goldgar

Gibson said:
I use the following code to open an ADO recordset of a totals query.
I then try to take the total for field TotA and put it into a
variable, intTot1. I receive an error message telling me the field
(SumOfTotA)is not found in the collection. Am I referencing it
incorrectly? or possibly totals queries can't be used as a ADO
recordset? I know the value does exist in the query.

Thanks.

Set rsQry = New ADODB.Recordset
rsQry.Open SQLStmnt, CurrentProject.Connection, adOpenKeyset,
adLockOptimistic

If Not rsQry.EOF Then
intTot1 = rsQry![SumOfTotA]
End If

So what is the content of the variable "SQLStmnt"? What's the actual
SQL of the query? There's nothing obviously wrong with the code you've
posted.
 
G

Gibson

Thanks for the reply. Your question regarding SQLStmnt pointed me to the
solution. It is an sql statement that opens the recordset to a specific
record. The sql statement was referencing an incorrect ADO recordset. One of
those can't see the forest for the trees problems. Thanks again for calling
my attention to the obvious.


Dirk Goldgar said:
Gibson said:
I use the following code to open an ADO recordset of a totals query.
I then try to take the total for field TotA and put it into a
variable, intTot1. I receive an error message telling me the field
(SumOfTotA)is not found in the collection. Am I referencing it
incorrectly? or possibly totals queries can't be used as a ADO
recordset? I know the value does exist in the query.

Thanks.

Set rsQry = New ADODB.Recordset
rsQry.Open SQLStmnt, CurrentProject.Connection, adOpenKeyset,
adLockOptimistic

If Not rsQry.EOF Then
intTot1 = rsQry![SumOfTotA]
End If

So what is the content of the variable "SQLStmnt"? What's the actual
SQL of the query? There's nothing obviously wrong with the code you've
posted.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top