Retrieving a single value from a table

G

Guest

Is there a simple way in VBA to retrieve a single value from a table?

Suppose I have a table T with two fields, K (for key) and V (for value). I
want to execute a query:

SELECT V from T WHERE K = "something"

and return the value into a variable. It would be as though Docmd.RunSQL
was able to return a value.

I know how to create a recordset, open it, read a record and close the
recordset. I just wondered if there was an easier way.
 
J

John Spencer

The aggregate functions come to mind

DLookup("V","T","K=""Something"")

DLookup, DCount, DFirst, DLast, DSum, DAvg are all functions that you can
call in your VBA.

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 

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