place a value of SQL sentence inside of variable of vb code

T

thread

Hi all,
i'm trying to faster proccess,is there a way to place a value fro SQL
sentence inside of vb variable?
for ex.
dim value as integer
docmd.runSQL "SELECT .......,sum([data])...."=>value=sum([data])
 
P

pietlinden

thread said:
Hi all,
i'm trying to faster proccess,is there a way to place a value fro SQL
sentence inside of vb variable?
for ex.
dim value as integer
docmd.runSQL "SELECT .......,sum([data])...."=>value=sum([data])

you mean you're trying to open a SQL statement that runs a summary
function and then write that summary function's result to a variable?
You're going about it all wrong. RunSQL executes action queries. It
does not return recordsets/results. You need OpenRecordset for that.
Then, yes, you can return the results of a summation query to that and
then read the value of a field in the recordset.

Public MyFunction (arglist) as Long
dim rs as dao.recordset
set rs = db.openrecordset("SELECT...Sum(MyField) As MyTotal FROM
MyTable WHERE... GROUP BY SummaryField...", dbOpenSnapshot)
MyFunction = rs.Fields("MyTotal")
rs.close
set rs=nothing
End Function
 

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